-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
17 changed files
with
387 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
require "avro_turf/messaging" | ||
|
||
module Streamy | ||
class AvroEvent < Event | ||
def payload | ||
avro.encode(payload_attributes.deep_stringify_keys, schema_name: type) | ||
end | ||
|
||
private | ||
|
||
def avro | ||
AvroTurf::Messaging.new( | ||
registry_url: Streamy.configuration.avro_schema_registry_url, | ||
schemas_path: Streamy.configuration.avro_schemas_path | ||
) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Streamy | ||
class Configuration | ||
attr_accessor :avro_schema_registry_url, :avro_schemas_path | ||
|
||
def initialize | ||
@avro_schema_registry_url = nil | ||
@avro_schemas_path = nil | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Streamy | ||
class JsonEvent < Event | ||
def payload | ||
payload_attributes.to_json | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Streamy | ||
VERSION = "0.2.0".freeze | ||
VERSION = "0.3.0".freeze | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require "test_helper" | ||
require "avro_turf/test/fake_confluent_schema_registry_server" | ||
require "webmock/minitest" | ||
|
||
module Streamy | ||
class AvroEventTest < Minitest::Test | ||
def setup | ||
Streamy.configuration.avro_schema_registry_url = "http://registry.example.com" | ||
Streamy.configuration.avro_schemas_path = "test/fixtures/schemas" | ||
FakeConfluentSchemaRegistryServer.clear | ||
stub_request(:any, /^#{Streamy.configuration.avro_schema_registry_url}/).to_rack(FakeConfluentSchemaRegistryServer) | ||
end | ||
|
||
class TestEvent < AvroEvent | ||
def topic | ||
:bacon | ||
end | ||
|
||
def body | ||
{ | ||
smoked: "true", | ||
streaky: "false" | ||
} | ||
end | ||
|
||
def event_time | ||
"nowish" | ||
end | ||
end | ||
|
||
class IncorrectAttributeEvent < AvroEvent | ||
def topic | ||
:bacon | ||
end | ||
|
||
def body | ||
{ | ||
smoked: "true", | ||
streaky: 100 | ||
} | ||
end | ||
|
||
def event_time | ||
"nowish" | ||
end | ||
end | ||
|
||
class EventWithNoSchema < AvroEvent | ||
def topic; end | ||
def body; end | ||
def event_time; end | ||
end | ||
|
||
def test_publish | ||
SecureRandom.stubs(:uuid).returns("IAMUUID") | ||
|
||
TestEvent.publish | ||
|
||
assert_published_event( | ||
key: "IAMUUID", | ||
topic: :bacon, | ||
payload: "\u0000\u0000\u0000\u0000\u0000\u0014test_event\u0002\fnowish\u0002\btrue\u0002\nfalse" | ||
) | ||
end | ||
|
||
def test_helpful_error_message_on_incorrect_attribute_type | ||
assert_raises Avro::IO::AvroTypeError do | ||
IncorrectAttributeEvent.publish | ||
end | ||
end | ||
|
||
def test_helpful_error_message_on_event_with_no_schema | ||
assert_raises AvroTurf::SchemaNotFoundError do | ||
EventWithNoSchema.publish | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.