From 2ab8a655948c5ec665f28f15da7c109c14c55afc Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 2 Nov 2016 18:52:08 -0500 Subject: [PATCH 01/90] Skeleton implementation --- .gitignore | 13 ++++ MIT-License.txt | 20 ++++++ README.md | 7 ++ init.rb | 10 +++ install-gems.sh | 79 +++++++++++++++++++++ lib/messaging/postgres.rb | 5 ++ lib/messaging/postgres/controls.rb | 4 ++ lib/messaging/postgres/controls/message.rb | 7 ++ lib/messaging/postgres/controls/stream.rb | 7 ++ lib/messaging/postgres/log.rb | 11 +++ lib/messaging/postgres/write.rb | 17 +++++ library-symlinks.sh | 80 ++++++++++++++++++++++ messaging-postgres.gemspec | 22 ++++++ remove-lib-symlinks.sh | 3 + set-local-gem-path.sh | 16 +++++ settings/event_source_postgres.json | 14 ++++ symlink-lib.sh | 3 + test.rb | 1 + test/automated.rb | 6 ++ test/automated/automated_init.rb | 1 + test/automated/write/_write.rb | 20 ++++++ test/test_init.rb | 14 ++++ 22 files changed, 360 insertions(+) create mode 100755 .gitignore create mode 100755 MIT-License.txt create mode 100755 README.md create mode 100755 init.rb create mode 100755 install-gems.sh create mode 100644 lib/messaging/postgres.rb create mode 100644 lib/messaging/postgres/controls.rb create mode 100644 lib/messaging/postgres/controls/message.rb create mode 100644 lib/messaging/postgres/controls/stream.rb create mode 100644 lib/messaging/postgres/log.rb create mode 100644 lib/messaging/postgres/write.rb create mode 100755 library-symlinks.sh create mode 100644 messaging-postgres.gemspec create mode 100755 remove-lib-symlinks.sh create mode 100755 set-local-gem-path.sh create mode 100644 settings/event_source_postgres.json create mode 100755 symlink-lib.sh create mode 100755 test.rb create mode 100644 test/automated.rb create mode 100644 test/automated/automated_init.rb create mode 100644 test/automated/write/_write.rb create mode 100755 test/test_init.rb diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..d28b09c --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +.DS_store +.bundle/ +.ruby-version +.ruby-gemset +.rvmrc +Gemfile.lock +*.log +*.gem +gems +gems_backup +*scratch* +*notes* +loader.rb diff --git a/MIT-License.txt b/MIT-License.txt new file mode 100755 index 0000000..cd0e498 --- /dev/null +++ b/MIT-License.txt @@ -0,0 +1,20 @@ +Copyright (c) 2016 Scott Bellware + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100755 index 0000000..69127e1 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# messaging-postgres + +Postgres messaging for Eventide + +## License + +The `messaging-postgres` library is released under the [MIT License](https://github.com/eventide-project/messaging-postgres/blob/master/MIT-License.txt). diff --git a/init.rb b/init.rb new file mode 100755 index 0000000..e125715 --- /dev/null +++ b/init.rb @@ -0,0 +1,10 @@ +lib_dir = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir) + +libraries_dir = ENV['LIBRARIES_HOME'] +unless libraries_dir.nil? + libraries_dir = File.expand_path(libraries_dir) + $LOAD_PATH.unshift libraries_dir unless $LOAD_PATH.include?(libraries_dir) +end + +require 'messaging/postgres' diff --git a/install-gems.sh b/install-gems.sh new file mode 100755 index 0000000..2ea4b74 --- /dev/null +++ b/install-gems.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash + +set -e + +if [ -z ${GEM_AUTHORITY_PATH+x} ]; then + echo "GEM_AUTHORITY_PATH is not set" + exit +fi + +echo +echo 'Installing local gems' +echo '= = =' + +source ./set-local-gem-path.sh + +echo +echo 'Removing gem files' +echo '- - -' +if test -n "$(find . -maxdepth 1 -name '*.gem' -print -quit)"; then + for gem in *.gem; do + echo "- $gem" + rm $gem + done +else + echo "(No gem files found)" +fi + +echo +echo 'Building gems' +echo '- - -' +for gemspec in *.gemspec; do + echo "- $gemspec" + gem build $gemspec +done + +if [ -z ${POSTURE+x} ]; then + echo "(POSTURE is not set. Using \"operational\" by default.)" + posture="operational" +else + posture=$POSTURE +fi + +scheme="https:" +gem_repo_authority_path=$GEM_AUTHORITY_PATH +public_gem_repo_uri="$scheme//$gem_repo_authority_path" + +gemfury_token="" +if [ ! -z ${GEMFURY_TOKEN+x} ]; then + gemfury_token=$GEMFURY_TOKEN +fi + +private_source="" +if [ ! $gemfury_token = "" ]; then + private_gem_repo_uri="$scheme//$gemfury_token@$gem_repo_authority_path" + private_source="--source $private_gem_repo_uri" +fi + +public_source="--source $public_gem_repo_uri" + +ruby_gems_source="--source https://rubygems.org" + +echo +echo "Installing gems locally (posture: $posture)" +echo '- - -' +for gem in *.gem; do + echo "($gem)" + cmd="gem install $gem --clear-sources $private_source $public_source $ruby_gems_source --install-dir ./gems" + + if [ operational != "$posture" ]; then + cmd="$cmd --development" + fi + + echo $cmd + ($cmd) || exit 1 +done + +echo '= = =' +echo '(done)' +echo diff --git a/lib/messaging/postgres.rb b/lib/messaging/postgres.rb new file mode 100644 index 0000000..8254e1a --- /dev/null +++ b/lib/messaging/postgres.rb @@ -0,0 +1,5 @@ +require 'messaging' +require 'event_source/postgres' + +require 'messaging/postgres/log' +require 'messaging/postgres/write' diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb new file mode 100644 index 0000000..5927c13 --- /dev/null +++ b/lib/messaging/postgres/controls.rb @@ -0,0 +1,4 @@ +require 'messaging/controls' + +require 'messaging/postgres/controls/stream' +require 'messaging/postgres/controls/message' diff --git a/lib/messaging/postgres/controls/message.rb b/lib/messaging/postgres/controls/message.rb new file mode 100644 index 0000000..bf200f0 --- /dev/null +++ b/lib/messaging/postgres/controls/message.rb @@ -0,0 +1,7 @@ +module Messaging + module Postgres + module Controls + Message = Messaging::Controls::Message + end + end +end diff --git a/lib/messaging/postgres/controls/stream.rb b/lib/messaging/postgres/controls/stream.rb new file mode 100644 index 0000000..32552c8 --- /dev/null +++ b/lib/messaging/postgres/controls/stream.rb @@ -0,0 +1,7 @@ +module Messaging + module Postgres + module Controls + Stream = Messaging::Controls::Stream + end + end +end diff --git a/lib/messaging/postgres/log.rb b/lib/messaging/postgres/log.rb new file mode 100644 index 0000000..dedd494 --- /dev/null +++ b/lib/messaging/postgres/log.rb @@ -0,0 +1,11 @@ +module Messaging + module Postgres + class Log < ::Log + def tag!(tags) + tags << :messaging_postgres + tags << :library + tags << :verbose + end + end + end +end diff --git a/lib/messaging/postgres/write.rb b/lib/messaging/postgres/write.rb new file mode 100644 index 0000000..4c272d8 --- /dev/null +++ b/lib/messaging/postgres/write.rb @@ -0,0 +1,17 @@ +module Messaging + module Postgres + class Write + # include Messaging::Write + include Log::Dependency + + def self.logger + @logger ||= Log.get(self) + end + + def self.build_event_writer + logger.trace "Building event writer" + logger.debug "Built event writer" + end + end + end +end diff --git a/library-symlinks.sh b/library-symlinks.sh new file mode 100755 index 0000000..b68a396 --- /dev/null +++ b/library-symlinks.sh @@ -0,0 +1,80 @@ +set -e + +if [ -z ${LIBRARIES_HOME+x} ]; then + echo "LIBRARIES_HOME must be set to the libraries directory path... exiting" + exit 1 +fi + +if [ ! -d "$LIBRARIES_HOME" ]; then + echo "$LIBRARIES_HOME does not exist... exiting" + exit 1 +fi + +function make_directory { + directory=$1 + + lib_directory="$LIBRARIES_HOME/$directory" + + if [ ! -d "$lib_directory" ]; then + echo "- making directory $lib_directory" + mkdir -p "$lib_directory" + fi +} + +function remove_lib_symlinks { + name=$1 + directory=$2 + + dest="$LIBRARIES_HOME" + if [ ! -z "$directory" ]; then + dest="$dest/$directory" + fi + dest="$dest/$name" + + for entry in $dest*; do + if [ -h "$entry" ]; then + echo "- removing symlink: $entry" + rm $entry + fi + done +} + +function symlink_lib { + name=$1 + directory=$2 + + echo + echo "Symlinking $name" + echo "- - -" + + remove_lib_symlinks $name $directory + + src="$(pwd)/lib" + dest="$LIBRARIES_HOME" + if [ ! -z "$directory" ]; then + src="$src/$directory" + dest="$dest/$directory" + + make_directory $directory + fi + src="$src/$name" + + echo "- destination is $dest" + + full_name=$directory/$name + + for entry in $src*; do + entry_basename=$(basename $entry) + dest_item="$dest/$entry_basename" + + echo "- symlinking $entry_basename to $dest_item" + + cmd="ln -s $entry $dest_item" + echo $cmd + ($cmd) + done + + echo "- - -" + echo "($name done)" + echo +} diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec new file mode 100644 index 0000000..f97c9f7 --- /dev/null +++ b/messaging-postgres.gemspec @@ -0,0 +1,22 @@ +# -*- encoding: utf-8 -*- +Gem::Specification.new do |s| + s.name = 'messaging-postgres' + s.version = '0.0.0.0' + s.summary = 'Postgres messaging for Eventide' + s.description = ' ' + + s.authors = ['The Eventide Project'] + s.email = 'opensource@eventide-project.org' + s.homepage = 'https://github.com/eventide-project/messaging-postgres' + s.licenses = ['MIT'] + + s.require_paths = ['lib'] + s.files = Dir.glob('{lib}/**/*') + s.platform = Gem::Platform::RUBY + s.required_ruby_version = '>= 2.2.3' + + s.add_runtime_dependency 'messaging' + s.add_runtime_dependency 'event_source-postgres' + + s.add_development_dependency 'test_bench' +end diff --git a/remove-lib-symlinks.sh b/remove-lib-symlinks.sh new file mode 100755 index 0000000..a56bde1 --- /dev/null +++ b/remove-lib-symlinks.sh @@ -0,0 +1,3 @@ +source ./library-symlinks.sh + +remove_lib_symlinks 'messaging' 'postgres' diff --git a/set-local-gem-path.sh b/set-local-gem-path.sh new file mode 100755 index 0000000..c0b633e --- /dev/null +++ b/set-local-gem-path.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +unchanged_gem_path=$GEM_PATH + +if [[ ! $GEM_PATH == *"./gems"* ]]; then + export GEM_PATH=./gems:$GEM_PATH + + echo "Gem path was changed" + echo " from: $unchanged_gem_path" + echo " to: $GEM_PATH" +else + echo "Gem path was unchanged" + echo " from: $unchanged_gem_path" +fi + +echo diff --git a/settings/event_source_postgres.json b/settings/event_source_postgres.json new file mode 100644 index 0000000..4f17e59 --- /dev/null +++ b/settings/event_source_postgres.json @@ -0,0 +1,14 @@ +{ + "dbname": "eventsource", + "host": "localhost", + "hostaddr": "127.0.0.1", + "port": 5432, + "user": "eventsource", + "password": null, + "connect_timeout": null, + "options": null, + "sslmode": null, + "krbsrvname": null, + "gsslib": null, + "service": null +} diff --git a/symlink-lib.sh b/symlink-lib.sh new file mode 100755 index 0000000..2950b01 --- /dev/null +++ b/symlink-lib.sh @@ -0,0 +1,3 @@ +source ./library-symlinks.sh + +symlink_lib 'messaging' 'postgres' diff --git a/test.rb b/test.rb new file mode 100755 index 0000000..d92b472 --- /dev/null +++ b/test.rb @@ -0,0 +1 @@ +require_relative 'test/automated' diff --git a/test/automated.rb b/test/automated.rb new file mode 100644 index 0000000..de477e0 --- /dev/null +++ b/test/automated.rb @@ -0,0 +1,6 @@ +require_relative 'test_init' + +TestBench::Runner.( + 'automated/**/*.rb', + exclude_pattern: %r{\/_|sketch|(_init\.rb|_tests\.rb)\z} +) or exit 1 diff --git a/test/automated/automated_init.rb b/test/automated/automated_init.rb new file mode 100644 index 0000000..faa8577 --- /dev/null +++ b/test/automated/automated_init.rb @@ -0,0 +1 @@ +require_relative '../test_init' diff --git a/test/automated/write/_write.rb b/test/automated/write/_write.rb new file mode 100644 index 0000000..e89358d --- /dev/null +++ b/test/automated/write/_write.rb @@ -0,0 +1,20 @@ +require_relative '../automated_init' + +# context "Write" do +# stream = Controls::Stream.example + +# message = Controls::Message.example + +# written_position = Write.(message, stream.name) + +# read_message = nil +# EventSource::Postgres::Read.(stream.name, position: written_position, batch_size: 1) do |event_data| +# read_message = Message::Import.(event_data, message.class) +# end + +# test "Got the event that was written" do +# assert(read_message == message) +# end +# end + +Messaging::Postgres::Write.build_event_writer diff --git a/test/test_init.rb b/test/test_init.rb new file mode 100755 index 0000000..283bacb --- /dev/null +++ b/test/test_init.rb @@ -0,0 +1,14 @@ +ENV['CONSOLE_DEVICE'] ||= 'stdout' +ENV['LOG_LEVEL'] ||= '_min' + +puts RUBY_DESCRIPTION + +require_relative '../init.rb' + +require 'test_bench'; TestBench.activate + +require 'pp' +require 'securerandom' + +require 'messaging/postgres/controls' +include Messaging::Postgres From a39d0be5bbbe82af58ab42ba38d71e48699755f6 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Thu, 3 Nov 2016 19:22:30 -0500 Subject: [PATCH 02/90] Write message --- lib/messaging/postgres/write.rb | 12 +++--------- test/automated/write/_write.rb | 20 -------------------- test/automated/write/write.rb | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 test/automated/write/_write.rb create mode 100644 test/automated/write/write.rb diff --git a/lib/messaging/postgres/write.rb b/lib/messaging/postgres/write.rb index 4c272d8..bfdf8af 100644 --- a/lib/messaging/postgres/write.rb +++ b/lib/messaging/postgres/write.rb @@ -1,16 +1,10 @@ module Messaging module Postgres class Write - # include Messaging::Write - include Log::Dependency + include Messaging::Write - def self.logger - @logger ||= Log.get(self) - end - - def self.build_event_writer - logger.trace "Building event writer" - logger.debug "Built event writer" + def configure(partition: nil, session: nil) + EventSource::Postgres::Write.configure(self, attr_name: :event_writer, partition: nil, session: nil) end end end diff --git a/test/automated/write/_write.rb b/test/automated/write/_write.rb deleted file mode 100644 index e89358d..0000000 --- a/test/automated/write/_write.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../automated_init' - -# context "Write" do -# stream = Controls::Stream.example - -# message = Controls::Message.example - -# written_position = Write.(message, stream.name) - -# read_message = nil -# EventSource::Postgres::Read.(stream.name, position: written_position, batch_size: 1) do |event_data| -# read_message = Message::Import.(event_data, message.class) -# end - -# test "Got the event that was written" do -# assert(read_message == message) -# end -# end - -Messaging::Postgres::Write.build_event_writer diff --git a/test/automated/write/write.rb b/test/automated/write/write.rb new file mode 100644 index 0000000..cac6582 --- /dev/null +++ b/test/automated/write/write.rb @@ -0,0 +1,18 @@ +require_relative '../automated_init' + +context "Write" do + stream = Controls::Stream.example + + message = Controls::Message.example + + written_position = Write.(message, stream.name) + + read_message = nil + EventSource::Postgres::Read.(stream.name, position: written_position, batch_size: 1) do |event_data| + read_message = Messaging::Message::Import.(event_data, message.class) + end + + test "Got the event that was written" do + assert(read_message == message) + end +end From 06ee6b3246b906e3e5692325289e66ddcdf7ba70 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Thu, 3 Nov 2016 22:56:20 -0500 Subject: [PATCH 03/90] Reply --- lib/messaging/postgres/controls.rb | 1 + .../postgres/controls/stream_name.rb | 7 +++++++ test/automated/write/reply.rb | 21 +++++++++++++++++++ test/automated/write/write.rb | 20 ++++++++++-------- 4 files changed, 40 insertions(+), 9 deletions(-) create mode 100644 lib/messaging/postgres/controls/stream_name.rb create mode 100644 test/automated/write/reply.rb diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb index 5927c13..9baae5e 100644 --- a/lib/messaging/postgres/controls.rb +++ b/lib/messaging/postgres/controls.rb @@ -1,4 +1,5 @@ require 'messaging/controls' require 'messaging/postgres/controls/stream' +require 'messaging/postgres/controls/stream_name' require 'messaging/postgres/controls/message' diff --git a/lib/messaging/postgres/controls/stream_name.rb b/lib/messaging/postgres/controls/stream_name.rb new file mode 100644 index 0000000..98b640e --- /dev/null +++ b/lib/messaging/postgres/controls/stream_name.rb @@ -0,0 +1,7 @@ +module Messaging + module Postgres + module Controls + StreamName = Messaging::Controls::StreamName + end + end +end diff --git a/test/automated/write/reply.rb b/test/automated/write/reply.rb new file mode 100644 index 0000000..084cb0b --- /dev/null +++ b/test/automated/write/reply.rb @@ -0,0 +1,21 @@ +require_relative '../automated_init' + +context "Write" do + context "Replying to a Message" do + message = Controls::Message.example + + reply_stream_name = Controls::StreamName.example(category: 'replyToTestReply') + message.metadata.reply_stream_name = reply_stream_name + + writer = Messaging::Postgres::Write.build + + written_position = writer.reply(message) + + stream = Controls::Stream.example(stream_name: reply_stream_name) + read_event = EventSource::Postgres::Get.(stream, position: written_position, batch_size: 1).first + + test "Writes the message to the reply stream" do + assert(read_event.data == message.to_h) + end + end +end diff --git a/test/automated/write/write.rb b/test/automated/write/write.rb index cac6582..5969ca9 100644 --- a/test/automated/write/write.rb +++ b/test/automated/write/write.rb @@ -1,18 +1,20 @@ require_relative '../automated_init' context "Write" do - stream = Controls::Stream.example + context "Single Message" do + stream = Controls::Stream.example - message = Controls::Message.example + message = Controls::Message.example - written_position = Write.(message, stream.name) + written_position = Write.(message, stream.name) - read_message = nil - EventSource::Postgres::Read.(stream.name, position: written_position, batch_size: 1) do |event_data| - read_message = Messaging::Message::Import.(event_data, message.class) - end + read_message = nil + EventSource::Postgres::Read.(stream.name, position: written_position, batch_size: 1) do |event_data| + read_message = Messaging::Message::Import.(event_data, message.class) + end - test "Got the event that was written" do - assert(read_message == message) + test "Got the event that was written" do + assert(read_message == message) + end end end From dcc979994f72fc284a029436d5f490cfb1adfe7b Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Thu, 3 Nov 2016 23:04:31 -0500 Subject: [PATCH 04/90] Using Get rather than Read in tests --- test/automated/write/write.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/automated/write/write.rb b/test/automated/write/write.rb index 5969ca9..5af886e 100644 --- a/test/automated/write/write.rb +++ b/test/automated/write/write.rb @@ -8,13 +8,10 @@ written_position = Write.(message, stream.name) - read_message = nil - EventSource::Postgres::Read.(stream.name, position: written_position, batch_size: 1) do |event_data| - read_message = Messaging::Message::Import.(event_data, message.class) - end + read_event = EventSource::Postgres::Get.(stream, position: written_position, batch_size: 1).first - test "Got the event that was written" do - assert(read_message == message) + test "Writes the message" do + assert(read_event.data == message.to_h) end end end From 6ed91e9987d2c70ef0ab6ac4ff77d1290272e7f9 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Thu, 3 Nov 2016 23:19:09 -0500 Subject: [PATCH 05/90] Test writing reply stream name --- .../write/write_with_reply_stream.rb | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/automated/write/write_with_reply_stream.rb diff --git a/test/automated/write/write_with_reply_stream.rb b/test/automated/write/write_with_reply_stream.rb new file mode 100644 index 0000000..ad9422f --- /dev/null +++ b/test/automated/write/write_with_reply_stream.rb @@ -0,0 +1,21 @@ +require_relative '../automated_init' + +context "Write" do + context "With Reply Stream" do + message = Controls::Message.example + + stream_name = Controls::StreamName.example + reply_stream_name = Controls::StreamName.example(category: 'testReply') + + writer = Messaging::Postgres::Write.build + + written_position = writer.write(message, stream_name, reply_stream_name: reply_stream_name) + + stream = Controls::Stream.example(stream_name: stream_name) + read_event = EventSource::Postgres::Get.(stream, position: written_position, batch_size: 1).first + + test "Sets the metadata reply stream name" do + assert(read_event.metadata[:reply_stream_name] == reply_stream_name) + end + end +end From 321fd948e13f7897ec15496ea3afbeb6978b7ba4 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 4 Nov 2016 00:25:58 -0500 Subject: [PATCH 06/90] Convenience interfaces operate in terms of stream_name rather than stream --- test/automated/write/reply.rb | 3 +-- test/automated/write/write.rb | 6 +++--- test/automated/write/write_with_reply_stream.rb | 3 +-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/test/automated/write/reply.rb b/test/automated/write/reply.rb index 084cb0b..2e743ae 100644 --- a/test/automated/write/reply.rb +++ b/test/automated/write/reply.rb @@ -11,8 +11,7 @@ written_position = writer.reply(message) - stream = Controls::Stream.example(stream_name: reply_stream_name) - read_event = EventSource::Postgres::Get.(stream, position: written_position, batch_size: 1).first + read_event = EventSource::Postgres::Get.(reply_stream_name, position: written_position, batch_size: 1).first test "Writes the message to the reply stream" do assert(read_event.data == message.to_h) diff --git a/test/automated/write/write.rb b/test/automated/write/write.rb index 5af886e..735b26c 100644 --- a/test/automated/write/write.rb +++ b/test/automated/write/write.rb @@ -2,13 +2,13 @@ context "Write" do context "Single Message" do - stream = Controls::Stream.example + stream_name = Controls::StreamName.example message = Controls::Message.example - written_position = Write.(message, stream.name) + written_position = Write.(message, stream_name) - read_event = EventSource::Postgres::Get.(stream, position: written_position, batch_size: 1).first + read_event = EventSource::Postgres::Get.(stream_name, position: written_position, batch_size: 1).first test "Writes the message" do assert(read_event.data == message.to_h) diff --git a/test/automated/write/write_with_reply_stream.rb b/test/automated/write/write_with_reply_stream.rb index ad9422f..c43ebeb 100644 --- a/test/automated/write/write_with_reply_stream.rb +++ b/test/automated/write/write_with_reply_stream.rb @@ -11,8 +11,7 @@ written_position = writer.write(message, stream_name, reply_stream_name: reply_stream_name) - stream = Controls::Stream.example(stream_name: stream_name) - read_event = EventSource::Postgres::Get.(stream, position: written_position, batch_size: 1).first + read_event = EventSource::Postgres::Get.(stream_name, position: written_position, batch_size: 1).first test "Sets the metadata reply stream name" do assert(read_event.metadata[:reply_stream_name] == reply_stream_name) From dd45009a7fd8277ded5dc9cae865e9c7fa24a3d9 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 4 Nov 2016 00:36:22 -0500 Subject: [PATCH 07/90] Expected version test --- test/automated/write/expected_version.rb | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 test/automated/write/expected_version.rb diff --git a/test/automated/write/expected_version.rb b/test/automated/write/expected_version.rb new file mode 100644 index 0000000..4844a43 --- /dev/null +++ b/test/automated/write/expected_version.rb @@ -0,0 +1,27 @@ +require_relative '../automated_init' + +context "Write" do + context "Single Message" do + stream_name = Controls::StreamName.example(category: 'testWrongVersion') + + message_1 = Controls::Message.example + + Write.(message_1, stream_name) + + message_2 = Controls::Message.example + + context "Right Version" do + test "Succeeds" do + Write.(message_2, stream_name, expected_version: 0) + end + end + + context "Wrong Version" do + test "Fails" do + assert proc { Write.(message_2, stream_name, expected_version: 11) } do + raises_error? EventSource::ExpectedVersionError + end + end + end + end +end From fe0b2194f605a52ec8990fd6096f21644d185f48 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 4 Nov 2016 18:06:17 -0500 Subject: [PATCH 08/90] Write batch --- test/automated/write/write_batch.rb | 28 +++++++++++++++++++ .../write/{write.rb => write_message.rb} | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 test/automated/write/write_batch.rb rename test/automated/write/{write.rb => write_message.rb} (93%) diff --git a/test/automated/write/write_batch.rb b/test/automated/write/write_batch.rb new file mode 100644 index 0000000..04fbfe6 --- /dev/null +++ b/test/automated/write/write_batch.rb @@ -0,0 +1,28 @@ +require_relative '../automated_init' + +context "Write" do + context "Batch" do + stream_name = Controls::StreamName.example(category: 'testBatch') + + message_1 = Controls::Message.example(some_attribute: 'value_1') + message_2 = Controls::Message.example(some_attribute: 'value_2') + + batch = [message_1, message_2] + + last_written_position = Write.(batch, stream_name) + + test "Last written position" do + assert(last_written_position == 1) + end + + context "Individual Events are Written" do + 2.times do |i| + read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + + test "Event #{i + 1}" do + assert(read_event.data[:some_attribute] == "value_#{i + 1}") + end + end + end + end +end diff --git a/test/automated/write/write.rb b/test/automated/write/write_message.rb similarity index 93% rename from test/automated/write/write.rb rename to test/automated/write/write_message.rb index 735b26c..7c21481 100644 --- a/test/automated/write/write.rb +++ b/test/automated/write/write_message.rb @@ -1,7 +1,7 @@ require_relative '../automated_init' context "Write" do - context "Single Message" do + context "Message" do stream_name = Controls::StreamName.example message = Controls::Message.example From 043f3d0711cca17ca51d17e67327d508e34a7ef9 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 4 Nov 2016 19:20:47 -0500 Subject: [PATCH 09/90] Test for write batch with reply stream name --- .../write/{write_batch.rb => batch/write.rb} | 2 +- .../write/batch/write_with_reply_stream.rb | 28 +++++++++++++++++++ .../{write_message.rb => message/write.rb} | 2 +- .../write/message/write_with_reply_stream.rb | 22 +++++++++++++++ .../write/write_with_reply_stream.rb | 20 ------------- 5 files changed, 52 insertions(+), 22 deletions(-) rename test/automated/write/{write_batch.rb => batch/write.rb} (94%) create mode 100644 test/automated/write/batch/write_with_reply_stream.rb rename test/automated/write/{write_message.rb => message/write.rb} (90%) create mode 100644 test/automated/write/message/write_with_reply_stream.rb delete mode 100644 test/automated/write/write_with_reply_stream.rb diff --git a/test/automated/write/write_batch.rb b/test/automated/write/batch/write.rb similarity index 94% rename from test/automated/write/write_batch.rb rename to test/automated/write/batch/write.rb index 04fbfe6..9861c56 100644 --- a/test/automated/write/write_batch.rb +++ b/test/automated/write/batch/write.rb @@ -1,4 +1,4 @@ -require_relative '../automated_init' +require_relative '../../automated_init' context "Write" do context "Batch" do diff --git a/test/automated/write/batch/write_with_reply_stream.rb b/test/automated/write/batch/write_with_reply_stream.rb new file mode 100644 index 0000000..a6e42ca --- /dev/null +++ b/test/automated/write/batch/write_with_reply_stream.rb @@ -0,0 +1,28 @@ +require_relative '../../automated_init' + +context "Write" do + context "Batch" do + context "With Reply Stream" do + stream_name = Controls::StreamName.example(category: 'testReply') + reply_stream_name = Controls::StreamName.example(category: 'testReply') + + message_1 = Controls::Message.example(some_attribute: 'value_1') + message_2 = Controls::Message.example(some_attribute: 'value_2') + + batch = [message_1, message_2] + + writer = Messaging::Postgres::Write.build + writer.write(batch, stream_name, reply_stream_name: reply_stream_name) + + context "Individual Events are Written" do + 2.times do |i| + read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + + test "Event #{i + 1}" do + assert(read_event.metadata[:reply_stream_name] == reply_stream_name) + end + end + end + end + end +end diff --git a/test/automated/write/write_message.rb b/test/automated/write/message/write.rb similarity index 90% rename from test/automated/write/write_message.rb rename to test/automated/write/message/write.rb index 7c21481..88885c1 100644 --- a/test/automated/write/write_message.rb +++ b/test/automated/write/message/write.rb @@ -1,4 +1,4 @@ -require_relative '../automated_init' +require_relative '../../automated_init' context "Write" do context "Message" do diff --git a/test/automated/write/message/write_with_reply_stream.rb b/test/automated/write/message/write_with_reply_stream.rb new file mode 100644 index 0000000..af6bb5f --- /dev/null +++ b/test/automated/write/message/write_with_reply_stream.rb @@ -0,0 +1,22 @@ +require_relative '../../automated_init' + +context "Write" do + context "Message" do + context "With Reply Stream" do + message = Controls::Message.example + + stream_name = Controls::StreamName.example(category: 'testReply') + reply_stream_name = Controls::StreamName.example(category: 'testReplyTo') + + writer = Messaging::Postgres::Write.build + + written_position = writer.write(message, stream_name, reply_stream_name: reply_stream_name) + + read_event = EventSource::Postgres::Get.(stream_name, position: written_position, batch_size: 1).first + + test "Sets the metadata reply stream name" do + assert(read_event.metadata[:reply_stream_name] == reply_stream_name) + end + end + end +end diff --git a/test/automated/write/write_with_reply_stream.rb b/test/automated/write/write_with_reply_stream.rb deleted file mode 100644 index c43ebeb..0000000 --- a/test/automated/write/write_with_reply_stream.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../automated_init' - -context "Write" do - context "With Reply Stream" do - message = Controls::Message.example - - stream_name = Controls::StreamName.example - reply_stream_name = Controls::StreamName.example(category: 'testReply') - - writer = Messaging::Postgres::Write.build - - written_position = writer.write(message, stream_name, reply_stream_name: reply_stream_name) - - read_event = EventSource::Postgres::Get.(stream_name, position: written_position, batch_size: 1).first - - test "Sets the metadata reply stream name" do - assert(read_event.metadata[:reply_stream_name] == reply_stream_name) - end - end -end From 4dfafc270801dfdcb8ac2aa365c81762b15920c1 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 4 Nov 2016 19:22:59 -0500 Subject: [PATCH 10/90] Superfluous persistent reference is removed --- test/automated/write/batch/write_with_reply_stream.rb | 3 +-- test/automated/write/message/write_with_reply_stream.rb | 4 +--- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/test/automated/write/batch/write_with_reply_stream.rb b/test/automated/write/batch/write_with_reply_stream.rb index a6e42ca..6fa6dc0 100644 --- a/test/automated/write/batch/write_with_reply_stream.rb +++ b/test/automated/write/batch/write_with_reply_stream.rb @@ -11,8 +11,7 @@ batch = [message_1, message_2] - writer = Messaging::Postgres::Write.build - writer.write(batch, stream_name, reply_stream_name: reply_stream_name) + Write.(batch, stream_name, reply_stream_name: reply_stream_name) context "Individual Events are Written" do 2.times do |i| diff --git a/test/automated/write/message/write_with_reply_stream.rb b/test/automated/write/message/write_with_reply_stream.rb index af6bb5f..9416a7d 100644 --- a/test/automated/write/message/write_with_reply_stream.rb +++ b/test/automated/write/message/write_with_reply_stream.rb @@ -8,9 +8,7 @@ stream_name = Controls::StreamName.example(category: 'testReply') reply_stream_name = Controls::StreamName.example(category: 'testReplyTo') - writer = Messaging::Postgres::Write.build - - written_position = writer.write(message, stream_name, reply_stream_name: reply_stream_name) + written_position = Write.(message, stream_name, reply_stream_name: reply_stream_name) read_event = EventSource::Postgres::Get.(stream_name, position: written_position, batch_size: 1).first From c0181def826a0964b61f4992b833df53a3dee43c Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 4 Nov 2016 19:33:46 -0500 Subject: [PATCH 11/90] Test for reply checks that the reply stream name is cleared from the metadata --- test/automated/write/batch/reply.rb | 0 test/automated/write/message/reply.rb | 26 ++++++++++++++++++++++++++ test/automated/write/reply.rb | 20 -------------------- 3 files changed, 26 insertions(+), 20 deletions(-) create mode 100644 test/automated/write/batch/reply.rb create mode 100644 test/automated/write/message/reply.rb delete mode 100644 test/automated/write/reply.rb diff --git a/test/automated/write/batch/reply.rb b/test/automated/write/batch/reply.rb new file mode 100644 index 0000000..e69de29 diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb new file mode 100644 index 0000000..dd509af --- /dev/null +++ b/test/automated/write/message/reply.rb @@ -0,0 +1,26 @@ +require_relative '../../automated_init' + +context "Write" do + context "Message" do + context "Replying to a Message" do + message = Controls::Message.example + + reply_stream_name = Controls::StreamName.example(category: 'replyToTestReply') + message.metadata.reply_stream_name = reply_stream_name + + writer = Messaging::Postgres::Write.build + + written_position = writer.reply(message) + + read_event = EventSource::Postgres::Get.(reply_stream_name, position: written_position, batch_size: 1).first + + test "Writes the message to the reply stream" do + assert(read_event.data == message.to_h) + end + + test "Clears the reply stream from the metadata" do + assert(read_event.metadata[:reply_stream_name].nil?) + end + end + end +end diff --git a/test/automated/write/reply.rb b/test/automated/write/reply.rb deleted file mode 100644 index 2e743ae..0000000 --- a/test/automated/write/reply.rb +++ /dev/null @@ -1,20 +0,0 @@ -require_relative '../automated_init' - -context "Write" do - context "Replying to a Message" do - message = Controls::Message.example - - reply_stream_name = Controls::StreamName.example(category: 'replyToTestReply') - message.metadata.reply_stream_name = reply_stream_name - - writer = Messaging::Postgres::Write.build - - written_position = writer.reply(message) - - read_event = EventSource::Postgres::Get.(reply_stream_name, position: written_position, batch_size: 1).first - - test "Writes the message to the reply stream" do - assert(read_event.data == message.to_h) - end - end -end From 57befbf1c20ef33cdc4320abbb8c5af1bb1f8755 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 4 Nov 2016 19:57:52 -0500 Subject: [PATCH 12/90] Test for erroneous reply with a batch --- test/automated/write/batch/reply.rb | 22 ++++++++++++++++++++++ test/automated/write/message/reply.rb | 4 ++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/test/automated/write/batch/reply.rb b/test/automated/write/batch/reply.rb index e69de29..d69ba7e 100644 --- a/test/automated/write/batch/reply.rb +++ b/test/automated/write/batch/reply.rb @@ -0,0 +1,22 @@ +require_relative '../../automated_init' + +context "Write" do + context "Reply" do + context "Batch" do + reply_stream_name = Controls::StreamName.example + + message_1 = Controls::Message.example + message_2 = Controls::Message.example + + batch = [message_1, message_2] + + writer = Messaging::Postgres::Write.build + + test "Is an error" do + assert proc { writer.reply(batch) } do + raises_error? + end + end + end + end +end diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index dd509af..c5fbfdb 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -1,8 +1,8 @@ require_relative '../../automated_init' context "Write" do - context "Message" do - context "Replying to a Message" do + context "Reply" do + context "Batch" do message = Controls::Message.example reply_stream_name = Controls::StreamName.example(category: 'replyToTestReply') From 329758e9f0187355f02d8889ff026dcbb6ff12dc Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 4 Nov 2016 20:02:21 -0500 Subject: [PATCH 13/90] Test for failure when replying without a reply stream name in the metadata --- test/automated/write/batch/reply.rb | 2 +- test/automated/write/message/reply.rb | 2 +- .../reply_missing_reply_stream_name.rb | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/automated/write/message/reply_missing_reply_stream_name.rb diff --git a/test/automated/write/batch/reply.rb b/test/automated/write/batch/reply.rb index d69ba7e..9a01d37 100644 --- a/test/automated/write/batch/reply.rb +++ b/test/automated/write/batch/reply.rb @@ -14,7 +14,7 @@ test "Is an error" do assert proc { writer.reply(batch) } do - raises_error? + raises_error? Messaging::Write::Error end end end diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index c5fbfdb..2eb0b68 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -2,7 +2,7 @@ context "Write" do context "Reply" do - context "Batch" do + context "Message" do message = Controls::Message.example reply_stream_name = Controls::StreamName.example(category: 'replyToTestReply') diff --git a/test/automated/write/message/reply_missing_reply_stream_name.rb b/test/automated/write/message/reply_missing_reply_stream_name.rb new file mode 100644 index 0000000..b00149c --- /dev/null +++ b/test/automated/write/message/reply_missing_reply_stream_name.rb @@ -0,0 +1,20 @@ +require_relative '../../automated_init' + +context "Write" do + context "Reply" do + context "Missing Reply Stream Name" do + message = Controls::Message.example + message.metadata.reply_stream_name = nil + + reply_stream_name = Controls::StreamName.example(category: 'testReplyMissingReplyStreamName') + + writer = Messaging::Postgres::Write.build + + test "Is an error" do + assert proc { writer.reply(message) } do + raises_error? Messaging::Write::Error + end + end + end + end +end From a05ef314fad6bebf0ba836d8fa3a5784c1bb7ebe Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 5 Nov 2016 00:20:43 -0500 Subject: [PATCH 14/90] Expected version error is in the ExpectedVersion namespace --- test/automated/write/expected_version.rb | 2 +- test/automated/write/message/write_initial.rb | 52 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 test/automated/write/message/write_initial.rb diff --git a/test/automated/write/expected_version.rb b/test/automated/write/expected_version.rb index 4844a43..12cbf56 100644 --- a/test/automated/write/expected_version.rb +++ b/test/automated/write/expected_version.rb @@ -19,7 +19,7 @@ context "Wrong Version" do test "Fails" do assert proc { Write.(message_2, stream_name, expected_version: 11) } do - raises_error? EventSource::ExpectedVersionError + raises_error? EventSource::ExpectedVersion::Error end end end diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb new file mode 100644 index 0000000..e247eb8 --- /dev/null +++ b/test/automated/write/message/write_initial.rb @@ -0,0 +1,52 @@ +require_relative '../../automated_init' + +context "Write" do + context "Message" do + context "Initial" do + random_id = SecureRandom.hex + stream_name = Controls::StreamName.example(id: random_id) + + message = Controls::Message.example + + writer = Messaging::Postgres::Write.build + writer.write_initial(message, stream_name) + + read_event = EventSource::Postgres::Get.(stream_name, position: 0, batch_size: 1).first + + test "Writes the message" do + assert(read_event.data == message.to_h) + end + end + end +end +__END__ + +context "Initial Event" do + context "Writing the initial event to a stream that has not been created yet" do + substitute_writer = EventStore::Messaging::Writer::Substitute.build + + stream_name = EventStore::Messaging::Controls::StreamName.get 'testWriter' + message = EventStore::Messaging::Controls::Message.example + + substitute_writer.write_initial message, stream_name + + test "Has an expected version of :no_stream" do + assert(substitute_writer.written? { |msg, stream, expected_version | message == msg && expected_version == :no_stream }) + end + end + + context "Writing the initial event to a stream that was previously created by the writing of another event" do + writer = EventStore::Messaging::Writer.build + + message = EventStore::Messaging::Controls::Message.example + stream_name = EventStore::Messaging::Controls::StreamName.get 'testWriter' + + writer.write message, stream_name + + test "Is an error" do + assert proc { writer.write_initial message, stream_name } do + raises_error? EventStore::Client::HTTP::Request::Post::ExpectedVersionError + end + end + end +end From 27103f9f0077a2bd86d2bf60e79294af230ba859 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 5 Nov 2016 01:23:26 -0500 Subject: [PATCH 15/90] Write initial --- test/automated/write/message/write_initial.rb | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index e247eb8..d51a45b 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -2,13 +2,13 @@ context "Write" do context "Message" do - context "Initial" do - random_id = SecureRandom.hex - stream_name = Controls::StreamName.example(id: random_id) + context "Writing the initial event to a stream that has not been created yet" do + stream_name = Controls::StreamName.example message = Controls::Message.example writer = Messaging::Postgres::Write.build + writer.write_initial(message, stream_name) read_event = EventSource::Postgres::Get.(stream_name, position: 0, batch_size: 1).first @@ -17,6 +17,22 @@ assert(read_event.data == message.to_h) end end + + context "Writing the initial event to a stream that already exists" do + stream_name = Controls::StreamName.example + + message = Controls::Message.example + + writer = Messaging::Postgres::Write.build + + writer.write(message, stream_name) + + test "Is an error" do + assert proc { writer.write_initial(message, stream_name) } do + raises_error? EventSource::ExpectedVersion::Error + end + end + end end end __END__ From 9d4cd07998a32a11c853f6c14263bc95e0dddcc4 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 5 Nov 2016 18:32:14 -0500 Subject: [PATCH 16/90] Tests for initial write of batch --- test/automated/write/batch/write_initial.rb | 48 +++++++++++++++++++ test/automated/write/message/write_initial.rb | 33 +------------ 2 files changed, 49 insertions(+), 32 deletions(-) create mode 100644 test/automated/write/batch/write_initial.rb diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb new file mode 100644 index 0000000..d053ae1 --- /dev/null +++ b/test/automated/write/batch/write_initial.rb @@ -0,0 +1,48 @@ +require_relative '../../automated_init' + +context "Write" do + context "Message" do + context "Writing the initial event to a stream that has not been created yet" do + stream_name = Controls::StreamName.example(category: 'testBatchWriteInitial') + + message_1 = Controls::Message.example(some_attribute: 'value_1') + message_2 = Controls::Message.example(some_attribute: 'value_2') + + batch = [message_1, message_2] + + writer = Messaging::Postgres::Write.build + + writer.write_initial(batch, stream_name) + + context "Individual Events are Written" do + 2.times do |i| + read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + + test "Event #{i + 1}" do + assert(read_event.data[:some_attribute] == "value_#{i + 1}") + end + end + end + end + + context "Writing the initial event to a stream that already exists" do + stream_name = Controls::StreamName.example + + message_1 = Controls::Message.example + message_2 = Controls::Message.example + + batch = [message_1, message_2] + + writer = Messaging::Postgres::Write.build + + message = Controls::Message.example + Write.(message, stream_name) + + test "Is an error" do + assert proc { writer.write_initial(batch, stream_name) } do + raises_error? EventSource::ExpectedVersion::Error + end + end + end + end +end diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index d51a45b..b0b77c5 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -3,7 +3,7 @@ context "Write" do context "Message" do context "Writing the initial event to a stream that has not been created yet" do - stream_name = Controls::StreamName.example + stream_name = Controls::StreamName.example(category: 'testMessageWriteInitial') message = Controls::Message.example @@ -35,34 +35,3 @@ end end end -__END__ - -context "Initial Event" do - context "Writing the initial event to a stream that has not been created yet" do - substitute_writer = EventStore::Messaging::Writer::Substitute.build - - stream_name = EventStore::Messaging::Controls::StreamName.get 'testWriter' - message = EventStore::Messaging::Controls::Message.example - - substitute_writer.write_initial message, stream_name - - test "Has an expected version of :no_stream" do - assert(substitute_writer.written? { |msg, stream, expected_version | message == msg && expected_version == :no_stream }) - end - end - - context "Writing the initial event to a stream that was previously created by the writing of another event" do - writer = EventStore::Messaging::Writer.build - - message = EventStore::Messaging::Controls::Message.example - stream_name = EventStore::Messaging::Controls::StreamName.get 'testWriter' - - writer.write message, stream_name - - test "Is an error" do - assert proc { writer.write_initial message, stream_name } do - raises_error? EventStore::Client::HTTP::Request::Post::ExpectedVersionError - end - end - end -end From d4cce182f0825bd34c478a03e0410afd1f0c8079 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 5 Nov 2016 18:47:00 -0500 Subject: [PATCH 17/90] Test stream names are clarified --- test/automated/write/batch/reply.rb | 2 +- test/automated/write/batch/write.rb | 2 +- test/automated/write/batch/write_initial.rb | 2 +- test/automated/write/batch/write_with_reply_stream.rb | 4 ++-- test/automated/write/message/reply.rb | 2 +- .../write/message/reply_missing_reply_stream_name.rb | 2 +- test/automated/write/message/write.rb | 2 +- test/automated/write/message/write_initial.rb | 2 +- test/automated/write/message/write_with_reply_stream.rb | 4 ++-- 9 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/automated/write/batch/reply.rb b/test/automated/write/batch/reply.rb index 9a01d37..d6d65e7 100644 --- a/test/automated/write/batch/reply.rb +++ b/test/automated/write/batch/reply.rb @@ -3,7 +3,7 @@ context "Write" do context "Reply" do context "Batch" do - reply_stream_name = Controls::StreamName.example + reply_stream_name = Controls::StreamName.example(category: 'testReplyToBatchError') message_1 = Controls::Message.example message_2 = Controls::Message.example diff --git a/test/automated/write/batch/write.rb b/test/automated/write/batch/write.rb index 9861c56..ac0676f 100644 --- a/test/automated/write/batch/write.rb +++ b/test/automated/write/batch/write.rb @@ -2,7 +2,7 @@ context "Write" do context "Batch" do - stream_name = Controls::StreamName.example(category: 'testBatch') + stream_name = Controls::StreamName.example(category: 'testWriteBatch') message_1 = Controls::Message.example(some_attribute: 'value_1') message_2 = Controls::Message.example(some_attribute: 'value_2') diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index d053ae1..aed876e 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -3,7 +3,7 @@ context "Write" do context "Message" do context "Writing the initial event to a stream that has not been created yet" do - stream_name = Controls::StreamName.example(category: 'testBatchWriteInitial') + stream_name = Controls::StreamName.example(category: 'testWriteInitialBatch') message_1 = Controls::Message.example(some_attribute: 'value_1') message_2 = Controls::Message.example(some_attribute: 'value_2') diff --git a/test/automated/write/batch/write_with_reply_stream.rb b/test/automated/write/batch/write_with_reply_stream.rb index 6fa6dc0..06fb901 100644 --- a/test/automated/write/batch/write_with_reply_stream.rb +++ b/test/automated/write/batch/write_with_reply_stream.rb @@ -3,8 +3,8 @@ context "Write" do context "Batch" do context "With Reply Stream" do - stream_name = Controls::StreamName.example(category: 'testReply') - reply_stream_name = Controls::StreamName.example(category: 'testReply') + stream_name = Controls::StreamName.example(category: 'testWriteReplyStreamBatch') + reply_stream_name = Controls::StreamName.example(category: 'testWriteReplyStreamBatchReplyStream') message_1 = Controls::Message.example(some_attribute: 'value_1') message_2 = Controls::Message.example(some_attribute: 'value_2') diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index 2eb0b68..a4864ad 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -5,7 +5,7 @@ context "Message" do message = Controls::Message.example - reply_stream_name = Controls::StreamName.example(category: 'replyToTestReply') + reply_stream_name = Controls::StreamName.example(category: 'testReplyToMessage') message.metadata.reply_stream_name = reply_stream_name writer = Messaging::Postgres::Write.build diff --git a/test/automated/write/message/reply_missing_reply_stream_name.rb b/test/automated/write/message/reply_missing_reply_stream_name.rb index b00149c..f09d84c 100644 --- a/test/automated/write/message/reply_missing_reply_stream_name.rb +++ b/test/automated/write/message/reply_missing_reply_stream_name.rb @@ -6,7 +6,7 @@ message = Controls::Message.example message.metadata.reply_stream_name = nil - reply_stream_name = Controls::StreamName.example(category: 'testReplyMissingReplyStreamName') + reply_stream_name = Controls::StreamName.example(category: 'testReplyToMissingReplyStream') writer = Messaging::Postgres::Write.build diff --git a/test/automated/write/message/write.rb b/test/automated/write/message/write.rb index 88885c1..fdafad4 100644 --- a/test/automated/write/message/write.rb +++ b/test/automated/write/message/write.rb @@ -2,7 +2,7 @@ context "Write" do context "Message" do - stream_name = Controls::StreamName.example + stream_name = Controls::StreamName.example(category: 'testWriteMessage') message = Controls::Message.example diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index b0b77c5..530fc7e 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -3,7 +3,7 @@ context "Write" do context "Message" do context "Writing the initial event to a stream that has not been created yet" do - stream_name = Controls::StreamName.example(category: 'testMessageWriteInitial') + stream_name = Controls::StreamName.example(category: 'testWriteInitialMessage') message = Controls::Message.example diff --git a/test/automated/write/message/write_with_reply_stream.rb b/test/automated/write/message/write_with_reply_stream.rb index 9416a7d..29519cb 100644 --- a/test/automated/write/message/write_with_reply_stream.rb +++ b/test/automated/write/message/write_with_reply_stream.rb @@ -5,8 +5,8 @@ context "With Reply Stream" do message = Controls::Message.example - stream_name = Controls::StreamName.example(category: 'testReply') - reply_stream_name = Controls::StreamName.example(category: 'testReplyTo') + stream_name = Controls::StreamName.example(category: 'testWriteReplyStreamMessage') + reply_stream_name = Controls::StreamName.example(category: 'testWriteReplyStreamMessageReplyStream') written_position = Write.(message, stream_name, reply_stream_name: reply_stream_name) From 61a2375ef095581412b36908f403dd3fa7802b9d Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 5 Nov 2016 21:38:56 -0500 Subject: [PATCH 18/90] Superfluous namespace references are removed --- test/automated/write/batch/reply.rb | 2 +- test/automated/write/batch/write_initial.rb | 4 ++-- test/automated/write/message/reply.rb | 2 +- .../write/message/reply_missing_reply_stream_name.rb | 2 +- test/automated/write/message/write_initial.rb | 4 ++-- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/automated/write/batch/reply.rb b/test/automated/write/batch/reply.rb index d6d65e7..3f11c05 100644 --- a/test/automated/write/batch/reply.rb +++ b/test/automated/write/batch/reply.rb @@ -10,7 +10,7 @@ batch = [message_1, message_2] - writer = Messaging::Postgres::Write.build + writer = Write.build test "Is an error" do assert proc { writer.reply(batch) } do diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index aed876e..6f0f384 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -10,7 +10,7 @@ batch = [message_1, message_2] - writer = Messaging::Postgres::Write.build + writer = Write.build writer.write_initial(batch, stream_name) @@ -33,7 +33,7 @@ batch = [message_1, message_2] - writer = Messaging::Postgres::Write.build + writer = Write.build message = Controls::Message.example Write.(message, stream_name) diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index a4864ad..ce710a4 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -8,7 +8,7 @@ reply_stream_name = Controls::StreamName.example(category: 'testReplyToMessage') message.metadata.reply_stream_name = reply_stream_name - writer = Messaging::Postgres::Write.build + writer = Write.build written_position = writer.reply(message) diff --git a/test/automated/write/message/reply_missing_reply_stream_name.rb b/test/automated/write/message/reply_missing_reply_stream_name.rb index f09d84c..8146a27 100644 --- a/test/automated/write/message/reply_missing_reply_stream_name.rb +++ b/test/automated/write/message/reply_missing_reply_stream_name.rb @@ -8,7 +8,7 @@ reply_stream_name = Controls::StreamName.example(category: 'testReplyToMissingReplyStream') - writer = Messaging::Postgres::Write.build + writer = Write.build test "Is an error" do assert proc { writer.reply(message) } do diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index 530fc7e..3f0f04f 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -7,7 +7,7 @@ message = Controls::Message.example - writer = Messaging::Postgres::Write.build + writer = Write.build writer.write_initial(message, stream_name) @@ -23,7 +23,7 @@ message = Controls::Message.example - writer = Messaging::Postgres::Write.build + writer = Write.build writer.write(message, stream_name) From 74cdf981f9d8b252600e722785a8f9a40e559e0d Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sun, 6 Nov 2016 14:53:27 -0600 Subject: [PATCH 19/90] Reply to batch error is tested in the root messaging library --- test/automated/write/batch/reply.rb | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 test/automated/write/batch/reply.rb diff --git a/test/automated/write/batch/reply.rb b/test/automated/write/batch/reply.rb deleted file mode 100644 index 3f11c05..0000000 --- a/test/automated/write/batch/reply.rb +++ /dev/null @@ -1,22 +0,0 @@ -require_relative '../../automated_init' - -context "Write" do - context "Reply" do - context "Batch" do - reply_stream_name = Controls::StreamName.example(category: 'testReplyToBatchError') - - message_1 = Controls::Message.example - message_2 = Controls::Message.example - - batch = [message_1, message_2] - - writer = Write.build - - test "Is an error" do - assert proc { writer.reply(batch) } do - raises_error? Messaging::Write::Error - end - end - end - end -end From d7f7cc9eb11435fabeae6aa0ba65edb2cf8394a0 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sun, 6 Nov 2016 15:02:14 -0600 Subject: [PATCH 20/90] Package version established as 0.1.0.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index f97c9f7..05d2c3c 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'messaging-postgres' - s.version = '0.0.0.0' + s.version = '0.1.0.0' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From 98258c7b938a8c4e4dd38f38a1147c4b7eb79071 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 9 Nov 2016 18:13:24 -0600 Subject: [PATCH 21/90] Interactive test of production and consumption --- .gitignore | 1 + test/interactive.rb | 6 +++++ test/interactive/consumer.rb | 37 ++++++++++++++++++++++++++++ test/interactive/interactive_init.rb | 4 +++ test/interactive/producer.rb | 31 +++++++++++++++++++++++ 5 files changed, 79 insertions(+) create mode 100644 test/interactive.rb create mode 100644 test/interactive/consumer.rb create mode 100644 test/interactive/interactive_init.rb create mode 100644 test/interactive/producer.rb diff --git a/.gitignore b/.gitignore index d28b09c..65178b9 100755 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,4 @@ gems_backup *scratch* *notes* loader.rb +stream_name.tmp diff --git a/test/interactive.rb b/test/interactive.rb new file mode 100644 index 0000000..06883ac --- /dev/null +++ b/test/interactive.rb @@ -0,0 +1,6 @@ +require_relative 'test_init' + +TestBench::Runner.( + 'interactive/**/*.rb', + exclude_pattern: %r{\/_|sketch|(_init\.rb|_tests\.rb)\z} +) or exit 1 diff --git a/test/interactive/consumer.rb b/test/interactive/consumer.rb new file mode 100644 index 0000000..e483743 --- /dev/null +++ b/test/interactive/consumer.rb @@ -0,0 +1,37 @@ +require_relative 'interactive_init' + +class Handler + include Messaging::Handle + include Controls::Message + + handle SomeMessage do |some_message| + some_message.other_attribute = "Handled at: #{Clock::UTC.iso8601(precision: 5)}" + end +end + + +logger = Log.get('Consumer') + +logger.info "Starting Consumer", tag: :test + +stream_name_file = File.expand_path('stream_name.tmp', File.dirname(__FILE__)) +stream_name = nil +begin + stream_name = File.read(stream_name_file) +rescue + raise "Stream name file is missing (#{stream_name_file}). It's created by the producer script, which must be run concurrently with #{__FILE__}." +end + +logger.info "Stream name: #{stream_name}", tag: :test + +logger.info "Starting reader", tag: :test + +EventSource::Postgres::Read.(stream_name, batch_size: 1, delay_milliseconds: 10, timeout_milliseconds: 2000) do |event_data| + logger.debug event_data.pretty_inspect, tags: [:test, :data, :message] + + message = Handler.(event_data) + + logger.info "Handled message: #{message.message_type}", tags: [:test, :data, :message] + + logger.debug message.pretty_inspect, tags: [:test, :data, :message] +end diff --git a/test/interactive/interactive_init.rb b/test/interactive/interactive_init.rb new file mode 100644 index 0000000..c63fc5e --- /dev/null +++ b/test/interactive/interactive_init.rb @@ -0,0 +1,4 @@ +require_relative '../test_init' + +ENV['LOG_LEVEL'] = '_max' +ENV['LOG_TAGS'] = 'test' diff --git a/test/interactive/producer.rb b/test/interactive/producer.rb new file mode 100644 index 0000000..880b8c6 --- /dev/null +++ b/test/interactive/producer.rb @@ -0,0 +1,31 @@ +require_relative 'interactive_init' + +logger = Log.get('Producer') + +logger.info "Starting Producer", tag: :test + +stream_name = Controls::StreamName.example(category: 'testInteractive') +logger.info "Stream name: #{stream_name}", tag: :test + +stream_name_file = File.expand_path('stream_name.tmp', File.dirname(__FILE__)) + +File.write(stream_name_file, stream_name) +logger.debug "Wrote stream name file: #{stream_name_file}", tag: :test + +at_exit do + File.unlink stream_name_file +end + +period = ENV['PERIOD'] +period ||= 500 +period_seconds = Rational(period, 1000) + +loop do + message = Controls::Message.example(some_attribute: "Written at: #{Clock::UTC.iso8601(precision: 5)}") + logger.debug message.pretty_inspect, tags: [:test, :data, :message] + + written_position = Write.(message, stream_name) + logger.info "Wrote at position: #{written_position}", tags: [:test, :data, :message] + + sleep period_seconds +end From 29c26c7deeccb4a47605987ca225fee8d94e7f59 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 9 Nov 2016 19:10:31 -0600 Subject: [PATCH 22/90] Interactive tests use local controls --- test/interactive/consumer.rb | 11 +---------- test/interactive/controls.rb | 16 ++++++++++++++++ test/interactive/producer.rb | 3 ++- 3 files changed, 19 insertions(+), 11 deletions(-) create mode 100644 test/interactive/controls.rb diff --git a/test/interactive/consumer.rb b/test/interactive/consumer.rb index e483743..d1ba206 100644 --- a/test/interactive/consumer.rb +++ b/test/interactive/consumer.rb @@ -1,14 +1,5 @@ require_relative 'interactive_init' - -class Handler - include Messaging::Handle - include Controls::Message - - handle SomeMessage do |some_message| - some_message.other_attribute = "Handled at: #{Clock::UTC.iso8601(precision: 5)}" - end -end - +require_relative 'controls' logger = Log.get('Consumer') diff --git a/test/interactive/controls.rb b/test/interactive/controls.rb new file mode 100644 index 0000000..71fc8bf --- /dev/null +++ b/test/interactive/controls.rb @@ -0,0 +1,16 @@ +require_relative 'interactive_init' + +class SomeMessage + include Messaging::Message + + attribute :written_time + attribute :handled_time +end + +class Handler + include Messaging::Handle + + handle SomeMessage do |some_message| + some_message.handled_time = "Handled at: #{Clock::UTC.iso8601(precision: 5)}" + end +end diff --git a/test/interactive/producer.rb b/test/interactive/producer.rb index 880b8c6..7296212 100644 --- a/test/interactive/producer.rb +++ b/test/interactive/producer.rb @@ -1,4 +1,5 @@ require_relative 'interactive_init' +require_relative 'controls' logger = Log.get('Producer') @@ -21,7 +22,7 @@ period_seconds = Rational(period, 1000) loop do - message = Controls::Message.example(some_attribute: "Written at: #{Clock::UTC.iso8601(precision: 5)}") + message = SomeMessage.build(written_time: "Written at: #{Clock::UTC.iso8601(precision: 5)}") logger.debug message.pretty_inspect, tags: [:test, :data, :message] written_position = Write.(message, stream_name) From cd266324c4d0d93596b75c7756c553a170c28796 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 18 Nov 2016 17:31:50 -0600 Subject: [PATCH 23/90] Partition is an instance actuator parameter rather than a class constructor parameter --- lib/messaging/postgres/write.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/messaging/postgres/write.rb b/lib/messaging/postgres/write.rb index bfdf8af..3729ae1 100644 --- a/lib/messaging/postgres/write.rb +++ b/lib/messaging/postgres/write.rb @@ -3,8 +3,8 @@ module Postgres class Write include Messaging::Write - def configure(partition: nil, session: nil) - EventSource::Postgres::Write.configure(self, attr_name: :event_writer, partition: nil, session: nil) + def configure(session: nil) + EventSource::Postgres::Write.configure(self, attr_name: :event_writer, session: nil) end end end From 08795a92e5f138b74ab4e4fc2ffc0a92413e3619 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 18 Nov 2016 19:07:51 -0600 Subject: [PATCH 24/90] Package version is increased from 0.1.0.0 to 0.2.0.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 05d2c3c..6192d22 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'messaging-postgres' - s.version = '0.1.0.0' + s.version = '0.2.0.0' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From 9f1000f3418cd7a8123ea05ac7e413f14d0168cb Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 18 Nov 2016 21:13:51 -0600 Subject: [PATCH 25/90] Partition write test --- lib/messaging/postgres/controls.rb | 1 + lib/messaging/postgres/controls/partition.rb | 7 +++++++ test/automated/write/message/partition.rb | 21 ++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 lib/messaging/postgres/controls/partition.rb create mode 100644 test/automated/write/message/partition.rb diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb index 9baae5e..08ad632 100644 --- a/lib/messaging/postgres/controls.rb +++ b/lib/messaging/postgres/controls.rb @@ -1,5 +1,6 @@ require 'messaging/controls' require 'messaging/postgres/controls/stream' +require 'messaging/postgres/controls/partition' require 'messaging/postgres/controls/stream_name' require 'messaging/postgres/controls/message' diff --git a/lib/messaging/postgres/controls/partition.rb b/lib/messaging/postgres/controls/partition.rb new file mode 100644 index 0000000..6ed794a --- /dev/null +++ b/lib/messaging/postgres/controls/partition.rb @@ -0,0 +1,7 @@ +module Messaging + module Postgres + module Controls + Partition = Messaging::Controls::Partition + end + end +end diff --git a/test/automated/write/message/partition.rb b/test/automated/write/message/partition.rb new file mode 100644 index 0000000..d45775c --- /dev/null +++ b/test/automated/write/message/partition.rb @@ -0,0 +1,21 @@ +require_relative '../../automated_init' + +context "Write" do + context "Message" do + context "Partition" do + stream_name = Controls::StreamName.example(category: 'testWriteMessage') + + partition = Controls::Partition.example + + message = Controls::Message.example + + written_position = Write.(message, stream_name, partition: partition) + + read_event = EventSource::Postgres::Get.(stream_name, partition: partition, position: written_position, batch_size: 1).first + + test "Writes the message" do + assert(read_event.data == message.to_h) + end + end + end +end From 4c820118b1b161e5c97f728b69134aeb4aab36fa Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 18 Nov 2016 22:19:57 -0600 Subject: [PATCH 26/90] Partition tests --- test/automated/write/batch/partition.rb | 32 +++++++++++++++++++++++ test/automated/write/message/batch.rb | 28 ++++++++++++++++++++ test/automated/write/message/partition.rb | 2 +- 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/automated/write/batch/partition.rb create mode 100644 test/automated/write/message/batch.rb diff --git a/test/automated/write/batch/partition.rb b/test/automated/write/batch/partition.rb new file mode 100644 index 0000000..43c46dc --- /dev/null +++ b/test/automated/write/batch/partition.rb @@ -0,0 +1,32 @@ +require_relative '../../automated_init' + +context "Write" do + context "Batch" do + context "Partition" do + stream_name = Controls::StreamName.example(category: 'testWriteBatchPartition') + + partition = Controls::Partition.example + + message_1 = Controls::Message.example(some_attribute: 'value_1') + message_2 = Controls::Message.example(some_attribute: 'value_2') + + batch = [message_1, message_2] + + last_written_position = Write.(batch, stream_name, partition: partition) + + test "Last written position" do + assert(last_written_position == 1) + end + + context "Individual Events are Written" do + 2.times do |i| + read_event = EventSource::Postgres::Get.(stream_name, partition: partition, position: i, batch_size: 1).first + + test "Event #{i + 1}" do + assert(read_event.data[:some_attribute] == "value_#{i + 1}") + end + end + end + end + end +end diff --git a/test/automated/write/message/batch.rb b/test/automated/write/message/batch.rb new file mode 100644 index 0000000..dd9a342 --- /dev/null +++ b/test/automated/write/message/batch.rb @@ -0,0 +1,28 @@ +require_relative '../../automated_init' + +context "Write" do + context "Batch" do + stream_name = Controls::StreamName.example(category: 'testWriteBatchPartition') + + message_1 = Controls::Message.example(some_attribute: 'value_1') + message_2 = Controls::Message.example(some_attribute: 'value_2') + + batch = [message_1, message_2] + + last_written_position = Write.(batch, stream_name) + + test "Last written position" do + assert(last_written_position == 1) + end + + context "Individual Events are Written" do + 2.times do |i| + read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + + test "Event #{i + 1}" do + assert(read_event.data[:some_attribute] == "value_#{i + 1}") + end + end + end + end +end diff --git a/test/automated/write/message/partition.rb b/test/automated/write/message/partition.rb index d45775c..87c80fd 100644 --- a/test/automated/write/message/partition.rb +++ b/test/automated/write/message/partition.rb @@ -3,7 +3,7 @@ context "Write" do context "Message" do context "Partition" do - stream_name = Controls::StreamName.example(category: 'testWriteMessage') + stream_name = Controls::StreamName.example(category: 'testWriteMessagePartition') partition = Controls::Partition.example From 5b75972a68f5f6338c63e4dc06a2f69c55fe911c Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 18 Nov 2016 22:27:10 -0600 Subject: [PATCH 27/90] Test names are corrected --- test/automated/write/batch/write_initial.rb | 2 +- test/automated/write/message/batch.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index 6f0f384..36332f7 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -1,7 +1,7 @@ require_relative '../../automated_init' context "Write" do - context "Message" do + context "Batch" do context "Writing the initial event to a stream that has not been created yet" do stream_name = Controls::StreamName.example(category: 'testWriteInitialBatch') diff --git a/test/automated/write/message/batch.rb b/test/automated/write/message/batch.rb index dd9a342..e07909d 100644 --- a/test/automated/write/message/batch.rb +++ b/test/automated/write/message/batch.rb @@ -2,7 +2,7 @@ context "Write" do context "Batch" do - stream_name = Controls::StreamName.example(category: 'testWriteBatchPartition') + stream_name = Controls::StreamName.example(category: 'testWriteMessageBatch') message_1 = Controls::Message.example(some_attribute: 'value_1') message_2 = Controls::Message.example(some_attribute: 'value_2') From 8f67376151e6d43bb86c6df121ac9fc9de349f7e Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 19 Nov 2016 11:54:59 -0600 Subject: [PATCH 28/90] Package version is increased fro 0.2.0.0 to 0.2.1.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 6192d22..2fcc0db 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'messaging-postgres' - s.version = '0.2.0.0' + s.version = '0.2.1.0' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From f9c77b47684dcf20475c3c5cefb98d0bc2f44f62 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 19 Nov 2016 19:55:21 -0600 Subject: [PATCH 29/90] Partition is removed --- lib/messaging/postgres/controls.rb | 1 - lib/messaging/postgres/controls/partition.rb | 7 ----- test/automated/write/batch/partition.rb | 32 -------------------- test/automated/write/message/batch.rb | 28 ----------------- test/automated/write/message/partition.rb | 21 ------------- 5 files changed, 89 deletions(-) delete mode 100644 lib/messaging/postgres/controls/partition.rb delete mode 100644 test/automated/write/batch/partition.rb delete mode 100644 test/automated/write/message/batch.rb delete mode 100644 test/automated/write/message/partition.rb diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb index 08ad632..9baae5e 100644 --- a/lib/messaging/postgres/controls.rb +++ b/lib/messaging/postgres/controls.rb @@ -1,6 +1,5 @@ require 'messaging/controls' require 'messaging/postgres/controls/stream' -require 'messaging/postgres/controls/partition' require 'messaging/postgres/controls/stream_name' require 'messaging/postgres/controls/message' diff --git a/lib/messaging/postgres/controls/partition.rb b/lib/messaging/postgres/controls/partition.rb deleted file mode 100644 index 6ed794a..0000000 --- a/lib/messaging/postgres/controls/partition.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Messaging - module Postgres - module Controls - Partition = Messaging::Controls::Partition - end - end -end diff --git a/test/automated/write/batch/partition.rb b/test/automated/write/batch/partition.rb deleted file mode 100644 index 43c46dc..0000000 --- a/test/automated/write/batch/partition.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative '../../automated_init' - -context "Write" do - context "Batch" do - context "Partition" do - stream_name = Controls::StreamName.example(category: 'testWriteBatchPartition') - - partition = Controls::Partition.example - - message_1 = Controls::Message.example(some_attribute: 'value_1') - message_2 = Controls::Message.example(some_attribute: 'value_2') - - batch = [message_1, message_2] - - last_written_position = Write.(batch, stream_name, partition: partition) - - test "Last written position" do - assert(last_written_position == 1) - end - - context "Individual Events are Written" do - 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, partition: partition, position: i, batch_size: 1).first - - test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == "value_#{i + 1}") - end - end - end - end - end -end diff --git a/test/automated/write/message/batch.rb b/test/automated/write/message/batch.rb deleted file mode 100644 index e07909d..0000000 --- a/test/automated/write/message/batch.rb +++ /dev/null @@ -1,28 +0,0 @@ -require_relative '../../automated_init' - -context "Write" do - context "Batch" do - stream_name = Controls::StreamName.example(category: 'testWriteMessageBatch') - - message_1 = Controls::Message.example(some_attribute: 'value_1') - message_2 = Controls::Message.example(some_attribute: 'value_2') - - batch = [message_1, message_2] - - last_written_position = Write.(batch, stream_name) - - test "Last written position" do - assert(last_written_position == 1) - end - - context "Individual Events are Written" do - 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first - - test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == "value_#{i + 1}") - end - end - end - end -end diff --git a/test/automated/write/message/partition.rb b/test/automated/write/message/partition.rb deleted file mode 100644 index 87c80fd..0000000 --- a/test/automated/write/message/partition.rb +++ /dev/null @@ -1,21 +0,0 @@ -require_relative '../../automated_init' - -context "Write" do - context "Message" do - context "Partition" do - stream_name = Controls::StreamName.example(category: 'testWriteMessagePartition') - - partition = Controls::Partition.example - - message = Controls::Message.example - - written_position = Write.(message, stream_name, partition: partition) - - read_event = EventSource::Postgres::Get.(stream_name, partition: partition, position: written_position, batch_size: 1).first - - test "Writes the message" do - assert(read_event.data == message.to_h) - end - end - end -end From 26d9d32f2048f961bbf6298d90d62c74c2c23430 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 19 Nov 2016 19:55:53 -0600 Subject: [PATCH 30/90] Package version is increased from 0.2.1.0 to 0.3.0.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 2fcc0db..8bdd73d 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'messaging-postgres' - s.version = '0.2.1.0' + s.version = '0.3.0.0' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From 77dbeac7f45945b415b4c527ed2f84724e291286 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sun, 20 Nov 2016 11:51:28 -0600 Subject: [PATCH 31/90] Tests are improved --- lib/messaging/postgres/controls.rb | 1 + lib/messaging/postgres/controls/batch.rb | 31 +++++++++++++++++++ .../write/batch/reply_is_an_error.rb | 3 ++ test/automated/write/batch/write.rb | 9 ++---- test/automated/write/batch/write_initial.rb | 14 +++------ .../write/batch/write_with_reply_stream.rb | 11 +++---- test/automated/write/message/reply.rb | 6 ++-- ... reply_missing_reply_stream_name_error.rb} | 2 +- test/automated/write/message/write.rb | 6 ++-- test/automated/write/message/write_initial.rb | 2 +- .../write/message/write_with_reply_stream.rb | 8 ++--- 11 files changed, 58 insertions(+), 35 deletions(-) create mode 100644 lib/messaging/postgres/controls/batch.rb create mode 100644 test/automated/write/batch/reply_is_an_error.rb rename test/automated/write/message/{reply_missing_reply_stream_name.rb => reply_missing_reply_stream_name_error.rb} (80%) diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb index 9baae5e..0357684 100644 --- a/lib/messaging/postgres/controls.rb +++ b/lib/messaging/postgres/controls.rb @@ -3,3 +3,4 @@ require 'messaging/postgres/controls/stream' require 'messaging/postgres/controls/stream_name' require 'messaging/postgres/controls/message' +require 'messaging/postgres/controls/batch' diff --git a/lib/messaging/postgres/controls/batch.rb b/lib/messaging/postgres/controls/batch.rb new file mode 100644 index 0000000..4a35971 --- /dev/null +++ b/lib/messaging/postgres/controls/batch.rb @@ -0,0 +1,31 @@ +module Messaging + module Postgres + module Controls + module Batch + def self.example + values = [ + EventSource::Controls::RandomValue.example, + EventSource::Controls::RandomValue.example + ] + + batch = Messages.example + + 2.times do |i| + batch[i].some_attribute = values[i] + end + + return batch, values + end + + module Messages + def self.example + [ + Controls::Message.example, + Controls::Message.example + ] + end + end + end + end + end +end diff --git a/test/automated/write/batch/reply_is_an_error.rb b/test/automated/write/batch/reply_is_an_error.rb new file mode 100644 index 0000000..bf8f2d2 --- /dev/null +++ b/test/automated/write/batch/reply_is_an_error.rb @@ -0,0 +1,3 @@ +require_relative '../../automated_init' + +comment "Tested in Messaging generalization library" diff --git a/test/automated/write/batch/write.rb b/test/automated/write/batch/write.rb index ac0676f..cc86f1c 100644 --- a/test/automated/write/batch/write.rb +++ b/test/automated/write/batch/write.rb @@ -2,12 +2,9 @@ context "Write" do context "Batch" do - stream_name = Controls::StreamName.example(category: 'testWriteBatch') + stream_name = Controls::StreamName.example - message_1 = Controls::Message.example(some_attribute: 'value_1') - message_2 = Controls::Message.example(some_attribute: 'value_2') - - batch = [message_1, message_2] + batch, values = Controls::Batch.example last_written_position = Write.(batch, stream_name) @@ -20,7 +17,7 @@ read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == "value_#{i + 1}") + assert(read_event.data[:some_attribute] == values[i]) end end end diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index 36332f7..d760c95 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -3,12 +3,9 @@ context "Write" do context "Batch" do context "Writing the initial event to a stream that has not been created yet" do - stream_name = Controls::StreamName.example(category: 'testWriteInitialBatch') - - message_1 = Controls::Message.example(some_attribute: 'value_1') - message_2 = Controls::Message.example(some_attribute: 'value_2') + stream_name = Controls::StreamName.example - batch = [message_1, message_2] + batch, values = Controls::Batch.example writer = Write.build @@ -19,7 +16,7 @@ read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == "value_#{i + 1}") + assert(read_event.data[:some_attribute] == values[i]) end end end @@ -28,10 +25,7 @@ context "Writing the initial event to a stream that already exists" do stream_name = Controls::StreamName.example - message_1 = Controls::Message.example - message_2 = Controls::Message.example - - batch = [message_1, message_2] + batch = Controls::Batch::Messages.example writer = Write.build diff --git a/test/automated/write/batch/write_with_reply_stream.rb b/test/automated/write/batch/write_with_reply_stream.rb index 06fb901..a19070f 100644 --- a/test/automated/write/batch/write_with_reply_stream.rb +++ b/test/automated/write/batch/write_with_reply_stream.rb @@ -3,13 +3,10 @@ context "Write" do context "Batch" do context "With Reply Stream" do - stream_name = Controls::StreamName.example(category: 'testWriteReplyStreamBatch') - reply_stream_name = Controls::StreamName.example(category: 'testWriteReplyStreamBatchReplyStream') + stream_name = Controls::StreamName.example + reply_stream_name = Controls::StreamName.example - message_1 = Controls::Message.example(some_attribute: 'value_1') - message_2 = Controls::Message.example(some_attribute: 'value_2') - - batch = [message_1, message_2] + batch, values = Controls::Batch.example Write.(batch, stream_name, reply_stream_name: reply_stream_name) @@ -18,7 +15,7 @@ read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do - assert(read_event.metadata[:reply_stream_name] == reply_stream_name) + assert(read_event.data[:some_attribute] == values[i]) end end end diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index ce710a4..68e66f7 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -5,14 +5,14 @@ context "Message" do message = Controls::Message.example - reply_stream_name = Controls::StreamName.example(category: 'testReplyToMessage') + reply_stream_name = Controls::StreamName.example message.metadata.reply_stream_name = reply_stream_name writer = Write.build - written_position = writer.reply(message) + position = writer.reply(message) - read_event = EventSource::Postgres::Get.(reply_stream_name, position: written_position, batch_size: 1).first + read_event = EventSource::Postgres::Get.(reply_stream_name, position: position, batch_size: 1).first test "Writes the message to the reply stream" do assert(read_event.data == message.to_h) diff --git a/test/automated/write/message/reply_missing_reply_stream_name.rb b/test/automated/write/message/reply_missing_reply_stream_name_error.rb similarity index 80% rename from test/automated/write/message/reply_missing_reply_stream_name.rb rename to test/automated/write/message/reply_missing_reply_stream_name_error.rb index 8146a27..d2ff562 100644 --- a/test/automated/write/message/reply_missing_reply_stream_name.rb +++ b/test/automated/write/message/reply_missing_reply_stream_name_error.rb @@ -6,7 +6,7 @@ message = Controls::Message.example message.metadata.reply_stream_name = nil - reply_stream_name = Controls::StreamName.example(category: 'testReplyToMissingReplyStream') + reply_stream_name = Controls::StreamName.example writer = Write.build diff --git a/test/automated/write/message/write.rb b/test/automated/write/message/write.rb index fdafad4..a283930 100644 --- a/test/automated/write/message/write.rb +++ b/test/automated/write/message/write.rb @@ -2,13 +2,13 @@ context "Write" do context "Message" do - stream_name = Controls::StreamName.example(category: 'testWriteMessage') + stream_name = Controls::StreamName.example message = Controls::Message.example - written_position = Write.(message, stream_name) + position = Write.(message, stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: written_position, batch_size: 1).first + read_event = EventSource::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Writes the message" do assert(read_event.data == message.to_h) diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index 3f0f04f..1444ffd 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -3,7 +3,7 @@ context "Write" do context "Message" do context "Writing the initial event to a stream that has not been created yet" do - stream_name = Controls::StreamName.example(category: 'testWriteInitialMessage') + stream_name = Controls::StreamName.example message = Controls::Message.example diff --git a/test/automated/write/message/write_with_reply_stream.rb b/test/automated/write/message/write_with_reply_stream.rb index 29519cb..0e645c5 100644 --- a/test/automated/write/message/write_with_reply_stream.rb +++ b/test/automated/write/message/write_with_reply_stream.rb @@ -5,12 +5,12 @@ context "With Reply Stream" do message = Controls::Message.example - stream_name = Controls::StreamName.example(category: 'testWriteReplyStreamMessage') - reply_stream_name = Controls::StreamName.example(category: 'testWriteReplyStreamMessageReplyStream') + stream_name = Controls::StreamName.example + reply_stream_name = Controls::StreamName.example - written_position = Write.(message, stream_name, reply_stream_name: reply_stream_name) + position = Write.(message, stream_name, reply_stream_name: reply_stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: written_position, batch_size: 1).first + read_event = EventSource::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Sets the metadata reply stream name" do assert(read_event.metadata[:reply_stream_name] == reply_stream_name) From 1484697ce08967696c3f51ff1d6a8adbe82f054b Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sun, 20 Nov 2016 20:20:31 -0600 Subject: [PATCH 32/90] Batch control --- lib/messaging/postgres/controls/batch.rb | 26 +----------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/lib/messaging/postgres/controls/batch.rb b/lib/messaging/postgres/controls/batch.rb index 4a35971..d5b1395 100644 --- a/lib/messaging/postgres/controls/batch.rb +++ b/lib/messaging/postgres/controls/batch.rb @@ -1,31 +1,7 @@ module Messaging module Postgres module Controls - module Batch - def self.example - values = [ - EventSource::Controls::RandomValue.example, - EventSource::Controls::RandomValue.example - ] - - batch = Messages.example - - 2.times do |i| - batch[i].some_attribute = values[i] - end - - return batch, values - end - - module Messages - def self.example - [ - Controls::Message.example, - Controls::Message.example - ] - end - end - end + Batch = Messaging::Controls::Batch end end end From 5df4ae77d565e120178b7db35b01da5477ad2424 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sun, 20 Nov 2016 20:21:02 -0600 Subject: [PATCH 33/90] Package version increased from 0.3.0.0 to 0.3.0.1 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 8bdd73d..6615662 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'messaging-postgres' - s.version = '0.3.0.0' + s.version = '0.3.0.1' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From 9c437a2b8024846579b508eabf850235dbd707b4 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 26 Nov 2016 15:40:00 -0600 Subject: [PATCH 34/90] Changes to interactive tests in effort to target an issue with serialization --- test/interactive/{consumer.rb => consume.rb} | 2 +- .../consume_missing_stream_indefinately.rb | 14 ++++++++++++++ test/interactive/{producer.rb => produce.rb} | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) rename test/interactive/{consumer.rb => consume.rb} (96%) create mode 100644 test/interactive/consume_missing_stream_indefinately.rb rename test/interactive/{producer.rb => produce.rb} (96%) diff --git a/test/interactive/consumer.rb b/test/interactive/consume.rb similarity index 96% rename from test/interactive/consumer.rb rename to test/interactive/consume.rb index d1ba206..35a6483 100644 --- a/test/interactive/consumer.rb +++ b/test/interactive/consume.rb @@ -1,7 +1,7 @@ require_relative 'interactive_init' require_relative 'controls' -logger = Log.get('Consumer') +logger = Log.get('Consume') logger.info "Starting Consumer", tag: :test diff --git a/test/interactive/consume_missing_stream_indefinately.rb b/test/interactive/consume_missing_stream_indefinately.rb new file mode 100644 index 0000000..2e85653 --- /dev/null +++ b/test/interactive/consume_missing_stream_indefinately.rb @@ -0,0 +1,14 @@ +require_relative 'interactive_init' +require_relative 'controls' + +logger = Log.get('Consumer') + +logger.info "Starting Consumer - Read Indefinitely", tag: :test + +stream_name = SecureRandom.hex + +logger.info "Stream name: #{stream_name}", tag: :test + +logger.info "Starting reader", tag: :test + +EventSource::Postgres::Read.(stream_name, batch_size: 1, delay_milliseconds: 10) {} diff --git a/test/interactive/producer.rb b/test/interactive/produce.rb similarity index 96% rename from test/interactive/producer.rb rename to test/interactive/produce.rb index 7296212..2f6ce04 100644 --- a/test/interactive/producer.rb +++ b/test/interactive/produce.rb @@ -1,7 +1,7 @@ require_relative 'interactive_init' require_relative 'controls' -logger = Log.get('Producer') +logger = Log.get('Produce') logger.info "Starting Producer", tag: :test From 5c8c155efbb5392a7a5387da574aed0a0be572d1 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 26 Nov 2016 16:24:09 -0600 Subject: [PATCH 35/90] Updated cycle read's cycle parameter names --- test/interactive/consume.rb | 2 +- test/interactive/consume_missing_stream_indefinately.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/interactive/consume.rb b/test/interactive/consume.rb index 35a6483..111b9a3 100644 --- a/test/interactive/consume.rb +++ b/test/interactive/consume.rb @@ -17,7 +17,7 @@ logger.info "Starting reader", tag: :test -EventSource::Postgres::Read.(stream_name, batch_size: 1, delay_milliseconds: 10, timeout_milliseconds: 2000) do |event_data| +EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_delay_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| logger.debug event_data.pretty_inspect, tags: [:test, :data, :message] message = Handler.(event_data) diff --git a/test/interactive/consume_missing_stream_indefinately.rb b/test/interactive/consume_missing_stream_indefinately.rb index 2e85653..372e8eb 100644 --- a/test/interactive/consume_missing_stream_indefinately.rb +++ b/test/interactive/consume_missing_stream_indefinately.rb @@ -11,4 +11,4 @@ logger.info "Starting reader", tag: :test -EventSource::Postgres::Read.(stream_name, batch_size: 1, delay_milliseconds: 10) {} +EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_delay_milliseconds: 10) {} From a3ba213657f4fa84625c4099604924038c35ba18 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 30 Nov 2016 09:53:57 -0600 Subject: [PATCH 36/90] Pretty printing is already activated --- test/test_init.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_init.rb b/test/test_init.rb index 283bacb..dbd2da5 100755 --- a/test/test_init.rb +++ b/test/test_init.rb @@ -7,7 +7,6 @@ require 'test_bench'; TestBench.activate -require 'pp' require 'securerandom' require 'messaging/postgres/controls' From 0951283b1786e7d0c02bc6fc1d1838bc8c573fd2 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Tue, 13 Dec 2016 22:48:51 -0600 Subject: [PATCH 37/90] Write, rather than writer --- test/automated/write/batch/write_initial.rb | 8 ++++---- test/automated/write/message/reply.rb | 4 ++-- .../message/reply_missing_reply_stream_name_error.rb | 4 ++-- test/automated/write/message/write_initial.rb | 10 +++++----- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index d760c95..2f1daad 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -7,9 +7,9 @@ batch, values = Controls::Batch.example - writer = Write.build + write = Write.build - writer.write_initial(batch, stream_name) + write.write_initial(batch, stream_name) context "Individual Events are Written" do 2.times do |i| @@ -27,13 +27,13 @@ batch = Controls::Batch::Messages.example - writer = Write.build + write = Write.build message = Controls::Message.example Write.(message, stream_name) test "Is an error" do - assert proc { writer.write_initial(batch, stream_name) } do + assert proc { write.write_initial(batch, stream_name) } do raises_error? EventSource::ExpectedVersion::Error end end diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index 68e66f7..8d78f14 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -8,9 +8,9 @@ reply_stream_name = Controls::StreamName.example message.metadata.reply_stream_name = reply_stream_name - writer = Write.build + write = Write.build - position = writer.reply(message) + position = write.reply(message) read_event = EventSource::Postgres::Get.(reply_stream_name, position: position, batch_size: 1).first diff --git a/test/automated/write/message/reply_missing_reply_stream_name_error.rb b/test/automated/write/message/reply_missing_reply_stream_name_error.rb index d2ff562..10a1de7 100644 --- a/test/automated/write/message/reply_missing_reply_stream_name_error.rb +++ b/test/automated/write/message/reply_missing_reply_stream_name_error.rb @@ -8,10 +8,10 @@ reply_stream_name = Controls::StreamName.example - writer = Write.build + write = Write.build test "Is an error" do - assert proc { writer.reply(message) } do + assert proc { write.reply(message) } do raises_error? Messaging::Write::Error end end diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index 1444ffd..ef0d606 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -7,9 +7,9 @@ message = Controls::Message.example - writer = Write.build + write = Write.build - writer.write_initial(message, stream_name) + write.write_initial(message, stream_name) read_event = EventSource::Postgres::Get.(stream_name, position: 0, batch_size: 1).first @@ -23,12 +23,12 @@ message = Controls::Message.example - writer = Write.build + write = Write.build - writer.write(message, stream_name) + write.write(message, stream_name) test "Is an error" do - assert proc { writer.write_initial(message, stream_name) } do + assert proc { write.write_initial(message, stream_name) } do raises_error? EventSource::ExpectedVersion::Error end end From 677f23d79dd7810ddb3b221a3ad7a1e7298d36fb Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Tue, 13 Dec 2016 22:59:35 -0600 Subject: [PATCH 38/90] Initial, rather than write initial --- test/automated/write/batch/write_initial.rb | 4 ++-- test/automated/write/message/write_initial.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index 2f1daad..09b753e 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -9,7 +9,7 @@ write = Write.build - write.write_initial(batch, stream_name) + write.initial(batch, stream_name) context "Individual Events are Written" do 2.times do |i| @@ -33,7 +33,7 @@ Write.(message, stream_name) test "Is an error" do - assert proc { write.write_initial(batch, stream_name) } do + assert proc { write.initial(batch, stream_name) } do raises_error? EventSource::ExpectedVersion::Error end end diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index ef0d606..ec243cb 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -9,7 +9,7 @@ write = Write.build - write.write_initial(message, stream_name) + write.initial(message, stream_name) read_event = EventSource::Postgres::Get.(stream_name, position: 0, batch_size: 1).first @@ -25,10 +25,10 @@ write = Write.build - write.write(message, stream_name) + write.(message, stream_name) test "Is an error" do - assert proc { write.write_initial(message, stream_name) } do + assert proc { write.initial(message, stream_name) } do raises_error? EventSource::ExpectedVersion::Error end end From 9d198eaca62de74dac8bf0feea267421af3a29b2 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Tue, 13 Dec 2016 23:00:42 -0600 Subject: [PATCH 39/90] Package version increased from 0.3.0.1 to 0.4.0.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 6615662..65e3d52 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'messaging-postgres' - s.version = '0.3.0.1' + s.version = '0.4.0.0' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From 0df7643aa93c20003451f96dc0194a88dfaa77ad Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 14 Dec 2016 13:30:52 -0600 Subject: [PATCH 40/90] Database name is event_source --- settings/event_source_postgres.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/settings/event_source_postgres.json b/settings/event_source_postgres.json index 4f17e59..392938b 100644 --- a/settings/event_source_postgres.json +++ b/settings/event_source_postgres.json @@ -1,9 +1,9 @@ { - "dbname": "eventsource", + "dbname": "event_source", "host": "localhost", "hostaddr": "127.0.0.1", "port": 5432, - "user": "eventsource", + "user": "event_source", "password": null, "connect_timeout": null, "options": null, From 309a80c2fb2e2ebfe2c4664386ffec814ebd073a Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Mon, 19 Dec 2016 17:47:47 -0600 Subject: [PATCH 41/90] 'Required Ruby version is 2.3.3' --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 65e3d52..aa2a842 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.files = Dir.glob('{lib}/**/*') s.platform = Gem::Platform::RUBY - s.required_ruby_version = '>= 2.2.3' + s.required_ruby_version = '>= 2.3.3' s.add_runtime_dependency 'messaging' s.add_runtime_dependency 'event_source-postgres' From e99a4053c76f3c60bdef77c2a5cbf7b3123fff53 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Mon, 19 Dec 2016 21:41:00 -0600 Subject: [PATCH 42/90] Gem renamed to use the evt prefix --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index aa2a842..3504a33 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,6 +1,6 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| - s.name = 'messaging-postgres' + s.name = 'evt-messaging-postgres' s.version = '0.4.0.0' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From cdcaa0cd2a03c90c100a38cb0c5607c4c7769cfe Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Mon, 19 Dec 2016 23:04:35 -0600 Subject: [PATCH 43/90] Dependencies on rubygems.org --- messaging-postgres.gemspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 3504a33..62acc47 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -15,8 +15,8 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.required_ruby_version = '>= 2.3.3' - s.add_runtime_dependency 'messaging' - s.add_runtime_dependency 'event_source-postgres' + s.add_runtime_dependency 'evt-messaging' + s.add_runtime_dependency 'evt-event_source-postgres' - s.add_development_dependency 'test_bench' + s.add_development_dependency 'ntl-test_bench' end From 214a0832ba21c12683e1ee75e6b54051ae013554 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Tue, 20 Dec 2016 01:10:42 -0600 Subject: [PATCH 44/90] Package version increased from 0.4.0.0 to 0.4.0.1 --- messaging-postgres.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 62acc47..374aeb5 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.4.0.0' + s.version = '0.4.0.1' s.summary = 'Postgres messaging for Eventide' s.description = ' ' @@ -18,5 +18,5 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'evt-messaging' s.add_runtime_dependency 'evt-event_source-postgres' - s.add_development_dependency 'ntl-test_bench' + s.add_development_dependency 'test_bench' end From a6f2088782979c132cbc1f856279ff7cd3f1b8b4 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 21 Dec 2016 15:49:46 -0600 Subject: [PATCH 45/90] Interactive test's producer also measures throughput --- test/interactive/produce.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test/interactive/produce.rb b/test/interactive/produce.rb index 2f6ce04..a755660 100644 --- a/test/interactive/produce.rb +++ b/test/interactive/produce.rb @@ -3,6 +3,8 @@ logger = Log.get('Produce') +logger.level = :info + logger.info "Starting Producer", tag: :test stream_name = Controls::StreamName.example(category: 'testInteractive') @@ -18,15 +20,27 @@ end period = ENV['PERIOD'] -period ||= 500 +period ||= 0 period_seconds = Rational(period, 1000) -loop do +count = 0 +start_time = Time.now +1000.times do message = SomeMessage.build(written_time: "Written at: #{Clock::UTC.iso8601(precision: 5)}") logger.debug message.pretty_inspect, tags: [:test, :data, :message] written_position = Write.(message, stream_name) - logger.info "Wrote at position: #{written_position}", tags: [:test, :data, :message] + count += 1 + logger.debug "Wrote message ##{count} at position: #{written_position}", tags: [:test, :data, :message] sleep period_seconds end + +stop_time = Time.now + +duration = stop_time - start_time +throughput = count / duration + +logger.info "Messages: #{count}", tags: [:test, :data, :message] +logger.info "Duration: #{duration}", tags: [:test, :data, :message] +logger.info "Throughput: #{throughput}", tags: [:test, :data, :message] From c2467c4aa995def29d09bf26541a232c16b2f4a9 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 21 Dec 2016 15:55:18 -0600 Subject: [PATCH 46/90] Interactive test's consumer also measures throughput --- test/interactive/consume.rb | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/test/interactive/consume.rb b/test/interactive/consume.rb index 111b9a3..8a5fe76 100644 --- a/test/interactive/consume.rb +++ b/test/interactive/consume.rb @@ -3,6 +3,8 @@ logger = Log.get('Consume') +logger.level = :info + logger.info "Starting Consumer", tag: :test stream_name_file = File.expand_path('stream_name.tmp', File.dirname(__FILE__)) @@ -17,12 +19,26 @@ logger.info "Starting reader", tag: :test +handler = Handler.build + +count = 0 +start_time = Time.now EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_delay_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| - logger.debug event_data.pretty_inspect, tags: [:test, :data, :message] + logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } - message = Handler.(event_data) + message = handler.(event_data) + count += 1 - logger.info "Handled message: #{message.message_type}", tags: [:test, :data, :message] + logger.debug(tags: [:test, :data, :message]) { "Handled message: #{message.message_type}" } - logger.debug message.pretty_inspect, tags: [:test, :data, :message] + logger.debug(tags: [:test, :data, :message]) { message.pretty_inspect } end + +stop_time = Time.now + +duration = stop_time - start_time +throughput = count / duration + +logger.info "Messages: #{count}", tags: [:test, :data, :message] +logger.info "Duration: #{duration}", tags: [:test, :data, :message] +logger.info "Throughput: #{throughput}", tags: [:test, :data, :message] From 2f8c488d30c41667f7ff0ba3b3c37d55fcd1a46e Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 21 Dec 2016 17:38:19 -0600 Subject: [PATCH 47/90] Measurements are done in their own script --- test/interactive/consume.rb | 15 +------- test/interactive/measure.rb | 70 +++++++++++++++++++++++++++++++++++++ test/interactive/produce.rb | 20 +++-------- 3 files changed, 75 insertions(+), 30 deletions(-) create mode 100644 test/interactive/measure.rb diff --git a/test/interactive/consume.rb b/test/interactive/consume.rb index 8a5fe76..6642a1e 100644 --- a/test/interactive/consume.rb +++ b/test/interactive/consume.rb @@ -3,7 +3,7 @@ logger = Log.get('Consume') -logger.level = :info +logger.level = :debug logger.info "Starting Consumer", tag: :test @@ -21,24 +21,11 @@ handler = Handler.build -count = 0 -start_time = Time.now EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_delay_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } message = handler.(event_data) - count += 1 logger.debug(tags: [:test, :data, :message]) { "Handled message: #{message.message_type}" } - logger.debug(tags: [:test, :data, :message]) { message.pretty_inspect } end - -stop_time = Time.now - -duration = stop_time - start_time -throughput = count / duration - -logger.info "Messages: #{count}", tags: [:test, :data, :message] -logger.info "Duration: #{duration}", tags: [:test, :data, :message] -logger.info "Throughput: #{throughput}", tags: [:test, :data, :message] diff --git a/test/interactive/measure.rb b/test/interactive/measure.rb new file mode 100644 index 0000000..8a10b0b --- /dev/null +++ b/test/interactive/measure.rb @@ -0,0 +1,70 @@ +require_relative 'interactive_init' +require_relative 'controls' + +producer_logger = Log.get('Produce') +producer_logger.level = :info +producer_logger.info "Starting Producer", tag: :test + +stream_name = Controls::StreamName.example(category: 'testInteractive') +producer_logger.info "Stream name: #{stream_name}", tag: :test + +period = ENV['PERIOD'] +period ||= 0 +period_seconds = Rational(period, 1000) + +producer_count = 0 +producer_start_time = Time.now +1000.times do + message = SomeMessage.build(written_time: "Written at: #{Clock::UTC.iso8601(precision: 5)}") + producer_logger.debug message.pretty_inspect, tags: [:test, :data, :message] + + written_position = Write.(message, stream_name) + producer_count += 1 + producer_logger.debug "Wrote message ##{producer_count} at position: #{written_position}", tags: [:test, :data, :message] + + sleep period_seconds +end + +producer_stop_time = Time.now + + +consumer_logger = Log.get('Consume') +consumer_logger.level = :info +consumer_logger.info "Starting Consumer", tag: :test + +consumer_logger.info "Stream name: #{stream_name}", tag: :test + +consumer_logger.info "Starting reader", tag: :test + +handler = Handler.build + +consumer_count = 0 +consumer_start_time = Time.now +EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_delay_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| + consumer_logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } + + message = handler.(event_data) + consumer_count += 1 + + consumer_logger.debug(tags: [:test, :data, :message]) { "Handled message: #{message.message_type}" } + consumer_logger.debug(tags: [:test, :data, :message]) { message.pretty_inspect } +end + +consumer_stop_time = Time.now + + +producer_duration = producer_stop_time - producer_start_time +producer_throughput = producer_count / producer_duration + +producer_logger.info "Messages: #{producer_count}", tags: [:test, :data, :message] +producer_logger.info "Duration: #{producer_duration}", tags: [:test, :data, :message] +producer_logger.info "Throughput: #{producer_throughput}", tags: [:test, :data, :message] + + +consumer_duration = consumer_stop_time - consumer_start_time +consumer_throughput = consumer_count / consumer_duration + +consumer_logger.info "Messages: #{consumer_count}", tags: [:test, :data, :message] +consumer_logger.info "Duration: #{consumer_duration}", tags: [:test, :data, :message] +consumer_logger.info "Throughput: #{consumer_throughput}", tags: [:test, :data, :message] + diff --git a/test/interactive/produce.rb b/test/interactive/produce.rb index a755660..77341ce 100644 --- a/test/interactive/produce.rb +++ b/test/interactive/produce.rb @@ -3,7 +3,7 @@ logger = Log.get('Produce') -logger.level = :info +logger.level = :debug logger.info "Starting Producer", tag: :test @@ -20,27 +20,15 @@ end period = ENV['PERIOD'] -period ||= 0 +period ||= 500 period_seconds = Rational(period, 1000) -count = 0 -start_time = Time.now -1000.times do +loop do message = SomeMessage.build(written_time: "Written at: #{Clock::UTC.iso8601(precision: 5)}") logger.debug message.pretty_inspect, tags: [:test, :data, :message] written_position = Write.(message, stream_name) - count += 1 - logger.debug "Wrote message ##{count} at position: #{written_position}", tags: [:test, :data, :message] + logger.debug "Wrote message at position: #{written_position}", tags: [:test, :data, :message] sleep period_seconds end - -stop_time = Time.now - -duration = stop_time - start_time -throughput = count / duration - -logger.info "Messages: #{count}", tags: [:test, :data, :message] -logger.info "Duration: #{duration}", tags: [:test, :data, :message] -logger.info "Throughput: #{throughput}", tags: [:test, :data, :message] From e232855e18dcb30188bff91d28e87d8f7098fe70 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 21 Dec 2016 17:40:12 -0600 Subject: [PATCH 48/90] Reader in measurement script uses default batch size --- test/interactive/measure.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/interactive/measure.rb b/test/interactive/measure.rb index 8a10b0b..8711ceb 100644 --- a/test/interactive/measure.rb +++ b/test/interactive/measure.rb @@ -40,7 +40,7 @@ consumer_count = 0 consumer_start_time = Time.now -EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_delay_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| +EventSource::Postgres::Read.(stream_name) do |event_data| consumer_logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } message = handler.(event_data) From 290f0156e5ac04a6f736d8f7c522fa0e8c21b940 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Thu, 12 Jan 2017 19:24:58 -0600 Subject: [PATCH 49/90] Coverage of ID assignment is increased --- test/automated/write/batch/no_id.rb | 29 +++++++++++++++++++++++++++ test/automated/write/message/no_id.rb | 21 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 test/automated/write/batch/no_id.rb create mode 100644 test/automated/write/message/no_id.rb diff --git a/test/automated/write/batch/no_id.rb b/test/automated/write/batch/no_id.rb new file mode 100644 index 0000000..6d97849 --- /dev/null +++ b/test/automated/write/batch/no_id.rb @@ -0,0 +1,29 @@ +require_relative '../../automated_init' + +context "Write" do + context "Batch" do + context "No Message IDs" do + stream_name = Controls::StreamName.example + + batch, values = Controls::Batch.example(id: :none) + + batch.each do |message| + assert(message.id.nil?) + end + + position = Write.(batch, stream_name) + + context "Individual Events are Written" do + 2.times do |i| + read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + + context "Assigns an ID" do + test "Event #{i + 1}" do + refute(read_event.id.nil?) + end + end + end + end + end + end +end diff --git a/test/automated/write/message/no_id.rb b/test/automated/write/message/no_id.rb new file mode 100644 index 0000000..3df116f --- /dev/null +++ b/test/automated/write/message/no_id.rb @@ -0,0 +1,21 @@ +require_relative '../../automated_init' + +context "Write" do + context "Message" do + context "No ID" do + stream_name = Controls::StreamName.example + + message = Controls::Message.example(id: :none) + + assert(message.id.nil?) + + position = Write.(message, stream_name) + + read_event = EventSource::Postgres::Get.(stream_name, position: position, batch_size: 1).first + + test "Assigns an ID" do + refute(read_event.id.nil?) + end + end + end +end From 450b59e727ae8961ab647a6cbffd62989a935701 Mon Sep 17 00:00:00 2001 From: Nathan Ladd Date: Thu, 19 Jan 2017 13:21:18 -0600 Subject: [PATCH 50/90] Maximum milliseconds, not delay milliseconds --- test/interactive/consume.rb | 2 +- test/interactive/consume_missing_stream_indefinately.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/interactive/consume.rb b/test/interactive/consume.rb index 6642a1e..4e60e08 100644 --- a/test/interactive/consume.rb +++ b/test/interactive/consume.rb @@ -21,7 +21,7 @@ handler = Handler.build -EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_delay_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| +EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } message = handler.(event_data) diff --git a/test/interactive/consume_missing_stream_indefinately.rb b/test/interactive/consume_missing_stream_indefinately.rb index 372e8eb..49e1325 100644 --- a/test/interactive/consume_missing_stream_indefinately.rb +++ b/test/interactive/consume_missing_stream_indefinately.rb @@ -11,4 +11,4 @@ logger.info "Starting reader", tag: :test -EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_delay_milliseconds: 10) {} +EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10) {} From 5b1f413f82cf941e093fc6a64c19421f1c98c467 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Tue, 31 Jan 2017 22:51:36 -0600 Subject: [PATCH 51/90] Stream control is removed --- lib/messaging/postgres/controls.rb | 1 - lib/messaging/postgres/controls/stream.rb | 7 ------- 2 files changed, 8 deletions(-) delete mode 100644 lib/messaging/postgres/controls/stream.rb diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb index 0357684..887aed0 100644 --- a/lib/messaging/postgres/controls.rb +++ b/lib/messaging/postgres/controls.rb @@ -1,6 +1,5 @@ require 'messaging/controls' -require 'messaging/postgres/controls/stream' require 'messaging/postgres/controls/stream_name' require 'messaging/postgres/controls/message' require 'messaging/postgres/controls/batch' diff --git a/lib/messaging/postgres/controls/stream.rb b/lib/messaging/postgres/controls/stream.rb deleted file mode 100644 index 32552c8..0000000 --- a/lib/messaging/postgres/controls/stream.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Messaging - module Postgres - module Controls - Stream = Messaging::Controls::Stream - end - end -end From 6bdeb387ebddaaea5f1ae458d28fc8fe4e55834f Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Tue, 31 Jan 2017 22:52:03 -0600 Subject: [PATCH 52/90] Package version is updated from 0.4.0.1 to 0.5.0.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 374aeb5..bc7838c 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.4.0.1' + s.version = '0.5.0.0' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From 22d56378a394bd79fe4ea885d165dd6a3099360c Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 1 Feb 2017 02:03:24 -0600 Subject: [PATCH 53/90] Category stream name and command category stream name are platform specialization concerns --- lib/messaging/postgres.rb | 1 + .../postgres/controls/stream_name.rb | 14 +++++++ lib/messaging/postgres/stream_name.rb | 24 ++++++++++++ test/automated/stream_name.rb | 35 +++++++++++++++++ test/automated/stream_name_mixin.rb | 39 +++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 lib/messaging/postgres/stream_name.rb create mode 100644 test/automated/stream_name.rb create mode 100644 test/automated/stream_name_mixin.rb diff --git a/lib/messaging/postgres.rb b/lib/messaging/postgres.rb index 8254e1a..4330617 100644 --- a/lib/messaging/postgres.rb +++ b/lib/messaging/postgres.rb @@ -2,4 +2,5 @@ require 'event_source/postgres' require 'messaging/postgres/log' +require 'messaging/postgres/stream_name' require 'messaging/postgres/write' diff --git a/lib/messaging/postgres/controls/stream_name.rb b/lib/messaging/postgres/controls/stream_name.rb index 98b640e..1b1dde2 100644 --- a/lib/messaging/postgres/controls/stream_name.rb +++ b/lib/messaging/postgres/controls/stream_name.rb @@ -2,6 +2,20 @@ module Messaging module Postgres module Controls StreamName = Messaging::Controls::StreamName + + module StreamName + module Named + def self.example + Example.new + end + + class Example + include Messaging::Postgres::StreamName + + category :some_category + end + end + end end end end diff --git a/lib/messaging/postgres/stream_name.rb b/lib/messaging/postgres/stream_name.rb new file mode 100644 index 0000000..f0d5c96 --- /dev/null +++ b/lib/messaging/postgres/stream_name.rb @@ -0,0 +1,24 @@ +module Messaging + module Postgres + module StreamName + def self.included(cls) + cls.class_exec do + include Messaging::StreamName + end + end + + extend self + extend Messaging::StreamName + + def category_stream_name(category=nil) + category ||= self.category + category + end + + def command_category_stream_name(category=nil) + category ||= self.category + EventSource::StreamName.stream_name category, type: 'command' + end + end + end +end diff --git a/test/automated/stream_name.rb b/test/automated/stream_name.rb new file mode 100644 index 0000000..e1d8465 --- /dev/null +++ b/test/automated/stream_name.rb @@ -0,0 +1,35 @@ +require_relative 'automated_init' + +context "Stream Name" do + context "Category Stream Name" do + category_stream_name = StreamName.category_stream_name('someCategory') + + test "Is the category" do + assert(category_stream_name == 'someCategory') + end + end + + context "Identified Stream Name" do + stream_name = StreamName.stream_name('some_id', 'someCategory') + + test "Composed of the category name and an ID" do + assert(stream_name == 'someCategory-some_id') + end + end + + context "Command Stream Name" do + command_stream_name = StreamName.command_stream_name('some_id', 'someCategory') + + test "Composed of the command stream type token, category name, and an ID" do + assert(command_stream_name == 'someCategory:command-some_id') + end + end + + context "Command Category Stream Name" do + command_category_stream_name = StreamName.command_category_stream_name('someCategory') + + test "Composed of the command stream type token and the category name" do + assert(command_category_stream_name == 'someCategory:command') + end + end +end diff --git a/test/automated/stream_name_mixin.rb b/test/automated/stream_name_mixin.rb new file mode 100644 index 0000000..73bcb7c --- /dev/null +++ b/test/automated/stream_name_mixin.rb @@ -0,0 +1,39 @@ +require_relative 'automated_init' + +context "Stream Name" do + example = Controls::StreamName::Named.example + + context "Category" do + test "Camel-cased name specified by the category macro" do + assert(example.category == 'someCategory') + end + end + + context "Identified Stream Name" do + stream_name = example.stream_name('some_id') + test "Composed of the category name and an ID" do + assert(stream_name == 'someCategory-some_id') + end + end + + context "Command Stream Name" do + command_stream_name = example.command_stream_name('some_id') + test "Composed of the command stream type token, category name, and an ID" do + assert(command_stream_name == 'someCategory:command-some_id') + end + end + + context "Category Stream Name" do + category_stream_name = example.category_stream_name + test "Is the category name" do + assert(category_stream_name == example.category) + end + end + + context "Command Category Stream Name" do + command_category_stream_name = example.command_category_stream_name + test "Composed of the command stream type token and the category name" do + assert(command_category_stream_name == 'someCategory:command') + end + end +end From c3cba2e03c3eb6b9e538553bc89f3dc86ab3efd9 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 1 Feb 2017 02:04:06 -0600 Subject: [PATCH 54/90] Package version is increased from 0.5.0.0 to 0.5.1.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index bc7838c..cb6d947 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.5.0.0' + s.version = '0.5.1.0' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From d7003fd79df1f33d1f141bd8f0b02efb7a25718c Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 4 Feb 2017 21:19:00 -0600 Subject: [PATCH 55/90] Stream name generalizations are moved to specialization library --- lib/messaging/postgres/controls.rb | 1 + .../postgres/controls/stream_name.rb | 2 +- lib/messaging/postgres/stream_name.rb | 46 +++++++++++++++++-- test/automated/stream_name.rb | 35 -------------- test/automated/stream_name_mixin.rb | 39 ---------------- 5 files changed, 43 insertions(+), 80 deletions(-) delete mode 100644 test/automated/stream_name.rb delete mode 100644 test/automated/stream_name_mixin.rb diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb index 887aed0..30405f4 100644 --- a/lib/messaging/postgres/controls.rb +++ b/lib/messaging/postgres/controls.rb @@ -1,3 +1,4 @@ +require 'event_source/postgres/controls' require 'messaging/controls' require 'messaging/postgres/controls/stream_name' diff --git a/lib/messaging/postgres/controls/stream_name.rb b/lib/messaging/postgres/controls/stream_name.rb index 1b1dde2..ea92cf2 100644 --- a/lib/messaging/postgres/controls/stream_name.rb +++ b/lib/messaging/postgres/controls/stream_name.rb @@ -1,7 +1,7 @@ module Messaging module Postgres module Controls - StreamName = Messaging::Controls::StreamName + StreamName = EventSource::Postgres::Controls::StreamName module StreamName module Named diff --git a/lib/messaging/postgres/stream_name.rb b/lib/messaging/postgres/stream_name.rb index f0d5c96..32ed848 100644 --- a/lib/messaging/postgres/stream_name.rb +++ b/lib/messaging/postgres/stream_name.rb @@ -1,23 +1,59 @@ module Messaging module Postgres module StreamName + extend self + def self.included(cls) - cls.class_exec do - include Messaging::StreamName + cls.extend Macro + end + + def self.activate + target_class ||= Object + macro_module = Macro + return if target_class.is_a? macro_module + target_class.extend(macro_module) + end + + module Macro + def category_macro(category) + category = Casing::Camel.(category, symbol_to_string: true) + self.send :define_method, :category do + @category ||= category + end + + self.send :define_method, :category= do |category| + @category = category + end end + alias :category :category_macro end - extend self - extend Messaging::StreamName + def stream_name(id, category=nil, type: nil) + category ||= self.category + EventSource::Postgres::StreamName.stream_name(category, id, type: type) + end def category_stream_name(category=nil) category ||= self.category category end + def command_stream_name(id, category=nil) + category ||= self.category + EventSource::Postgres::StreamName.stream_name(category, id, type: 'command') + end + def command_category_stream_name(category=nil) category ||= self.category - EventSource::StreamName.stream_name category, type: 'command' + EventSource::Postgres::StreamName.stream_name(category, type: 'command') + end + + def self.get_category(stream_name) + EventSource::Postgres::StreamName.get_category(stream_name) + end + + def self.get_id(stream_name) + EventSource::Postgres::StreamName.get_id stream_name end end end diff --git a/test/automated/stream_name.rb b/test/automated/stream_name.rb deleted file mode 100644 index e1d8465..0000000 --- a/test/automated/stream_name.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative 'automated_init' - -context "Stream Name" do - context "Category Stream Name" do - category_stream_name = StreamName.category_stream_name('someCategory') - - test "Is the category" do - assert(category_stream_name == 'someCategory') - end - end - - context "Identified Stream Name" do - stream_name = StreamName.stream_name('some_id', 'someCategory') - - test "Composed of the category name and an ID" do - assert(stream_name == 'someCategory-some_id') - end - end - - context "Command Stream Name" do - command_stream_name = StreamName.command_stream_name('some_id', 'someCategory') - - test "Composed of the command stream type token, category name, and an ID" do - assert(command_stream_name == 'someCategory:command-some_id') - end - end - - context "Command Category Stream Name" do - command_category_stream_name = StreamName.command_category_stream_name('someCategory') - - test "Composed of the command stream type token and the category name" do - assert(command_category_stream_name == 'someCategory:command') - end - end -end diff --git a/test/automated/stream_name_mixin.rb b/test/automated/stream_name_mixin.rb deleted file mode 100644 index 73bcb7c..0000000 --- a/test/automated/stream_name_mixin.rb +++ /dev/null @@ -1,39 +0,0 @@ -require_relative 'automated_init' - -context "Stream Name" do - example = Controls::StreamName::Named.example - - context "Category" do - test "Camel-cased name specified by the category macro" do - assert(example.category == 'someCategory') - end - end - - context "Identified Stream Name" do - stream_name = example.stream_name('some_id') - test "Composed of the category name and an ID" do - assert(stream_name == 'someCategory-some_id') - end - end - - context "Command Stream Name" do - command_stream_name = example.command_stream_name('some_id') - test "Composed of the command stream type token, category name, and an ID" do - assert(command_stream_name == 'someCategory:command-some_id') - end - end - - context "Category Stream Name" do - category_stream_name = example.category_stream_name - test "Is the category name" do - assert(category_stream_name == example.category) - end - end - - context "Command Category Stream Name" do - command_category_stream_name = example.command_category_stream_name - test "Composed of the command stream type token and the category name" do - assert(command_category_stream_name == 'someCategory:command') - end - end -end From 95bf3f461298962fd9ecb2b9eb93aa76515d1327 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 4 Feb 2017 21:46:39 -0600 Subject: [PATCH 56/90] Test coverage from generalization library is moved into tests for this library --- test/automated/stream_name/get_category.rb | 57 +++++++++++++++++++ test/automated/stream_name/get_id.rb | 19 +++++++ test/automated/stream_name/macro.rb | 15 +++++ test/automated/stream_name/stream_name.rb | 35 ++++++++++++ .../stream_name/stream_name_mixin.rb | 53 +++++++++++++++++ 5 files changed, 179 insertions(+) create mode 100644 test/automated/stream_name/get_category.rb create mode 100644 test/automated/stream_name/get_id.rb create mode 100644 test/automated/stream_name/macro.rb create mode 100644 test/automated/stream_name/stream_name.rb create mode 100644 test/automated/stream_name/stream_name_mixin.rb diff --git a/test/automated/stream_name/get_category.rb b/test/automated/stream_name/get_category.rb new file mode 100644 index 0000000..e13742c --- /dev/null +++ b/test/automated/stream_name/get_category.rb @@ -0,0 +1,57 @@ +require_relative '../automated_init' + +context "Stream Name" do + context "Get Category" do + category = 'someStream' + + context "Stream Name Contains an ID" do + id = Identifier::UUID.random + stream_name = "#{category}-#{id}" + + stream_category = StreamName.get_category(stream_name) + + test "Category name is the part of the stream name before the first dash" do + assert(stream_category == category) + end + end + + context "Stream Name Contains no ID" do + stream_name = category + stream_category = StreamName.get_category(stream_name) + + test "Category name is the stream name" do + assert(stream_category == category) + end + end + + context "Stream Name Contains Type" do + stream_name = "#{category}:someType" + stream_category = StreamName.get_category(stream_name) + + test "Category name is the stream name" do + assert(stream_category == stream_name) + end + end + + context "Stream Name Contains Types" do + stream_name = "#{category}:someType+someOtherType" + stream_category = StreamName.get_category(stream_name) + + test "Category name is the stream name" do + assert(stream_category == stream_name) + end + end + + context "Stream Name Contains ID and Types" do + id = Identifier::UUID.random + category_and_types = "#{category}:someType+someOtherType" + stream_name = "#{category_and_types}-#{id}" + + stream_category = StreamName.get_category(stream_name) + + test "Category name is the stream name" do + assert(stream_category == category_and_types) + end + end + end +end diff --git a/test/automated/stream_name/get_id.rb b/test/automated/stream_name/get_id.rb new file mode 100644 index 0000000..e8fa9d8 --- /dev/null +++ b/test/automated/stream_name/get_id.rb @@ -0,0 +1,19 @@ +require_relative '../automated_init' + +context "Stream Name" do + context "Get ID" do + test "Is the part of a stream name after the first dash" do + id = Identifier::UUID.random + stream_name = "someStream-#{id}" + + stream_id = StreamName.get_id(stream_name) + + assert(stream_id == id) + end + + test "Is nil if there is no ID part in the stream name" do + stream_id = StreamName.get_id('someStream') + assert(stream_id.nil?) + end + end +end diff --git a/test/automated/stream_name/macro.rb b/test/automated/stream_name/macro.rb new file mode 100644 index 0000000..9576598 --- /dev/null +++ b/test/automated/stream_name/macro.rb @@ -0,0 +1,15 @@ +require_relative '../automated_init' + +context "Stream Name" do + example = Messaging::Controls::StreamName::Named.example + + context "Macro" do + test "Adds the category getter" do + assert(example.respond_to? :category) + end + + test "Adds the category setter" do + assert(example.respond_to? :category=) + end + end +end diff --git a/test/automated/stream_name/stream_name.rb b/test/automated/stream_name/stream_name.rb new file mode 100644 index 0000000..bf5819d --- /dev/null +++ b/test/automated/stream_name/stream_name.rb @@ -0,0 +1,35 @@ +require_relative '../automated_init' + +context "Stream Name" do + context "Stream Name" do + stream_name = StreamName.stream_name('some_id', 'someCategory') + + test "Composed of the category name and an ID" do + assert(stream_name == 'someCategory-some_id') + end + end + + context "Category Stream Name" do + category_stream_name = StreamName.category_stream_name('someCategory') + + test "Is the category" do + assert(category_stream_name == 'someCategory') + end + end + + context "Command Stream Name" do + command_stream_name = StreamName.command_stream_name('some_id', 'someCategory') + + test "Composed of the command stream type token, category name, and an ID" do + assert(command_stream_name == 'someCategory:command-some_id') + end + end + + context "Command Category Stream Name" do + command_category_stream_name = StreamName.command_category_stream_name('someCategory') + + test "Composed of the command stream type token and the category name" do + assert(command_category_stream_name == 'someCategory:command') + end + end +end diff --git a/test/automated/stream_name/stream_name_mixin.rb b/test/automated/stream_name/stream_name_mixin.rb new file mode 100644 index 0000000..0ca6bf9 --- /dev/null +++ b/test/automated/stream_name/stream_name_mixin.rb @@ -0,0 +1,53 @@ +require_relative '../automated_init' + +context "Stream Name" do + example = Controls::StreamName::Named.example + + context "Category Macro" do + context "Specify Category" do + test "Camel-cased name specified by the category macro" do + assert(example.category == 'someCategory') + end + end + + context "Overridden" do + category = 'otherCategory' + + overridden_example = Controls::StreamName::Named.example + + overridden_example.category = category + + test do + assert(overridden_example.category == category) + end + end + end + + context "Stream Name" do + stream_name = example.stream_name('some_id') + test "Composed of the category name and an ID" do + assert(stream_name == 'someCategory-some_id') + end + end + + context "Category Stream Name" do + category_stream_name = example.category_stream_name + test "Is the category name" do + assert(category_stream_name == example.category) + end + end + + context "Command Stream Name" do + command_stream_name = example.command_stream_name('some_id') + test "Composed of the command stream type token, category name, and an ID" do + assert(command_stream_name == 'someCategory:command-some_id') + end + end + + context "Command Category Stream Name" do + command_category_stream_name = example.command_category_stream_name + test "Composed of the command stream type token and the category name" do + assert(command_category_stream_name == 'someCategory:command') + end + end +end From 5b41f0e6bd5126c6c5554f6b6735837ed4596bdf Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 4 Feb 2017 23:18:38 -0600 Subject: [PATCH 57/90] Package version increased from 0.5.1.0 to 0.6.0.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index cb6d947..dcbfc6c 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.5.1.0' + s.version = '0.6.0.0' s.summary = 'Postgres messaging for Eventide' s.description = ' ' From 0ed6308b68f7fe2f704eb8ec74682ca85a4965c0 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 4 Feb 2017 23:28:27 -0600 Subject: [PATCH 58/90] Reference of vestigial constant is removed --- test/automated/stream_name/macro.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/automated/stream_name/macro.rb b/test/automated/stream_name/macro.rb index 9576598..c2d1b1e 100644 --- a/test/automated/stream_name/macro.rb +++ b/test/automated/stream_name/macro.rb @@ -1,7 +1,7 @@ require_relative '../automated_init' context "Stream Name" do - example = Messaging::Controls::StreamName::Named.example + example = Controls::StreamName::Named.example context "Macro" do test "Adds the category getter" do From 4d6759a31d8ab7781ec50aebeb6fe189c327fda5 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Sat, 4 Feb 2017 23:38:00 -0600 Subject: [PATCH 59/90] Category macro is moved to generalization --- lib/messaging/postgres/stream_name.rb | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/lib/messaging/postgres/stream_name.rb b/lib/messaging/postgres/stream_name.rb index 32ed848..a3d018c 100644 --- a/lib/messaging/postgres/stream_name.rb +++ b/lib/messaging/postgres/stream_name.rb @@ -4,28 +4,9 @@ module StreamName extend self def self.included(cls) - cls.extend Macro - end - - def self.activate - target_class ||= Object - macro_module = Macro - return if target_class.is_a? macro_module - target_class.extend(macro_module) - end - - module Macro - def category_macro(category) - category = Casing::Camel.(category, symbol_to_string: true) - self.send :define_method, :category do - @category ||= category - end - - self.send :define_method, :category= do |category| - @category = category - end + cls.class_exec do + include Messaging::Category end - alias :category :category_macro end def stream_name(id, category=nil, type: nil) From 74e0701abc7c3aa352641100833adef105aeb15d Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Fri, 19 May 2017 16:39:36 -0500 Subject: [PATCH 60/90] Draft of overview documentation --- README.md | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) diff --git a/README.md b/README.md index 69127e1..9d9f977 100755 --- a/README.md +++ b/README.md @@ -2,6 +2,129 @@ Postgres messaging for Eventide +## Summary + +The `messaging-postgres` library contains primitives for writing and reading messages, as well as message handlers and mixins for message schemas and stream name utilities. + +## Example + +```ruby +account_id = ‘123’ + +deposit = Deposit.new +deposit.account_id = account_id +deposit.amount = 11 + +stream_name = StreamName.stream_name(account_id, 'account') +# => 'account-123' + +Messaging::Postgres::Write.(deposit, stream_name) + +Messaging::Postgres::Read.(stream_name) do |message_data| + AccountComponent::Handlers::Command.(message_data) +end +``` + +## Elements + +### Handlers + +A Handler is the mechanism that receives messages, and takes action based on them. + +By including `Messaging::Handle`, a class becomes a handler. By including `Messaging::Postgres::StreamName` the handler class receives some useful utilities for composing stream names from constituent parts (category and an entity's ID), and for declaring a the category name that the handler is concerned with (eg: `account`, `fundsTransfer`, `userProfile`, etc). + +```ruby +module AccountComponent + module Handlers + class Commands + include Messaging::Handle + include Messaging::Postgres::StreamName + + category :account + + handle Deposit do |deposit| + account_id = deposit.account_id + + time = clock.iso8601 + + deposited = Deposited.follow(deposit) + + stream_name = stream_name(account_id) + + write.(deposited, stream_name, expected_version: version) + end + end + end +end +``` + +### Messages + +Messages are typically simplistic data structures that carry instructions and responses to and from services. + +By including `Messaging::Message`, a message class can declare attributes that will become part of a message's payload. + +```ruby +module AccountComponent + module Messages + module Commands + class Deposit + include Messaging::Message + + attribute :deposit_id, String + attribute :account_id, String + attribute :amount, Numeric + attribute :time, String + end + end + end +end + +deposit = AccountComponent::Messages::Commands::Deposit.new + +deposit.deposit_id = Identifier::UUID::Random.get +deposit.account_id = account_id +deposit.amount = 11 +deposit.time = clock.iso8601 +``` + +### Reading Messages + +The `Messaging::Postgres::Read` class provides access to streams stored in Postgres. The reader takes a block that receives raw _message data_, and executes the block for each message data received. + +```ruby +stream_name = 'account-123' + +Messaging::Postgres::Read.(stream_name) do |message_data| + puts message_data.type +end +``` + +### Writing Messages + +The `Messaging::Postgres::Write` class writes a message to a stream. The message is converted to raw _message data_ first, then written to the data store. + +```ruby +deposit = AccountComponent::Messages::Commands::Deposit.new + +deposit.deposit_id = Identifier::UUID::Random.get +deposit.account_id = account_id +deposit.amount = 11 +deposit.time = clock.iso8601 + +stream_name = 'account-123' + +Messaging::Postgres::Write.(deposit, stream_name) +``` + +## Detailed Examples + +For a more in-depth example of the use of this library, see the example projects in the Eventide Examples org on GitHub: https://github.com/eventide-examples + +## Complete Documentation + +The complete Eventide project documentation can be found at http://eventide-project.org + ## License The `messaging-postgres` library is released under the [MIT License](https://github.com/eventide-project/messaging-postgres/blob/master/MIT-License.txt). From 8d0fa1589e12d1c43af741be011cfaf845173974 Mon Sep 17 00:00:00 2001 From: ntl Date: Fri, 26 May 2017 14:23:03 -0500 Subject: [PATCH 61/90] EventSource, EventData is renamed to MessageStore, MessageData --- lib/messaging/postgres.rb | 1 - .../postgres/controls/stream_name.rb | 16 +----- lib/messaging/postgres/stream_name.rb | 10 ++-- lib/messaging/postgres/write.rb | 2 +- test/automated/stream_name/get_category.rb | 57 ------------------- test/automated/stream_name/get_id.rb | 19 ------- test/automated/stream_name/macro.rb | 15 ----- test/automated/stream_name/stream_name.rb | 35 ------------ .../stream_name/stream_name_mixin.rb | 53 ----------------- test/automated/write/batch/no_id.rb | 2 +- test/automated/write/batch/write.rb | 4 +- test/automated/write/batch/write_initial.rb | 6 +- .../write/batch/write_with_reply_stream.rb | 4 +- test/automated/write/expected_version.rb | 2 +- test/automated/write/message/no_id.rb | 2 +- test/automated/write/message/reply.rb | 4 +- test/automated/write/message/write.rb | 4 +- test/automated/write/message/write_initial.rb | 6 +- .../write/message/write_with_reply_stream.rb | 2 +- test/interactive/consume.rb | 6 +- .../consume_missing_stream_indefinately.rb | 2 +- test/interactive/measure.rb | 6 +- 22 files changed, 32 insertions(+), 226 deletions(-) delete mode 100644 test/automated/stream_name/get_category.rb delete mode 100644 test/automated/stream_name/get_id.rb delete mode 100644 test/automated/stream_name/macro.rb delete mode 100644 test/automated/stream_name/stream_name.rb delete mode 100644 test/automated/stream_name/stream_name_mixin.rb diff --git a/lib/messaging/postgres.rb b/lib/messaging/postgres.rb index 4330617..8254e1a 100644 --- a/lib/messaging/postgres.rb +++ b/lib/messaging/postgres.rb @@ -2,5 +2,4 @@ require 'event_source/postgres' require 'messaging/postgres/log' -require 'messaging/postgres/stream_name' require 'messaging/postgres/write' diff --git a/lib/messaging/postgres/controls/stream_name.rb b/lib/messaging/postgres/controls/stream_name.rb index ea92cf2..98b640e 100644 --- a/lib/messaging/postgres/controls/stream_name.rb +++ b/lib/messaging/postgres/controls/stream_name.rb @@ -1,21 +1,7 @@ module Messaging module Postgres module Controls - StreamName = EventSource::Postgres::Controls::StreamName - - module StreamName - module Named - def self.example - Example.new - end - - class Example - include Messaging::Postgres::StreamName - - category :some_category - end - end - end + StreamName = Messaging::Controls::StreamName end end end diff --git a/lib/messaging/postgres/stream_name.rb b/lib/messaging/postgres/stream_name.rb index a3d018c..f5bea43 100644 --- a/lib/messaging/postgres/stream_name.rb +++ b/lib/messaging/postgres/stream_name.rb @@ -11,7 +11,7 @@ def self.included(cls) def stream_name(id, category=nil, type: nil) category ||= self.category - EventSource::Postgres::StreamName.stream_name(category, id, type: type) + MessageStore::Postgres::StreamName.stream_name(category, id, type: type) end def category_stream_name(category=nil) @@ -21,20 +21,20 @@ def category_stream_name(category=nil) def command_stream_name(id, category=nil) category ||= self.category - EventSource::Postgres::StreamName.stream_name(category, id, type: 'command') + MessageStore::Postgres::StreamName.stream_name(category, id, type: 'command') end def command_category_stream_name(category=nil) category ||= self.category - EventSource::Postgres::StreamName.stream_name(category, type: 'command') + MessageStore::Postgres::StreamName.stream_name(category, type: 'command') end def self.get_category(stream_name) - EventSource::Postgres::StreamName.get_category(stream_name) + MessageStore::Postgres::StreamName.get_category(stream_name) end def self.get_id(stream_name) - EventSource::Postgres::StreamName.get_id stream_name + MessageStore::Postgres::StreamName.get_id stream_name end end end diff --git a/lib/messaging/postgres/write.rb b/lib/messaging/postgres/write.rb index 3729ae1..546b93a 100644 --- a/lib/messaging/postgres/write.rb +++ b/lib/messaging/postgres/write.rb @@ -4,7 +4,7 @@ class Write include Messaging::Write def configure(session: nil) - EventSource::Postgres::Write.configure(self, attr_name: :event_writer, session: nil) + MessageStore::Postgres::Write.configure(self, attr_name: :message_writer, session: nil) end end end diff --git a/test/automated/stream_name/get_category.rb b/test/automated/stream_name/get_category.rb deleted file mode 100644 index e13742c..0000000 --- a/test/automated/stream_name/get_category.rb +++ /dev/null @@ -1,57 +0,0 @@ -require_relative '../automated_init' - -context "Stream Name" do - context "Get Category" do - category = 'someStream' - - context "Stream Name Contains an ID" do - id = Identifier::UUID.random - stream_name = "#{category}-#{id}" - - stream_category = StreamName.get_category(stream_name) - - test "Category name is the part of the stream name before the first dash" do - assert(stream_category == category) - end - end - - context "Stream Name Contains no ID" do - stream_name = category - stream_category = StreamName.get_category(stream_name) - - test "Category name is the stream name" do - assert(stream_category == category) - end - end - - context "Stream Name Contains Type" do - stream_name = "#{category}:someType" - stream_category = StreamName.get_category(stream_name) - - test "Category name is the stream name" do - assert(stream_category == stream_name) - end - end - - context "Stream Name Contains Types" do - stream_name = "#{category}:someType+someOtherType" - stream_category = StreamName.get_category(stream_name) - - test "Category name is the stream name" do - assert(stream_category == stream_name) - end - end - - context "Stream Name Contains ID and Types" do - id = Identifier::UUID.random - category_and_types = "#{category}:someType+someOtherType" - stream_name = "#{category_and_types}-#{id}" - - stream_category = StreamName.get_category(stream_name) - - test "Category name is the stream name" do - assert(stream_category == category_and_types) - end - end - end -end diff --git a/test/automated/stream_name/get_id.rb b/test/automated/stream_name/get_id.rb deleted file mode 100644 index e8fa9d8..0000000 --- a/test/automated/stream_name/get_id.rb +++ /dev/null @@ -1,19 +0,0 @@ -require_relative '../automated_init' - -context "Stream Name" do - context "Get ID" do - test "Is the part of a stream name after the first dash" do - id = Identifier::UUID.random - stream_name = "someStream-#{id}" - - stream_id = StreamName.get_id(stream_name) - - assert(stream_id == id) - end - - test "Is nil if there is no ID part in the stream name" do - stream_id = StreamName.get_id('someStream') - assert(stream_id.nil?) - end - end -end diff --git a/test/automated/stream_name/macro.rb b/test/automated/stream_name/macro.rb deleted file mode 100644 index c2d1b1e..0000000 --- a/test/automated/stream_name/macro.rb +++ /dev/null @@ -1,15 +0,0 @@ -require_relative '../automated_init' - -context "Stream Name" do - example = Controls::StreamName::Named.example - - context "Macro" do - test "Adds the category getter" do - assert(example.respond_to? :category) - end - - test "Adds the category setter" do - assert(example.respond_to? :category=) - end - end -end diff --git a/test/automated/stream_name/stream_name.rb b/test/automated/stream_name/stream_name.rb deleted file mode 100644 index bf5819d..0000000 --- a/test/automated/stream_name/stream_name.rb +++ /dev/null @@ -1,35 +0,0 @@ -require_relative '../automated_init' - -context "Stream Name" do - context "Stream Name" do - stream_name = StreamName.stream_name('some_id', 'someCategory') - - test "Composed of the category name and an ID" do - assert(stream_name == 'someCategory-some_id') - end - end - - context "Category Stream Name" do - category_stream_name = StreamName.category_stream_name('someCategory') - - test "Is the category" do - assert(category_stream_name == 'someCategory') - end - end - - context "Command Stream Name" do - command_stream_name = StreamName.command_stream_name('some_id', 'someCategory') - - test "Composed of the command stream type token, category name, and an ID" do - assert(command_stream_name == 'someCategory:command-some_id') - end - end - - context "Command Category Stream Name" do - command_category_stream_name = StreamName.command_category_stream_name('someCategory') - - test "Composed of the command stream type token and the category name" do - assert(command_category_stream_name == 'someCategory:command') - end - end -end diff --git a/test/automated/stream_name/stream_name_mixin.rb b/test/automated/stream_name/stream_name_mixin.rb deleted file mode 100644 index 0ca6bf9..0000000 --- a/test/automated/stream_name/stream_name_mixin.rb +++ /dev/null @@ -1,53 +0,0 @@ -require_relative '../automated_init' - -context "Stream Name" do - example = Controls::StreamName::Named.example - - context "Category Macro" do - context "Specify Category" do - test "Camel-cased name specified by the category macro" do - assert(example.category == 'someCategory') - end - end - - context "Overridden" do - category = 'otherCategory' - - overridden_example = Controls::StreamName::Named.example - - overridden_example.category = category - - test do - assert(overridden_example.category == category) - end - end - end - - context "Stream Name" do - stream_name = example.stream_name('some_id') - test "Composed of the category name and an ID" do - assert(stream_name == 'someCategory-some_id') - end - end - - context "Category Stream Name" do - category_stream_name = example.category_stream_name - test "Is the category name" do - assert(category_stream_name == example.category) - end - end - - context "Command Stream Name" do - command_stream_name = example.command_stream_name('some_id') - test "Composed of the command stream type token, category name, and an ID" do - assert(command_stream_name == 'someCategory:command-some_id') - end - end - - context "Command Category Stream Name" do - command_category_stream_name = example.command_category_stream_name - test "Composed of the command stream type token and the category name" do - assert(command_category_stream_name == 'someCategory:command') - end - end -end diff --git a/test/automated/write/batch/no_id.rb b/test/automated/write/batch/no_id.rb index 6d97849..9676e71 100644 --- a/test/automated/write/batch/no_id.rb +++ b/test/automated/write/batch/no_id.rb @@ -15,7 +15,7 @@ context "Individual Events are Written" do 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first context "Assigns an ID" do test "Event #{i + 1}" do diff --git a/test/automated/write/batch/write.rb b/test/automated/write/batch/write.rb index cc86f1c..3001699 100644 --- a/test/automated/write/batch/write.rb +++ b/test/automated/write/batch/write.rb @@ -14,10 +14,10 @@ context "Individual Events are Written" do 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == values[i]) + assert(read_message.data[:some_attribute] == values[i]) end end end diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index 09b753e..45a0ea0 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -13,10 +13,10 @@ context "Individual Events are Written" do 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == values[i]) + assert(read_message.data[:some_attribute] == values[i]) end end end @@ -34,7 +34,7 @@ test "Is an error" do assert proc { write.initial(batch, stream_name) } do - raises_error? EventSource::ExpectedVersion::Error + raises_error? MessageStore::ExpectedVersion::Error end end end diff --git a/test/automated/write/batch/write_with_reply_stream.rb b/test/automated/write/batch/write_with_reply_stream.rb index a19070f..2546e64 100644 --- a/test/automated/write/batch/write_with_reply_stream.rb +++ b/test/automated/write/batch/write_with_reply_stream.rb @@ -12,10 +12,10 @@ context "Individual Events are Written" do 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == values[i]) + assert(read_message.data[:some_attribute] == values[i]) end end end diff --git a/test/automated/write/expected_version.rb b/test/automated/write/expected_version.rb index 12cbf56..4967ab3 100644 --- a/test/automated/write/expected_version.rb +++ b/test/automated/write/expected_version.rb @@ -19,7 +19,7 @@ context "Wrong Version" do test "Fails" do assert proc { Write.(message_2, stream_name, expected_version: 11) } do - raises_error? EventSource::ExpectedVersion::Error + raises_error? MessageStore::ExpectedVersion::Error end end end diff --git a/test/automated/write/message/no_id.rb b/test/automated/write/message/no_id.rb index 3df116f..59a6897 100644 --- a/test/automated/write/message/no_id.rb +++ b/test/automated/write/message/no_id.rb @@ -11,7 +11,7 @@ position = Write.(message, stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Assigns an ID" do refute(read_event.id.nil?) diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index 8d78f14..487c668 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -12,10 +12,10 @@ position = write.reply(message) - read_event = EventSource::Postgres::Get.(reply_stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(reply_stream_name, position: position, batch_size: 1).first test "Writes the message to the reply stream" do - assert(read_event.data == message.to_h) + assert(read_message.data == message.to_h) end test "Clears the reply stream from the metadata" do diff --git a/test/automated/write/message/write.rb b/test/automated/write/message/write.rb index a283930..521419a 100644 --- a/test/automated/write/message/write.rb +++ b/test/automated/write/message/write.rb @@ -8,10 +8,10 @@ position = Write.(message, stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Writes the message" do - assert(read_event.data == message.to_h) + assert(read_message.data == message.to_h) end end end diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index ec243cb..668874b 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -11,10 +11,10 @@ write.initial(message, stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: 0, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: 0, batch_size: 1).first test "Writes the message" do - assert(read_event.data == message.to_h) + assert(read_message.data == message.to_h) end end @@ -29,7 +29,7 @@ test "Is an error" do assert proc { write.initial(message, stream_name) } do - raises_error? EventSource::ExpectedVersion::Error + raises_error? MessageStore::ExpectedVersion::Error end end end diff --git a/test/automated/write/message/write_with_reply_stream.rb b/test/automated/write/message/write_with_reply_stream.rb index 0e645c5..f953fe2 100644 --- a/test/automated/write/message/write_with_reply_stream.rb +++ b/test/automated/write/message/write_with_reply_stream.rb @@ -10,7 +10,7 @@ position = Write.(message, stream_name, reply_stream_name: reply_stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Sets the metadata reply stream name" do assert(read_event.metadata[:reply_stream_name] == reply_stream_name) diff --git a/test/interactive/consume.rb b/test/interactive/consume.rb index 4e60e08..c9b3c08 100644 --- a/test/interactive/consume.rb +++ b/test/interactive/consume.rb @@ -21,10 +21,10 @@ handler = Handler.build -EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| - logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } +MessageStore::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |message_data| + logger.debug(tags: [:test, :data, :message]) { message_data.pretty_inspect } - message = handler.(event_data) + message = handler.(message_data) logger.debug(tags: [:test, :data, :message]) { "Handled message: #{message.message_type}" } logger.debug(tags: [:test, :data, :message]) { message.pretty_inspect } diff --git a/test/interactive/consume_missing_stream_indefinately.rb b/test/interactive/consume_missing_stream_indefinately.rb index 49e1325..7f8729f 100644 --- a/test/interactive/consume_missing_stream_indefinately.rb +++ b/test/interactive/consume_missing_stream_indefinately.rb @@ -11,4 +11,4 @@ logger.info "Starting reader", tag: :test -EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10) {} +MessageStore::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10) {} diff --git a/test/interactive/measure.rb b/test/interactive/measure.rb index 8711ceb..27604a6 100644 --- a/test/interactive/measure.rb +++ b/test/interactive/measure.rb @@ -40,10 +40,10 @@ consumer_count = 0 consumer_start_time = Time.now -EventSource::Postgres::Read.(stream_name) do |event_data| - consumer_logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } +MessageStore::Postgres::Read.(stream_name) do |message_data| + consumer_logger.debug(tags: [:test, :data, :message]) { message_data.pretty_inspect } - message = handler.(event_data) + message = handler.(message_data) consumer_count += 1 consumer_logger.debug(tags: [:test, :data, :message]) { "Handled message: #{message.message_type}" } From 8e33770265cd3673ea9fda9b9e9230fc03f7f090 Mon Sep 17 00:00:00 2001 From: ntl Date: Fri, 26 May 2017 16:30:12 -0500 Subject: [PATCH 62/90] Required ruby version is increased from 2.3.3 to 2.4.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index dcbfc6c..6b9ec2e 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |s| s.require_paths = ['lib'] s.files = Dir.glob('{lib}/**/*') s.platform = Gem::Platform::RUBY - s.required_ruby_version = '>= 2.3.3' + s.required_ruby_version = '>= 2.4.0' s.add_runtime_dependency 'evt-messaging' s.add_runtime_dependency 'evt-event_source-postgres' From e965470cac5205db303cdbf887fcfc0fb72d3978 Mon Sep 17 00:00:00 2001 From: ntl Date: Fri, 26 May 2017 16:33:11 -0500 Subject: [PATCH 63/90] Gem depends on message-store-postgres --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 6b9ec2e..89a5684 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -15,8 +15,8 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.required_ruby_version = '>= 2.4.0' + s.add_runtime_dependency 'evt-message_store-postgres' s.add_runtime_dependency 'evt-messaging' - s.add_runtime_dependency 'evt-event_source-postgres' s.add_development_dependency 'test_bench' end From f332444213d8252b9f4e59047851c42a26fb1042 Mon Sep 17 00:00:00 2001 From: ntl Date: Fri, 26 May 2017 16:35:51 -0500 Subject: [PATCH 64/90] Message store postgres settings file is moved --- .../{event_source_postgres.json => message_store_postgres.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename settings/{event_source_postgres.json => message_store_postgres.json} (100%) diff --git a/settings/event_source_postgres.json b/settings/message_store_postgres.json similarity index 100% rename from settings/event_source_postgres.json rename to settings/message_store_postgres.json From a85c3e556468bc6f52d5d39d657c61b791669a07 Mon Sep 17 00:00:00 2001 From: ntl Date: Fri, 26 May 2017 16:36:59 -0500 Subject: [PATCH 65/90] Usages of event instead of message are corrected --- lib/messaging/postgres.rb | 2 +- lib/messaging/postgres/controls.rb | 2 +- test/automated/write/batch/no_id.rb | 4 ++-- test/automated/write/message/no_id.rb | 4 ++-- test/automated/write/message/reply.rb | 2 +- test/automated/write/message/write_with_reply_stream.rb | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/messaging/postgres.rb b/lib/messaging/postgres.rb index 8254e1a..fd1c870 100644 --- a/lib/messaging/postgres.rb +++ b/lib/messaging/postgres.rb @@ -1,5 +1,5 @@ +require 'message_store/postgres' require 'messaging' -require 'event_source/postgres' require 'messaging/postgres/log' require 'messaging/postgres/write' diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb index 30405f4..58f103e 100644 --- a/lib/messaging/postgres/controls.rb +++ b/lib/messaging/postgres/controls.rb @@ -1,4 +1,4 @@ -require 'event_source/postgres/controls' +require 'message_store/postgres/controls' require 'messaging/controls' require 'messaging/postgres/controls/stream_name' diff --git a/test/automated/write/batch/no_id.rb b/test/automated/write/batch/no_id.rb index 9676e71..7151195 100644 --- a/test/automated/write/batch/no_id.rb +++ b/test/automated/write/batch/no_id.rb @@ -15,11 +15,11 @@ context "Individual Events are Written" do 2.times do |i| - read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first context "Assigns an ID" do test "Event #{i + 1}" do - refute(read_event.id.nil?) + refute(read_message.id.nil?) end end end diff --git a/test/automated/write/message/no_id.rb b/test/automated/write/message/no_id.rb index 59a6897..e21f768 100644 --- a/test/automated/write/message/no_id.rb +++ b/test/automated/write/message/no_id.rb @@ -11,10 +11,10 @@ position = Write.(message, stream_name) - read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Assigns an ID" do - refute(read_event.id.nil?) + refute(read_message.id.nil?) end end end diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index 487c668..9f5b7a9 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -19,7 +19,7 @@ end test "Clears the reply stream from the metadata" do - assert(read_event.metadata[:reply_stream_name].nil?) + assert(read_message.metadata[:reply_stream_name].nil?) end end end diff --git a/test/automated/write/message/write_with_reply_stream.rb b/test/automated/write/message/write_with_reply_stream.rb index f953fe2..7b27fdc 100644 --- a/test/automated/write/message/write_with_reply_stream.rb +++ b/test/automated/write/message/write_with_reply_stream.rb @@ -10,10 +10,10 @@ position = Write.(message, stream_name, reply_stream_name: reply_stream_name) - read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Sets the metadata reply stream name" do - assert(read_event.metadata[:reply_stream_name] == reply_stream_name) + assert(read_message.metadata[:reply_stream_name] == reply_stream_name) end end end From ffb52b631e74d86de55be838cd4460b4b3a5d7a6 Mon Sep 17 00:00:00 2001 From: ntl Date: Fri, 26 May 2017 16:37:12 -0500 Subject: [PATCH 66/90] Vestigal stream_name.rb file is removed --- lib/messaging/postgres/stream_name.rb | 41 --------------------------- 1 file changed, 41 deletions(-) delete mode 100644 lib/messaging/postgres/stream_name.rb diff --git a/lib/messaging/postgres/stream_name.rb b/lib/messaging/postgres/stream_name.rb deleted file mode 100644 index f5bea43..0000000 --- a/lib/messaging/postgres/stream_name.rb +++ /dev/null @@ -1,41 +0,0 @@ -module Messaging - module Postgres - module StreamName - extend self - - def self.included(cls) - cls.class_exec do - include Messaging::Category - end - end - - def stream_name(id, category=nil, type: nil) - category ||= self.category - MessageStore::Postgres::StreamName.stream_name(category, id, type: type) - end - - def category_stream_name(category=nil) - category ||= self.category - category - end - - def command_stream_name(id, category=nil) - category ||= self.category - MessageStore::Postgres::StreamName.stream_name(category, id, type: 'command') - end - - def command_category_stream_name(category=nil) - category ||= self.category - MessageStore::Postgres::StreamName.stream_name(category, type: 'command') - end - - def self.get_category(stream_name) - MessageStore::Postgres::StreamName.get_category(stream_name) - end - - def self.get_id(stream_name) - MessageStore::Postgres::StreamName.get_id stream_name - end - end - end -end From 984c31a208a74f6ac0c089cd31a83ea587d86af2 Mon Sep 17 00:00:00 2001 From: ntl Date: Fri, 26 May 2017 16:42:10 -0500 Subject: [PATCH 67/90] Symlink scripts are corrected --- remove-lib-symlinks.sh | 2 +- symlink-lib.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/remove-lib-symlinks.sh b/remove-lib-symlinks.sh index a56bde1..247b1c1 100755 --- a/remove-lib-symlinks.sh +++ b/remove-lib-symlinks.sh @@ -1,3 +1,3 @@ source ./library-symlinks.sh -remove_lib_symlinks 'messaging' 'postgres' +remove_lib_symlinks 'postgres' 'messaging' diff --git a/symlink-lib.sh b/symlink-lib.sh index 2950b01..a620abd 100755 --- a/symlink-lib.sh +++ b/symlink-lib.sh @@ -1,3 +1,3 @@ source ./library-symlinks.sh -symlink_lib 'messaging' 'postgres' +symlink_lib 'postgres' 'messaging' From 49099f6cbbf5dc3fb954cbaa17ce7867d5a7c14f Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Mon, 29 May 2017 22:48:52 -0500 Subject: [PATCH 68/90] Messaging uses MessageStore --- Gemfile | 3 + init.rb | 9 +-- install-gems.sh | 68 +++---------------- lib/messaging/postgres.rb | 2 +- lib/messaging/postgres/controls.rb | 2 +- .../postgres/controls/stream_name.rb | 2 +- lib/messaging/postgres/stream_name.rb | 10 +-- lib/messaging/postgres/write.rb | 2 +- messaging-postgres.gemspec => library.gemspec | 4 +- load_path.rb | 18 +++++ set-local-gem-path.sh | 16 ----- ...tgres.json => message_store_postgres.json} | 4 +- test/automated/write/batch/no_id.rb | 2 +- 13 files changed, 44 insertions(+), 98 deletions(-) create mode 100644 Gemfile rename messaging-postgres.gemspec => library.gemspec (84%) create mode 100644 load_path.rb delete mode 100755 set-local-gem-path.sh rename settings/{event_source_postgres.json => message_store_postgres.json} (79%) diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..fa75df1 --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gemspec diff --git a/init.rb b/init.rb index e125715..7b64332 100755 --- a/init.rb +++ b/init.rb @@ -1,10 +1,3 @@ -lib_dir = File.expand_path('../lib', __FILE__) -$LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir) - -libraries_dir = ENV['LIBRARIES_HOME'] -unless libraries_dir.nil? - libraries_dir = File.expand_path(libraries_dir) - $LOAD_PATH.unshift libraries_dir unless $LOAD_PATH.include?(libraries_dir) -end +require_relative 'load_path' require 'messaging/postgres' diff --git a/install-gems.sh b/install-gems.sh index 2ea4b74..40cac53 100755 --- a/install-gems.sh +++ b/install-gems.sh @@ -2,37 +2,6 @@ set -e -if [ -z ${GEM_AUTHORITY_PATH+x} ]; then - echo "GEM_AUTHORITY_PATH is not set" - exit -fi - -echo -echo 'Installing local gems' -echo '= = =' - -source ./set-local-gem-path.sh - -echo -echo 'Removing gem files' -echo '- - -' -if test -n "$(find . -maxdepth 1 -name '*.gem' -print -quit)"; then - for gem in *.gem; do - echo "- $gem" - rm $gem - done -else - echo "(No gem files found)" -fi - -echo -echo 'Building gems' -echo '- - -' -for gemspec in *.gemspec; do - echo "- $gemspec" - gem build $gemspec -done - if [ -z ${POSTURE+x} ]; then echo "(POSTURE is not set. Using \"operational\" by default.)" posture="operational" @@ -40,40 +9,19 @@ else posture=$POSTURE fi -scheme="https:" -gem_repo_authority_path=$GEM_AUTHORITY_PATH -public_gem_repo_uri="$scheme//$gem_repo_authority_path" +echo +echo "Installing gems locally (posture: $posture)" +echo '= = =' -gemfury_token="" -if [ ! -z ${GEMFURY_TOKEN+x} ]; then - gemfury_token=$GEMFURY_TOKEN -fi +cmd="bundle install --standalone --path=./gems" -private_source="" -if [ ! $gemfury_token = "" ]; then - private_gem_repo_uri="$scheme//$gemfury_token@$gem_repo_authority_path" - private_source="--source $private_gem_repo_uri" +if [ operational == "$posture" ]; then + cmd="$cmd --without=development" fi -public_source="--source $public_gem_repo_uri" - -ruby_gems_source="--source https://rubygems.org" +echo $cmd +($cmd) -echo -echo "Installing gems locally (posture: $posture)" echo '- - -' -for gem in *.gem; do - echo "($gem)" - cmd="gem install $gem --clear-sources $private_source $public_source $ruby_gems_source --install-dir ./gems" - - if [ operational != "$posture" ]; then - cmd="$cmd --development" - fi - - echo $cmd - ($cmd) || exit 1 -done - -echo '= = =' echo '(done)' echo diff --git a/lib/messaging/postgres.rb b/lib/messaging/postgres.rb index 4330617..e868ce0 100644 --- a/lib/messaging/postgres.rb +++ b/lib/messaging/postgres.rb @@ -1,5 +1,5 @@ require 'messaging' -require 'event_source/postgres' +require 'message_store/postgres' require 'messaging/postgres/log' require 'messaging/postgres/stream_name' diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb index 30405f4..58f103e 100644 --- a/lib/messaging/postgres/controls.rb +++ b/lib/messaging/postgres/controls.rb @@ -1,4 +1,4 @@ -require 'event_source/postgres/controls' +require 'message_store/postgres/controls' require 'messaging/controls' require 'messaging/postgres/controls/stream_name' diff --git a/lib/messaging/postgres/controls/stream_name.rb b/lib/messaging/postgres/controls/stream_name.rb index ea92cf2..22981d5 100644 --- a/lib/messaging/postgres/controls/stream_name.rb +++ b/lib/messaging/postgres/controls/stream_name.rb @@ -1,7 +1,7 @@ module Messaging module Postgres module Controls - StreamName = EventSource::Postgres::Controls::StreamName + StreamName = MessageStore::Postgres::Controls::StreamName module StreamName module Named diff --git a/lib/messaging/postgres/stream_name.rb b/lib/messaging/postgres/stream_name.rb index a3d018c..f5bea43 100644 --- a/lib/messaging/postgres/stream_name.rb +++ b/lib/messaging/postgres/stream_name.rb @@ -11,7 +11,7 @@ def self.included(cls) def stream_name(id, category=nil, type: nil) category ||= self.category - EventSource::Postgres::StreamName.stream_name(category, id, type: type) + MessageStore::Postgres::StreamName.stream_name(category, id, type: type) end def category_stream_name(category=nil) @@ -21,20 +21,20 @@ def category_stream_name(category=nil) def command_stream_name(id, category=nil) category ||= self.category - EventSource::Postgres::StreamName.stream_name(category, id, type: 'command') + MessageStore::Postgres::StreamName.stream_name(category, id, type: 'command') end def command_category_stream_name(category=nil) category ||= self.category - EventSource::Postgres::StreamName.stream_name(category, type: 'command') + MessageStore::Postgres::StreamName.stream_name(category, type: 'command') end def self.get_category(stream_name) - EventSource::Postgres::StreamName.get_category(stream_name) + MessageStore::Postgres::StreamName.get_category(stream_name) end def self.get_id(stream_name) - EventSource::Postgres::StreamName.get_id stream_name + MessageStore::Postgres::StreamName.get_id stream_name end end end diff --git a/lib/messaging/postgres/write.rb b/lib/messaging/postgres/write.rb index 3729ae1..79215f2 100644 --- a/lib/messaging/postgres/write.rb +++ b/lib/messaging/postgres/write.rb @@ -4,7 +4,7 @@ class Write include Messaging::Write def configure(session: nil) - EventSource::Postgres::Write.configure(self, attr_name: :event_writer, session: nil) + MessageStore::Postgres::Write.configure(self, attr_name: :event_writer, session: nil) end end end diff --git a/messaging-postgres.gemspec b/library.gemspec similarity index 84% rename from messaging-postgres.gemspec rename to library.gemspec index dcbfc6c..e31f065 100644 --- a/messaging-postgres.gemspec +++ b/library.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' s.version = '0.6.0.0' - s.summary = 'Postgres messaging for Eventide' + s.summary = 'Eventide messaging for Eventide' s.description = ' ' s.authors = ['The Eventide Project'] @@ -16,7 +16,7 @@ Gem::Specification.new do |s| s.required_ruby_version = '>= 2.3.3' s.add_runtime_dependency 'evt-messaging' - s.add_runtime_dependency 'evt-event_source-postgres' + s.add_runtime_dependency 'evt-message_store-postgres' s.add_development_dependency 'test_bench' end diff --git a/load_path.rb b/load_path.rb new file mode 100644 index 0000000..2257423 --- /dev/null +++ b/load_path.rb @@ -0,0 +1,18 @@ +bundler_standalone_loader = 'gems/bundler/setup' + +begin + require_relative bundler_standalone_loader +rescue LoadError + puts "WARNING: Standalone bundle loader is not at #{bundler_standalone_loader}. Using Bundler to load gems." + require "bundler/setup" + Bundler.require +end + +lib_dir = File.expand_path('../lib', __FILE__) +$LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir) + +libraries_dir = ENV['LIBRARIES_HOME'] +unless libraries_dir.nil? + libraries_dir = File.expand_path(libraries_dir) + $LOAD_PATH.unshift libraries_dir unless $LOAD_PATH.include?(libraries_dir) +end diff --git a/set-local-gem-path.sh b/set-local-gem-path.sh deleted file mode 100755 index c0b633e..0000000 --- a/set-local-gem-path.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash - -unchanged_gem_path=$GEM_PATH - -if [[ ! $GEM_PATH == *"./gems"* ]]; then - export GEM_PATH=./gems:$GEM_PATH - - echo "Gem path was changed" - echo " from: $unchanged_gem_path" - echo " to: $GEM_PATH" -else - echo "Gem path was unchanged" - echo " from: $unchanged_gem_path" -fi - -echo diff --git a/settings/event_source_postgres.json b/settings/message_store_postgres.json similarity index 79% rename from settings/event_source_postgres.json rename to settings/message_store_postgres.json index 392938b..96139f8 100644 --- a/settings/event_source_postgres.json +++ b/settings/message_store_postgres.json @@ -1,9 +1,9 @@ { - "dbname": "event_source", + "dbname": "message_store", "host": "localhost", "hostaddr": "127.0.0.1", "port": 5432, - "user": "event_source", + "user": "message_store", "password": null, "connect_timeout": null, "options": null, diff --git a/test/automated/write/batch/no_id.rb b/test/automated/write/batch/no_id.rb index 6d97849..9676e71 100644 --- a/test/automated/write/batch/no_id.rb +++ b/test/automated/write/batch/no_id.rb @@ -15,7 +15,7 @@ context "Individual Events are Written" do 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first context "Assigns an ID" do test "Event #{i + 1}" do From 92263c799e24a6cb12cc3507adebc88f4c5b0885 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Mon, 29 May 2017 22:58:47 -0500 Subject: [PATCH 69/90] MessageStore, rather than EventSource --- lib/messaging/postgres/write.rb | 2 +- test/automated/write/batch/write.rb | 2 +- test/automated/write/batch/write_initial.rb | 4 ++-- test/automated/write/batch/write_with_reply_stream.rb | 2 +- test/automated/write/expected_version.rb | 2 +- test/automated/write/message/no_id.rb | 2 +- test/automated/write/message/reply.rb | 2 +- test/automated/write/message/write.rb | 2 +- test/automated/write/message/write_initial.rb | 4 ++-- test/automated/write/message/write_with_reply_stream.rb | 2 +- test/interactive/consume.rb | 2 +- test/interactive/consume_missing_stream_indefinately.rb | 2 +- test/interactive/measure.rb | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/messaging/postgres/write.rb b/lib/messaging/postgres/write.rb index 79215f2..546b93a 100644 --- a/lib/messaging/postgres/write.rb +++ b/lib/messaging/postgres/write.rb @@ -4,7 +4,7 @@ class Write include Messaging::Write def configure(session: nil) - MessageStore::Postgres::Write.configure(self, attr_name: :event_writer, session: nil) + MessageStore::Postgres::Write.configure(self, attr_name: :message_writer, session: nil) end end end diff --git a/test/automated/write/batch/write.rb b/test/automated/write/batch/write.rb index cc86f1c..69bc532 100644 --- a/test/automated/write/batch/write.rb +++ b/test/automated/write/batch/write.rb @@ -14,7 +14,7 @@ context "Individual Events are Written" do 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do assert(read_event.data[:some_attribute] == values[i]) diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index 09b753e..94d5dc6 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -13,7 +13,7 @@ context "Individual Events are Written" do 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do assert(read_event.data[:some_attribute] == values[i]) @@ -34,7 +34,7 @@ test "Is an error" do assert proc { write.initial(batch, stream_name) } do - raises_error? EventSource::ExpectedVersion::Error + raises_error? MessageStore::ExpectedVersion::Error end end end diff --git a/test/automated/write/batch/write_with_reply_stream.rb b/test/automated/write/batch/write_with_reply_stream.rb index a19070f..512e701 100644 --- a/test/automated/write/batch/write_with_reply_stream.rb +++ b/test/automated/write/batch/write_with_reply_stream.rb @@ -12,7 +12,7 @@ context "Individual Events are Written" do 2.times do |i| - read_event = EventSource::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do assert(read_event.data[:some_attribute] == values[i]) diff --git a/test/automated/write/expected_version.rb b/test/automated/write/expected_version.rb index 12cbf56..4967ab3 100644 --- a/test/automated/write/expected_version.rb +++ b/test/automated/write/expected_version.rb @@ -19,7 +19,7 @@ context "Wrong Version" do test "Fails" do assert proc { Write.(message_2, stream_name, expected_version: 11) } do - raises_error? EventSource::ExpectedVersion::Error + raises_error? MessageStore::ExpectedVersion::Error end end end diff --git a/test/automated/write/message/no_id.rb b/test/automated/write/message/no_id.rb index 3df116f..59a6897 100644 --- a/test/automated/write/message/no_id.rb +++ b/test/automated/write/message/no_id.rb @@ -11,7 +11,7 @@ position = Write.(message, stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Assigns an ID" do refute(read_event.id.nil?) diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index 8d78f14..deae0c2 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -12,7 +12,7 @@ position = write.reply(message) - read_event = EventSource::Postgres::Get.(reply_stream_name, position: position, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(reply_stream_name, position: position, batch_size: 1).first test "Writes the message to the reply stream" do assert(read_event.data == message.to_h) diff --git a/test/automated/write/message/write.rb b/test/automated/write/message/write.rb index a283930..d8ec1dd 100644 --- a/test/automated/write/message/write.rb +++ b/test/automated/write/message/write.rb @@ -8,7 +8,7 @@ position = Write.(message, stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Writes the message" do assert(read_event.data == message.to_h) diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index ec243cb..8eb72a8 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -11,7 +11,7 @@ write.initial(message, stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: 0, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: 0, batch_size: 1).first test "Writes the message" do assert(read_event.data == message.to_h) @@ -29,7 +29,7 @@ test "Is an error" do assert proc { write.initial(message, stream_name) } do - raises_error? EventSource::ExpectedVersion::Error + raises_error? MessageStore::ExpectedVersion::Error end end end diff --git a/test/automated/write/message/write_with_reply_stream.rb b/test/automated/write/message/write_with_reply_stream.rb index 0e645c5..f953fe2 100644 --- a/test/automated/write/message/write_with_reply_stream.rb +++ b/test/automated/write/message/write_with_reply_stream.rb @@ -10,7 +10,7 @@ position = Write.(message, stream_name, reply_stream_name: reply_stream_name) - read_event = EventSource::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Sets the metadata reply stream name" do assert(read_event.metadata[:reply_stream_name] == reply_stream_name) diff --git a/test/interactive/consume.rb b/test/interactive/consume.rb index 4e60e08..31d1e33 100644 --- a/test/interactive/consume.rb +++ b/test/interactive/consume.rb @@ -21,7 +21,7 @@ handler = Handler.build -EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| +MessageStore::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } message = handler.(event_data) diff --git a/test/interactive/consume_missing_stream_indefinately.rb b/test/interactive/consume_missing_stream_indefinately.rb index 49e1325..7f8729f 100644 --- a/test/interactive/consume_missing_stream_indefinately.rb +++ b/test/interactive/consume_missing_stream_indefinately.rb @@ -11,4 +11,4 @@ logger.info "Starting reader", tag: :test -EventSource::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10) {} +MessageStore::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10) {} diff --git a/test/interactive/measure.rb b/test/interactive/measure.rb index 8711ceb..b267da6 100644 --- a/test/interactive/measure.rb +++ b/test/interactive/measure.rb @@ -40,7 +40,7 @@ consumer_count = 0 consumer_start_time = Time.now -EventSource::Postgres::Read.(stream_name) do |event_data| +MessageStore::Postgres::Read.(stream_name) do |event_data| consumer_logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } message = handler.(event_data) From 94d158eb89b56721b4708ffcc9a64e434a4d7e90 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Mon, 29 May 2017 23:06:23 -0500 Subject: [PATCH 70/90] Message, rather than event --- test/automated/write/batch/no_id.rb | 4 ++-- test/automated/write/batch/write.rb | 4 ++-- test/automated/write/batch/write_initial.rb | 8 ++++---- test/automated/write/batch/write_with_reply_stream.rb | 4 ++-- test/automated/write/message/no_id.rb | 4 ++-- test/automated/write/message/reply.rb | 6 +++--- test/automated/write/message/write.rb | 4 ++-- test/automated/write/message/write_initial.rb | 8 ++++---- test/automated/write/message/write_with_reply_stream.rb | 4 ++-- test/interactive/consume.rb | 6 +++--- test/interactive/measure.rb | 6 +++--- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/test/automated/write/batch/no_id.rb b/test/automated/write/batch/no_id.rb index 9676e71..7151195 100644 --- a/test/automated/write/batch/no_id.rb +++ b/test/automated/write/batch/no_id.rb @@ -15,11 +15,11 @@ context "Individual Events are Written" do 2.times do |i| - read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first context "Assigns an ID" do test "Event #{i + 1}" do - refute(read_event.id.nil?) + refute(read_message.id.nil?) end end end diff --git a/test/automated/write/batch/write.rb b/test/automated/write/batch/write.rb index 69bc532..3001699 100644 --- a/test/automated/write/batch/write.rb +++ b/test/automated/write/batch/write.rb @@ -14,10 +14,10 @@ context "Individual Events are Written" do 2.times do |i| - read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == values[i]) + assert(read_message.data[:some_attribute] == values[i]) end end end diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index 94d5dc6..756782b 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -2,7 +2,7 @@ context "Write" do context "Batch" do - context "Writing the initial event to a stream that has not been created yet" do + context "Writing the initial message to a stream that has not been created yet" do stream_name = Controls::StreamName.example batch, values = Controls::Batch.example @@ -13,16 +13,16 @@ context "Individual Events are Written" do 2.times do |i| - read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == values[i]) + assert(read_message.data[:some_attribute] == values[i]) end end end end - context "Writing the initial event to a stream that already exists" do + context "Writing the initial message to a stream that already exists" do stream_name = Controls::StreamName.example batch = Controls::Batch::Messages.example diff --git a/test/automated/write/batch/write_with_reply_stream.rb b/test/automated/write/batch/write_with_reply_stream.rb index 512e701..2546e64 100644 --- a/test/automated/write/batch/write_with_reply_stream.rb +++ b/test/automated/write/batch/write_with_reply_stream.rb @@ -12,10 +12,10 @@ context "Individual Events are Written" do 2.times do |i| - read_event = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do - assert(read_event.data[:some_attribute] == values[i]) + assert(read_message.data[:some_attribute] == values[i]) end end end diff --git a/test/automated/write/message/no_id.rb b/test/automated/write/message/no_id.rb index 59a6897..e21f768 100644 --- a/test/automated/write/message/no_id.rb +++ b/test/automated/write/message/no_id.rb @@ -11,10 +11,10 @@ position = Write.(message, stream_name) - read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Assigns an ID" do - refute(read_event.id.nil?) + refute(read_message.id.nil?) end end end diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index deae0c2..9f5b7a9 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -12,14 +12,14 @@ position = write.reply(message) - read_event = MessageStore::Postgres::Get.(reply_stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(reply_stream_name, position: position, batch_size: 1).first test "Writes the message to the reply stream" do - assert(read_event.data == message.to_h) + assert(read_message.data == message.to_h) end test "Clears the reply stream from the metadata" do - assert(read_event.metadata[:reply_stream_name].nil?) + assert(read_message.metadata[:reply_stream_name].nil?) end end end diff --git a/test/automated/write/message/write.rb b/test/automated/write/message/write.rb index d8ec1dd..521419a 100644 --- a/test/automated/write/message/write.rb +++ b/test/automated/write/message/write.rb @@ -8,10 +8,10 @@ position = Write.(message, stream_name) - read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Writes the message" do - assert(read_event.data == message.to_h) + assert(read_message.data == message.to_h) end end end diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index 8eb72a8..64e3ce5 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -2,7 +2,7 @@ context "Write" do context "Message" do - context "Writing the initial event to a stream that has not been created yet" do + context "Writing the initial message to a stream that has not been created yet" do stream_name = Controls::StreamName.example message = Controls::Message.example @@ -11,14 +11,14 @@ write.initial(message, stream_name) - read_event = MessageStore::Postgres::Get.(stream_name, position: 0, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: 0, batch_size: 1).first test "Writes the message" do - assert(read_event.data == message.to_h) + assert(read_message.data == message.to_h) end end - context "Writing the initial event to a stream that already exists" do + context "Writing the initial message to a stream that already exists" do stream_name = Controls::StreamName.example message = Controls::Message.example diff --git a/test/automated/write/message/write_with_reply_stream.rb b/test/automated/write/message/write_with_reply_stream.rb index f953fe2..7b27fdc 100644 --- a/test/automated/write/message/write_with_reply_stream.rb +++ b/test/automated/write/message/write_with_reply_stream.rb @@ -10,10 +10,10 @@ position = Write.(message, stream_name, reply_stream_name: reply_stream_name) - read_event = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first test "Sets the metadata reply stream name" do - assert(read_event.metadata[:reply_stream_name] == reply_stream_name) + assert(read_message.metadata[:reply_stream_name] == reply_stream_name) end end end diff --git a/test/interactive/consume.rb b/test/interactive/consume.rb index 31d1e33..c9b3c08 100644 --- a/test/interactive/consume.rb +++ b/test/interactive/consume.rb @@ -21,10 +21,10 @@ handler = Handler.build -MessageStore::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |event_data| - logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } +MessageStore::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |message_data| + logger.debug(tags: [:test, :data, :message]) { message_data.pretty_inspect } - message = handler.(event_data) + message = handler.(message_data) logger.debug(tags: [:test, :data, :message]) { "Handled message: #{message.message_type}" } logger.debug(tags: [:test, :data, :message]) { message.pretty_inspect } diff --git a/test/interactive/measure.rb b/test/interactive/measure.rb index b267da6..27604a6 100644 --- a/test/interactive/measure.rb +++ b/test/interactive/measure.rb @@ -40,10 +40,10 @@ consumer_count = 0 consumer_start_time = Time.now -MessageStore::Postgres::Read.(stream_name) do |event_data| - consumer_logger.debug(tags: [:test, :data, :message]) { event_data.pretty_inspect } +MessageStore::Postgres::Read.(stream_name) do |message_data| + consumer_logger.debug(tags: [:test, :data, :message]) { message_data.pretty_inspect } - message = handler.(event_data) + message = handler.(message_data) consumer_count += 1 consumer_logger.debug(tags: [:test, :data, :message]) { "Handled message: #{message.message_type}" } From 95daa1351220812b3e6f6490b28e43c1e05b64fd Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Tue, 30 May 2017 01:33:36 -0500 Subject: [PATCH 71/90] Package description is corrected --- library.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.gemspec b/library.gemspec index 0471c7b..1a2562a 100644 --- a/library.gemspec +++ b/library.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' s.version = '0.6.0.0' - s.summary = 'Eventide messaging for Eventide' + s.summary = 'Eventide messaging for Postgres' s.description = ' ' s.authors = ['The Eventide Project'] From e6cf2b019661009348b51b7d9480b89207d71417 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Tue, 30 May 2017 01:34:10 -0500 Subject: [PATCH 72/90] Package version increased from 0.6.0.0 to 0.7.0.0 --- library.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.gemspec b/library.gemspec index 1a2562a..6b97c8d 100644 --- a/library.gemspec +++ b/library.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.6.0.0' + s.version = '0.7.0.0' s.summary = 'Eventide messaging for Postgres' s.description = ' ' From f125a5f9eb809452ee632d370f83d96c619f6a5d Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 31 May 2017 16:49:21 -0500 Subject: [PATCH 73/90] Gemspec is named for the library --- library.gemspec => messaging-postgres.gemspec | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename library.gemspec => messaging-postgres.gemspec (100%) diff --git a/library.gemspec b/messaging-postgres.gemspec similarity index 100% rename from library.gemspec rename to messaging-postgres.gemspec From fdde05ea1a54c7e5ff59bcb76888307be2366496 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 31 May 2017 16:50:07 -0500 Subject: [PATCH 74/90] Package version is increased from 0.7.0.0 to 0.7.0.1 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 6b97c8d..a256f3c 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.7.0.0' + s.version = '0.7.0.1' s.summary = 'Eventide messaging for Postgres' s.description = ' ' From 5753ac065b4fbd3027377e4c43c44ba7bb92c7ed Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Wed, 31 May 2017 21:04:04 -0500 Subject: [PATCH 75/90] Package version is increased from 0.7.0.1 to 0.7.0.2 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index a256f3c..4acbae0 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.7.0.1' + s.version = '0.7.0.2' s.summary = 'Eventide messaging for Postgres' s.description = ' ' From 724392339f0736d77cc525f060fe2e7cdb51b061 Mon Sep 17 00:00:00 2001 From: ntl Date: Sun, 30 Jul 2017 17:14:30 -0500 Subject: [PATCH 76/90] Write configure method passes session to put configure method --- lib/messaging/postgres/write.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/messaging/postgres/write.rb b/lib/messaging/postgres/write.rb index 546b93a..365fb15 100644 --- a/lib/messaging/postgres/write.rb +++ b/lib/messaging/postgres/write.rb @@ -4,7 +4,7 @@ class Write include Messaging::Write def configure(session: nil) - MessageStore::Postgres::Write.configure(self, attr_name: :message_writer, session: nil) + MessageStore::Postgres::Write.configure(self, attr_name: :message_writer, session: session) end end end From 1c48ff1a16e565e864b813b81a3d62f6da07e4cb Mon Sep 17 00:00:00 2001 From: ntl Date: Sun, 30 Jul 2017 17:14:48 -0500 Subject: [PATCH 77/90] Package version is increased from 0.7.0.2 to 0.7.0.3 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 4acbae0..e4008e2 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.7.0.2' + s.version = '0.7.0.3' s.summary = 'Eventide messaging for Postgres' s.description = ' ' From ff39f66d67f796ad4ea7b06ce0f60e11b7d587a7 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Mon, 13 Aug 2018 19:55:32 -0500 Subject: [PATCH 78/90] load_path.rb is updated with the latest version --- load_path.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/load_path.rb b/load_path.rb index 2257423..4f7ebf2 100644 --- a/load_path.rb +++ b/load_path.rb @@ -3,13 +3,13 @@ begin require_relative bundler_standalone_loader rescue LoadError - puts "WARNING: Standalone bundle loader is not at #{bundler_standalone_loader}. Using Bundler to load gems." + warn "WARNING: Standalone bundle loader is not at #{bundler_standalone_loader}. Using Bundler to load gems." require "bundler/setup" Bundler.require end -lib_dir = File.expand_path('../lib', __FILE__) -$LOAD_PATH.unshift lib_dir unless $LOAD_PATH.include?(lib_dir) +lib_dir = File.expand_path('lib', __dir__) +$LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir) libraries_dir = ENV['LIBRARIES_HOME'] unless libraries_dir.nil? From cd099b68852bcc5caf3b34fe6799d1e0e55d4853 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Mon, 3 Sep 2018 22:34:05 -0500 Subject: [PATCH 79/90] Readme defers to documentation site --- README.md | 125 ++---------------------------------------------------- 1 file changed, 3 insertions(+), 122 deletions(-) diff --git a/README.md b/README.md index 9d9f977..e567a8a 100755 --- a/README.md +++ b/README.md @@ -1,129 +1,10 @@ # messaging-postgres -Postgres messaging for Eventide +Eventide messaging for Postgres -## Summary +## Documentation -The `messaging-postgres` library contains primitives for writing and reading messages, as well as message handlers and mixins for message schemas and stream name utilities. - -## Example - -```ruby -account_id = ‘123’ - -deposit = Deposit.new -deposit.account_id = account_id -deposit.amount = 11 - -stream_name = StreamName.stream_name(account_id, 'account') -# => 'account-123' - -Messaging::Postgres::Write.(deposit, stream_name) - -Messaging::Postgres::Read.(stream_name) do |message_data| - AccountComponent::Handlers::Command.(message_data) -end -``` - -## Elements - -### Handlers - -A Handler is the mechanism that receives messages, and takes action based on them. - -By including `Messaging::Handle`, a class becomes a handler. By including `Messaging::Postgres::StreamName` the handler class receives some useful utilities for composing stream names from constituent parts (category and an entity's ID), and for declaring a the category name that the handler is concerned with (eg: `account`, `fundsTransfer`, `userProfile`, etc). - -```ruby -module AccountComponent - module Handlers - class Commands - include Messaging::Handle - include Messaging::Postgres::StreamName - - category :account - - handle Deposit do |deposit| - account_id = deposit.account_id - - time = clock.iso8601 - - deposited = Deposited.follow(deposit) - - stream_name = stream_name(account_id) - - write.(deposited, stream_name, expected_version: version) - end - end - end -end -``` - -### Messages - -Messages are typically simplistic data structures that carry instructions and responses to and from services. - -By including `Messaging::Message`, a message class can declare attributes that will become part of a message's payload. - -```ruby -module AccountComponent - module Messages - module Commands - class Deposit - include Messaging::Message - - attribute :deposit_id, String - attribute :account_id, String - attribute :amount, Numeric - attribute :time, String - end - end - end -end - -deposit = AccountComponent::Messages::Commands::Deposit.new - -deposit.deposit_id = Identifier::UUID::Random.get -deposit.account_id = account_id -deposit.amount = 11 -deposit.time = clock.iso8601 -``` - -### Reading Messages - -The `Messaging::Postgres::Read` class provides access to streams stored in Postgres. The reader takes a block that receives raw _message data_, and executes the block for each message data received. - -```ruby -stream_name = 'account-123' - -Messaging::Postgres::Read.(stream_name) do |message_data| - puts message_data.type -end -``` - -### Writing Messages - -The `Messaging::Postgres::Write` class writes a message to a stream. The message is converted to raw _message data_ first, then written to the data store. - -```ruby -deposit = AccountComponent::Messages::Commands::Deposit.new - -deposit.deposit_id = Identifier::UUID::Random.get -deposit.account_id = account_id -deposit.amount = 11 -deposit.time = clock.iso8601 - -stream_name = 'account-123' - -Messaging::Postgres::Write.(deposit, stream_name) -``` - -## Detailed Examples - -For a more in-depth example of the use of this library, see the example projects in the Eventide Examples org on GitHub: https://github.com/eventide-examples - -## Complete Documentation - -The complete Eventide project documentation can be found at http://eventide-project.org +See the [Eventide documentation site](http://docs.eventide-project.org) for more information, examples, and user guides. ## License From c8629d5689171cb6a22539a811698701367608c6 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Thu, 1 Nov 2018 15:16:14 -0500 Subject: [PATCH 80/90] Library and verbose tags are removed --- lib/messaging/postgres/log.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/messaging/postgres/log.rb b/lib/messaging/postgres/log.rb index dedd494..cd4e2d5 100644 --- a/lib/messaging/postgres/log.rb +++ b/lib/messaging/postgres/log.rb @@ -3,8 +3,6 @@ module Postgres class Log < ::Log def tag!(tags) tags << :messaging_postgres - tags << :library - tags << :verbose end end end From 079172b8c2862c7bb2cecab02c44d36c5a41eb3d Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Thu, 1 Nov 2018 15:17:34 -0500 Subject: [PATCH 81/90] The messaging_postgres log tag is replaced with the messaging log tag --- lib/messaging/postgres/log.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/messaging/postgres/log.rb b/lib/messaging/postgres/log.rb index cd4e2d5..5042f0a 100644 --- a/lib/messaging/postgres/log.rb +++ b/lib/messaging/postgres/log.rb @@ -2,7 +2,7 @@ module Messaging module Postgres class Log < ::Log def tag!(tags) - tags << :messaging_postgres + tags << :messaging end end end From 0b18299be506b6eff30be14858c18eae02d0ee43 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Thu, 1 Nov 2018 15:18:19 -0500 Subject: [PATCH 82/90] Package version is increased from 0.7.0.3 to 0.7.0.4 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index e4008e2..38aa9fa 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.7.0.3' + s.version = '0.7.0.4' s.summary = 'Eventide messaging for Postgres' s.description = ' ' From e98435a342aca48a7013f00ca70a9f6f0c28df04 Mon Sep 17 00:00:00 2001 From: Nathan Ladd Date: Sun, 4 Nov 2018 13:18:16 -0600 Subject: [PATCH 83/90] Package version is increased from 0.7.0.4 to 1.0.0.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 38aa9fa..0a26e4e 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '0.7.0.4' + s.version = '1.0.0.0' s.summary = 'Eventide messaging for Postgres' s.description = ' ' From f200b98cbf41daa3a1d3f188660bcc8c983cc07a Mon Sep 17 00:00:00 2001 From: Nathan Ladd Date: Mon, 14 Oct 2019 14:57:45 -0500 Subject: [PATCH 84/90] Test files are compatible with TestBench 2.0 --- test/automated.rb | 9 ++++----- test/automated/write/batch/write_initial.rb | 4 ++-- test/automated/write/expected_version.rb | 4 ++-- .../message/reply_missing_reply_stream_name_error.rb | 4 ++-- test/automated/write/message/write_initial.rb | 4 ++-- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/test/automated.rb b/test/automated.rb index de477e0..4d17efc 100644 --- a/test/automated.rb +++ b/test/automated.rb @@ -1,6 +1,5 @@ -require_relative 'test_init' +ENV['TEST_BENCH_EXCLUDE_FILE_PATTERN'] ||= '/_|sketch|(_init\.rb|_tests\.rb)\z' -TestBench::Runner.( - 'automated/**/*.rb', - exclude_pattern: %r{\/_|sketch|(_init\.rb|_tests\.rb)\z} -) or exit 1 +require_relative './test_init' + +TestBench::CLI.() diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index 756782b..7ebf785 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -33,8 +33,8 @@ Write.(message, stream_name) test "Is an error" do - assert proc { write.initial(batch, stream_name) } do - raises_error? MessageStore::ExpectedVersion::Error + assert_raises MessageStore::ExpectedVersion::Error do + write.initial(batch, stream_name) end end end diff --git a/test/automated/write/expected_version.rb b/test/automated/write/expected_version.rb index 4967ab3..a49e9d5 100644 --- a/test/automated/write/expected_version.rb +++ b/test/automated/write/expected_version.rb @@ -18,8 +18,8 @@ context "Wrong Version" do test "Fails" do - assert proc { Write.(message_2, stream_name, expected_version: 11) } do - raises_error? MessageStore::ExpectedVersion::Error + assert_raises MessageStore::ExpectedVersion::Error do + Write.(message_2, stream_name, expected_version: 11) end end end diff --git a/test/automated/write/message/reply_missing_reply_stream_name_error.rb b/test/automated/write/message/reply_missing_reply_stream_name_error.rb index 10a1de7..3c70588 100644 --- a/test/automated/write/message/reply_missing_reply_stream_name_error.rb +++ b/test/automated/write/message/reply_missing_reply_stream_name_error.rb @@ -11,8 +11,8 @@ write = Write.build test "Is an error" do - assert proc { write.reply(message) } do - raises_error? Messaging::Write::Error + assert_raises Messaging::Write::Error do + write.reply(message) end end end diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index 64e3ce5..21a19c2 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -28,8 +28,8 @@ write.(message, stream_name) test "Is an error" do - assert proc { write.initial(message, stream_name) } do - raises_error? MessageStore::ExpectedVersion::Error + assert_raises MessageStore::ExpectedVersion::Error do + write.initial(message, stream_name) end end end From 0dcf640276157590a1e41c81890355ca9372678f Mon Sep 17 00:00:00 2001 From: Nathan Ladd Date: Thu, 17 Oct 2019 16:32:20 -0500 Subject: [PATCH 85/90] Automated test runner supplies exclude file pattern directly into CLI --- test/automated.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/automated.rb b/test/automated.rb index 4d17efc..5bdd0b4 100644 --- a/test/automated.rb +++ b/test/automated.rb @@ -1,5 +1,5 @@ -ENV['TEST_BENCH_EXCLUDE_FILE_PATTERN'] ||= '/_|sketch|(_init\.rb|_tests\.rb)\z' - require_relative './test_init' -TestBench::CLI.() +TestBench::CLI.( + exclude_file_pattern: %r{/_|sketch|(_init\.rb|_tests\.rb)\z} +) From 904356796848b76635d80552a8cb37d99acf9823 Mon Sep 17 00:00:00 2001 From: Nathan Ladd Date: Thu, 17 Oct 2019 16:32:20 -0500 Subject: [PATCH 86/90] Parenthesis are added to assert_raises and refute_raises --- test/automated/write/batch/write_initial.rb | 2 +- test/automated/write/expected_version.rb | 2 +- .../write/message/reply_missing_reply_stream_name_error.rb | 2 +- test/automated/write/message/write_initial.rb | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index 7ebf785..00a747e 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -33,7 +33,7 @@ Write.(message, stream_name) test "Is an error" do - assert_raises MessageStore::ExpectedVersion::Error do + assert_raises(MessageStore::ExpectedVersion::Error) do write.initial(batch, stream_name) end end diff --git a/test/automated/write/expected_version.rb b/test/automated/write/expected_version.rb index a49e9d5..239ae77 100644 --- a/test/automated/write/expected_version.rb +++ b/test/automated/write/expected_version.rb @@ -18,7 +18,7 @@ context "Wrong Version" do test "Fails" do - assert_raises MessageStore::ExpectedVersion::Error do + assert_raises(MessageStore::ExpectedVersion::Error) do Write.(message_2, stream_name, expected_version: 11) end end diff --git a/test/automated/write/message/reply_missing_reply_stream_name_error.rb b/test/automated/write/message/reply_missing_reply_stream_name_error.rb index 3c70588..f4138ea 100644 --- a/test/automated/write/message/reply_missing_reply_stream_name_error.rb +++ b/test/automated/write/message/reply_missing_reply_stream_name_error.rb @@ -11,7 +11,7 @@ write = Write.build test "Is an error" do - assert_raises Messaging::Write::Error do + assert_raises(Messaging::Write::Error) do write.reply(message) end end diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index 21a19c2..7a9e108 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -28,7 +28,7 @@ write.(message, stream_name) test "Is an error" do - assert_raises MessageStore::ExpectedVersion::Error do + assert_raises(MessageStore::ExpectedVersion::Error) do write.initial(message, stream_name) end end From d963fa8fc2478b657767e1673712488889a05861 Mon Sep 17 00:00:00 2001 From: Scott Bellware Date: Tue, 10 Dec 2019 15:19:09 -0600 Subject: [PATCH 87/90] Package version is increased from 1.0.0.0 to 2.0.0.0 --- messaging-postgres.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec index 0a26e4e..d1fc588 100644 --- a/messaging-postgres.gemspec +++ b/messaging-postgres.gemspec @@ -1,7 +1,7 @@ # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = 'evt-messaging-postgres' - s.version = '1.0.0.0' + s.version = '2.0.0.0' s.summary = 'Eventide messaging for Postgres' s.description = ' ' From f2cfc3567e4861e5a36b1d77baf9cfd6b8e9c3c4 Mon Sep 17 00:00:00 2001 From: Nathan Ladd Date: Thu, 23 Jul 2020 14:17:26 -0500 Subject: [PATCH 88/90] All tests blocks have an assertion --- test/automated/write/expected_version.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/automated/write/expected_version.rb b/test/automated/write/expected_version.rb index 239ae77..0f6d0c2 100644 --- a/test/automated/write/expected_version.rb +++ b/test/automated/write/expected_version.rb @@ -12,7 +12,9 @@ context "Right Version" do test "Succeeds" do - Write.(message_2, stream_name, expected_version: 0) + refute_raises(MessageStore::ExpectedVersion::Error) do + Write.(message_2, stream_name, expected_version: 0) + end end end From 4bd402410c8a3299cd4523fcf46f57bbc8f59dec Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Sat, 21 Jan 2023 14:51:46 -0500 Subject: [PATCH 89/90] messaging and messaging-postgres are combined --- .gitignore | 5 +- lib/messaging.rb | 0 lib/messaging/controls.rb | 1 - lib/messaging/controls/write.rb | 15 ----- lib/messaging/postgres.rb | 5 -- lib/messaging/postgres/controls.rb | 6 -- lib/messaging/postgres/controls/batch.rb | 7 --- lib/messaging/postgres/controls/message.rb | 7 --- .../postgres/controls/stream_name.rb | 7 --- lib/messaging/postgres/log.rb | 9 --- lib/messaging/postgres/write.rb | 11 ---- lib/messaging/write.rb | 56 +++++++------------ lib/messaging/write/substitute.rb | 6 +- messaging-postgres.gemspec | 22 -------- messaging.gemspec | 5 +- test/automated/write/batch/no_id.rb | 2 +- test/automated/write/batch/reply.rb | 2 +- test/automated/write/batch/write.rb | 2 +- test/automated/write/batch/write_initial.rb | 2 +- .../write/batch/write_with_reply_stream.rb | 2 +- test/automated/write/message/no_id.rb | 2 +- test/automated/write/message/reply.rb | 2 +- test/automated/write/message/write.rb | 2 +- test/automated/write/message/write_initial.rb | 2 +- .../write/message/write_with_reply_stream.rb | 2 +- test/automated/write/telemetry/batch/write.rb | 3 +- .../write/telemetry/message/reply.rb | 3 +- .../write/telemetry/message/write.rb | 3 +- test/interactive/consume.rb | 2 +- .../consume_missing_stream_indefinately.rb | 2 +- test/interactive/measure.rb | 2 +- test/test_init.rb | 1 + 32 files changed, 46 insertions(+), 152 deletions(-) mode change 100755 => 100644 lib/messaging.rb delete mode 100644 lib/messaging/controls/write.rb delete mode 100644 lib/messaging/postgres.rb delete mode 100644 lib/messaging/postgres/controls.rb delete mode 100644 lib/messaging/postgres/controls/batch.rb delete mode 100644 lib/messaging/postgres/controls/message.rb delete mode 100644 lib/messaging/postgres/controls/stream_name.rb delete mode 100644 lib/messaging/postgres/log.rb delete mode 100644 lib/messaging/postgres/write.rb delete mode 100644 messaging-postgres.gemspec diff --git a/.gitignore b/.gitignore index 4a8240f..39cd624 100755 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,5 @@ .bundle/ Gemfile.lock +*.log *.gem gems -*sketch* -*notes.* -todo.md -fixtures diff --git a/lib/messaging.rb b/lib/messaging.rb old mode 100755 new mode 100644 diff --git a/lib/messaging/controls.rb b/lib/messaging/controls.rb index 942fb18..3ebe676 100644 --- a/lib/messaging/controls.rb +++ b/lib/messaging/controls.rb @@ -13,6 +13,5 @@ require 'messaging/controls/message_data' require 'messaging/controls/message' require 'messaging/controls/batch' -require 'messaging/controls/write' require 'messaging/controls/settings' require 'messaging/controls/handler' diff --git a/lib/messaging/controls/write.rb b/lib/messaging/controls/write.rb deleted file mode 100644 index 1ddaa99..0000000 --- a/lib/messaging/controls/write.rb +++ /dev/null @@ -1,15 +0,0 @@ -module Messaging - module Controls - module Write - def self.example - Example.build - end - - class Example - include Messaging::Write - - virtual :configure - end - end - end -end diff --git a/lib/messaging/postgres.rb b/lib/messaging/postgres.rb deleted file mode 100644 index fd1c870..0000000 --- a/lib/messaging/postgres.rb +++ /dev/null @@ -1,5 +0,0 @@ -require 'message_store/postgres' -require 'messaging' - -require 'messaging/postgres/log' -require 'messaging/postgres/write' diff --git a/lib/messaging/postgres/controls.rb b/lib/messaging/postgres/controls.rb deleted file mode 100644 index 58f103e..0000000 --- a/lib/messaging/postgres/controls.rb +++ /dev/null @@ -1,6 +0,0 @@ -require 'message_store/postgres/controls' -require 'messaging/controls' - -require 'messaging/postgres/controls/stream_name' -require 'messaging/postgres/controls/message' -require 'messaging/postgres/controls/batch' diff --git a/lib/messaging/postgres/controls/batch.rb b/lib/messaging/postgres/controls/batch.rb deleted file mode 100644 index d5b1395..0000000 --- a/lib/messaging/postgres/controls/batch.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Messaging - module Postgres - module Controls - Batch = Messaging::Controls::Batch - end - end -end diff --git a/lib/messaging/postgres/controls/message.rb b/lib/messaging/postgres/controls/message.rb deleted file mode 100644 index bf200f0..0000000 --- a/lib/messaging/postgres/controls/message.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Messaging - module Postgres - module Controls - Message = Messaging::Controls::Message - end - end -end diff --git a/lib/messaging/postgres/controls/stream_name.rb b/lib/messaging/postgres/controls/stream_name.rb deleted file mode 100644 index 98b640e..0000000 --- a/lib/messaging/postgres/controls/stream_name.rb +++ /dev/null @@ -1,7 +0,0 @@ -module Messaging - module Postgres - module Controls - StreamName = Messaging::Controls::StreamName - end - end -end diff --git a/lib/messaging/postgres/log.rb b/lib/messaging/postgres/log.rb deleted file mode 100644 index 5042f0a..0000000 --- a/lib/messaging/postgres/log.rb +++ /dev/null @@ -1,9 +0,0 @@ -module Messaging - module Postgres - class Log < ::Log - def tag!(tags) - tags << :messaging - end - end - end -end diff --git a/lib/messaging/postgres/write.rb b/lib/messaging/postgres/write.rb deleted file mode 100644 index 365fb15..0000000 --- a/lib/messaging/postgres/write.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Messaging - module Postgres - class Write - include Messaging::Write - - def configure(session: nil) - MessageStore::Postgres::Write.configure(self, attr_name: :message_writer, session: session) - end - end - end -end diff --git a/lib/messaging/write.rb b/lib/messaging/write.rb index 3f78958..5ace374 100644 --- a/lib/messaging/write.rb +++ b/lib/messaging/write.rb @@ -1,48 +1,30 @@ module Messaging - module Write - class Error < RuntimeError; end - - def self.included(cls) - cls.class_exec do - include Dependency - include Virtual - include Log::Dependency - - dependency :message_writer - dependency :telemetry, ::Telemetry + class Write + include Dependency + include Virtual + include Log::Dependency - extend Build - extend Call - extend Configure - - abstract :configure + class Error < RuntimeError; end - const_set :Substitute, Substitute - end - end + dependency :message_writer, MessageStore::Write + dependency :telemetry, ::Telemetry - module Build - def build(session: nil) - instance = new - instance.configure(session: session) - ::Telemetry.configure instance - instance - end + def self.build(session: nil) + instance = new + MessageStore::Write.configure(instance, attr_name: :message_writer, session: session) + ::Telemetry.configure(instance) + instance end - module Configure - def configure(receiver, session: nil, attr_name: nil) - attr_name ||= :write - instance = build(session: session) - receiver.public_send "#{attr_name}=", instance - end + def self.configure(receiver, session: nil, attr_name: nil) + attr_name ||= :write + instance = build(session: session) + receiver.public_send "#{attr_name}=", instance end - module Call - def call(message, stream_name, expected_version: nil, reply_stream_name: nil, session: nil) - instance = build(session: session) - instance.(message, stream_name, expected_version: expected_version, reply_stream_name: reply_stream_name) - end + def self.call(message, stream_name, expected_version: nil, reply_stream_name: nil, session: nil) + instance = build(session: session) + instance.(message, stream_name, expected_version: expected_version, reply_stream_name: reply_stream_name) end def call(message_or_batch, stream_name, expected_version: nil, reply_stream_name: nil) diff --git a/lib/messaging/write/substitute.rb b/lib/messaging/write/substitute.rb index 70e1471..116515f 100644 --- a/lib/messaging/write/substitute.rb +++ b/lib/messaging/write/substitute.rb @@ -1,5 +1,5 @@ module Messaging - module Write + class Write module Substitute def self.build Substitute::Write.build.tap do |substitute_writer| @@ -10,9 +10,7 @@ def self.build Error = Class.new(RuntimeError) - class Write - include Messaging::Write - + class Write < Messaging::Write attr_accessor :sink def raise_expected_version_error diff --git a/messaging-postgres.gemspec b/messaging-postgres.gemspec deleted file mode 100644 index d1fc588..0000000 --- a/messaging-postgres.gemspec +++ /dev/null @@ -1,22 +0,0 @@ -# -*- encoding: utf-8 -*- -Gem::Specification.new do |s| - s.name = 'evt-messaging-postgres' - s.version = '2.0.0.0' - s.summary = 'Eventide messaging for Postgres' - s.description = ' ' - - s.authors = ['The Eventide Project'] - s.email = 'opensource@eventide-project.org' - s.homepage = 'https://github.com/eventide-project/messaging-postgres' - s.licenses = ['MIT'] - - s.require_paths = ['lib'] - s.files = Dir.glob('{lib}/**/*') - s.platform = Gem::Platform::RUBY - s.required_ruby_version = '>= 2.4.0' - - s.add_runtime_dependency 'evt-message_store-postgres' - s.add_runtime_dependency 'evt-messaging' - - s.add_development_dependency 'test_bench' -end diff --git a/messaging.gemspec b/messaging.gemspec index 75abc9d..f27eefb 100644 --- a/messaging.gemspec +++ b/messaging.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = 'evt-messaging' s.version = '2.7.0.1' - s.summary = 'Common primitives for platform-specific messaging implementations for Eventide' + s.summary = 'Eventide messaging for Postgres' s.description = ' ' s.authors = ['The Eventide Project'] @@ -15,6 +15,9 @@ Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.required_ruby_version = '>= 2.4.0' + ## Remove after message store is published w/ pg dependency + s.add_runtime_dependency 'pg' + s.add_runtime_dependency 'evt-message_store' s.add_runtime_dependency 'evt-settings' diff --git a/test/automated/write/batch/no_id.rb b/test/automated/write/batch/no_id.rb index 7151195..610ca90 100644 --- a/test/automated/write/batch/no_id.rb +++ b/test/automated/write/batch/no_id.rb @@ -15,7 +15,7 @@ context "Individual Events are Written" do 2.times do |i| - read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Get.(stream_name, position: i, batch_size: 1).first context "Assigns an ID" do test "Event #{i + 1}" do diff --git a/test/automated/write/batch/reply.rb b/test/automated/write/batch/reply.rb index 513b2d3..defd266 100644 --- a/test/automated/write/batch/reply.rb +++ b/test/automated/write/batch/reply.rb @@ -10,7 +10,7 @@ batch = [message_1, message_2] - write = Controls::Write.example + write = Write.new test "Is an error" do assert_raises(Messaging::Write::Error) do diff --git a/test/automated/write/batch/write.rb b/test/automated/write/batch/write.rb index 3001699..2e30787 100644 --- a/test/automated/write/batch/write.rb +++ b/test/automated/write/batch/write.rb @@ -14,7 +14,7 @@ context "Individual Events are Written" do 2.times do |i| - read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do assert(read_message.data[:some_attribute] == values[i]) diff --git a/test/automated/write/batch/write_initial.rb b/test/automated/write/batch/write_initial.rb index 00a747e..545748e 100644 --- a/test/automated/write/batch/write_initial.rb +++ b/test/automated/write/batch/write_initial.rb @@ -13,7 +13,7 @@ context "Individual Events are Written" do 2.times do |i| - read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do assert(read_message.data[:some_attribute] == values[i]) diff --git a/test/automated/write/batch/write_with_reply_stream.rb b/test/automated/write/batch/write_with_reply_stream.rb index 2546e64..980edbd 100644 --- a/test/automated/write/batch/write_with_reply_stream.rb +++ b/test/automated/write/batch/write_with_reply_stream.rb @@ -12,7 +12,7 @@ context "Individual Events are Written" do 2.times do |i| - read_message = MessageStore::Postgres::Get.(stream_name, position: i, batch_size: 1).first + read_message = MessageStore::Get.(stream_name, position: i, batch_size: 1).first test "Event #{i + 1}" do assert(read_message.data[:some_attribute] == values[i]) diff --git a/test/automated/write/message/no_id.rb b/test/automated/write/message/no_id.rb index e21f768..687319e 100644 --- a/test/automated/write/message/no_id.rb +++ b/test/automated/write/message/no_id.rb @@ -11,7 +11,7 @@ position = Write.(message, stream_name) - read_message = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Get.(stream_name, position: position, batch_size: 1).first test "Assigns an ID" do refute(read_message.id.nil?) diff --git a/test/automated/write/message/reply.rb b/test/automated/write/message/reply.rb index 9f5b7a9..bdc5f01 100644 --- a/test/automated/write/message/reply.rb +++ b/test/automated/write/message/reply.rb @@ -12,7 +12,7 @@ position = write.reply(message) - read_message = MessageStore::Postgres::Get.(reply_stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Get.(reply_stream_name, position: position, batch_size: 1).first test "Writes the message to the reply stream" do assert(read_message.data == message.to_h) diff --git a/test/automated/write/message/write.rb b/test/automated/write/message/write.rb index 521419a..6c0814c 100644 --- a/test/automated/write/message/write.rb +++ b/test/automated/write/message/write.rb @@ -8,7 +8,7 @@ position = Write.(message, stream_name) - read_message = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Get.(stream_name, position: position, batch_size: 1).first test "Writes the message" do assert(read_message.data == message.to_h) diff --git a/test/automated/write/message/write_initial.rb b/test/automated/write/message/write_initial.rb index 7a9e108..2d731c4 100644 --- a/test/automated/write/message/write_initial.rb +++ b/test/automated/write/message/write_initial.rb @@ -11,7 +11,7 @@ write.initial(message, stream_name) - read_message = MessageStore::Postgres::Get.(stream_name, position: 0, batch_size: 1).first + read_message = MessageStore::Get.(stream_name, position: 0, batch_size: 1).first test "Writes the message" do assert(read_message.data == message.to_h) diff --git a/test/automated/write/message/write_with_reply_stream.rb b/test/automated/write/message/write_with_reply_stream.rb index 7b27fdc..8a01b1b 100644 --- a/test/automated/write/message/write_with_reply_stream.rb +++ b/test/automated/write/message/write_with_reply_stream.rb @@ -10,7 +10,7 @@ position = Write.(message, stream_name, reply_stream_name: reply_stream_name) - read_message = MessageStore::Postgres::Get.(stream_name, position: position, batch_size: 1).first + read_message = MessageStore::Get.(stream_name, position: position, batch_size: 1).first test "Sets the metadata reply stream name" do assert(read_message.metadata[:reply_stream_name] == reply_stream_name) diff --git a/test/automated/write/telemetry/batch/write.rb b/test/automated/write/telemetry/batch/write.rb index a27e844..d38401d 100644 --- a/test/automated/write/telemetry/batch/write.rb +++ b/test/automated/write/telemetry/batch/write.rb @@ -11,7 +11,8 @@ batch = [message_1, message_2] - writer = Controls::Write.example + writer = Write.new + writer.telemetry = Telemetry.build sink = Write.register_telemetry_sink(writer) diff --git a/test/automated/write/telemetry/message/reply.rb b/test/automated/write/telemetry/message/reply.rb index e7137c7..28503d9 100644 --- a/test/automated/write/telemetry/message/reply.rb +++ b/test/automated/write/telemetry/message/reply.rb @@ -8,7 +8,8 @@ reply_stream_name = message.metadata.reply_stream_name - writer = Controls::Write.example + writer = Write.new + writer.telemetry = Telemetry.build sink = Write.register_telemetry_sink(writer) diff --git a/test/automated/write/telemetry/message/write.rb b/test/automated/write/telemetry/message/write.rb index d69b596..47cd28a 100644 --- a/test/automated/write/telemetry/message/write.rb +++ b/test/automated/write/telemetry/message/write.rb @@ -7,7 +7,8 @@ message = Controls::Message.example stream_name = Controls::StreamName.example(category: 'testTelemetryWrite') - writer = Controls::Write.example + writer = Write.new + writer.telemetry = Telemetry.build sink = Write.register_telemetry_sink(writer) diff --git a/test/interactive/consume.rb b/test/interactive/consume.rb index c9b3c08..03f1818 100644 --- a/test/interactive/consume.rb +++ b/test/interactive/consume.rb @@ -21,7 +21,7 @@ handler = Handler.build -MessageStore::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |message_data| +MessageStore::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10, cycle_timeout_milliseconds: 2000) do |message_data| logger.debug(tags: [:test, :data, :message]) { message_data.pretty_inspect } message = handler.(message_data) diff --git a/test/interactive/consume_missing_stream_indefinately.rb b/test/interactive/consume_missing_stream_indefinately.rb index 7f8729f..feab9ca 100644 --- a/test/interactive/consume_missing_stream_indefinately.rb +++ b/test/interactive/consume_missing_stream_indefinately.rb @@ -11,4 +11,4 @@ logger.info "Starting reader", tag: :test -MessageStore::Postgres::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10) {} +MessageStore::Read.(stream_name, batch_size: 1, cycle_maximum_milliseconds: 10) {} diff --git a/test/interactive/measure.rb b/test/interactive/measure.rb index 27604a6..5da7cd3 100644 --- a/test/interactive/measure.rb +++ b/test/interactive/measure.rb @@ -40,7 +40,7 @@ consumer_count = 0 consumer_start_time = Time.now -MessageStore::Postgres::Read.(stream_name) do |message_data| +MessageStore::Read.(stream_name) do |message_data| consumer_logger.debug(tags: [:test, :data, :message]) { message_data.pretty_inspect } message = handler.(message_data) diff --git a/test/test_init.rb b/test/test_init.rb index 7ad6716..c23c23e 100755 --- a/test/test_init.rb +++ b/test/test_init.rb @@ -10,6 +10,7 @@ require 'test_bench'; TestBench.activate require 'securerandom' +require 'pp' require 'messaging/controls' include Messaging From 36056bb822dd1035445f785843b65419aa82b28b Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Sat, 21 Jan 2023 15:05:55 -0500 Subject: [PATCH 90/90] Gitignore is updated --- .gitignore | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.gitignore b/.gitignore index 39cd624..9c38e31 100755 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,8 @@ Gemfile.lock *.log *.gem gems +*sketch* +*notes.* +todo.md +fixtures +/test/interactive/stream_name.tmp