-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
165 additions
and
102 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,33 @@ | ||
// | ||
// Copyright (C) 2021 - 2024 Dmitry Kolesnikov | ||
// | ||
// This file may be modified and distributed under the terms | ||
// of the Apache License Version 2.0. See the LICENSE file for details. | ||
// https://github.com/fogfish/swarm | ||
// | ||
|
||
package eventddb | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/fogfish/swarm" | ||
) | ||
|
||
type Option func(*Client) | ||
|
||
var defs = []Option{WithConfig()} | ||
|
||
func WithConfig(opts ...swarm.Option) Option { | ||
return func(c *Client) { | ||
config := swarm.NewConfig() | ||
for _, opt := range opts { | ||
opt(&config) | ||
} | ||
|
||
// Mandatory overrides | ||
config.PollFrequency = 5 * time.Microsecond | ||
|
||
c.config = config | ||
} | ||
} |
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,73 @@ | ||
// | ||
// Copyright (C) 2021 - 2024 Dmitry Kolesnikov | ||
// | ||
// This file may be modified and distributed under the terms | ||
// of the Apache License Version 2.0. See the LICENSE file for details. | ||
// https://github.com/fogfish/swarm | ||
// | ||
|
||
package eventddb | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"testing" | ||
"time" | ||
|
||
"github.com/fogfish/it/v2" | ||
"github.com/fogfish/swarm" | ||
"github.com/fogfish/swarm/kernel" | ||
) | ||
|
||
func TestReader(t *testing.T) { | ||
var bag []swarm.Bag | ||
bridge := &bridge{kernel.NewBridge(100 * time.Millisecond)} | ||
|
||
t.Run("NewReader", func(t *testing.T) { | ||
q, err := NewReader( | ||
WithConfig( | ||
swarm.WithLogStdErr(), | ||
), | ||
) | ||
it.Then(t).Should(it.Nil(err)) | ||
q.Close() | ||
}) | ||
|
||
t.Run("Dequeue", func(t *testing.T) { | ||
go func() { | ||
bag, _ = bridge.Ask(context.Background()) | ||
for _, m := range bag { | ||
bridge.Ack(context.Background(), m.Digest) | ||
} | ||
}() | ||
|
||
err := bridge.run( | ||
DynamoDBEvent{ | ||
Records: []json.RawMessage{[]byte(`{"sut":"test"}`)}, | ||
}, | ||
) | ||
|
||
it.Then(t).Should( | ||
it.Nil(err), | ||
it.Equal(len(bag), 1), | ||
it.Equal(bag[0].Category, Category), | ||
it.Equiv(bag[0].Object, []byte(`{"sut":"test"}`)), | ||
) | ||
}) | ||
|
||
t.Run("Dequeue.Timeout", func(t *testing.T) { | ||
go func() { | ||
bag, _ = bridge.Ask(context.Background()) | ||
}() | ||
|
||
err := bridge.run( | ||
DynamoDBEvent{ | ||
Records: []json.RawMessage{[]byte(`{"sut":"test"}`)}, | ||
}, | ||
) | ||
|
||
it.Then(t).ShouldNot( | ||
it.Nil(err), | ||
) | ||
}) | ||
} |
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
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
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 |
---|---|---|
|
@@ -8,4 +8,4 @@ | |
|
||
package eventddb | ||
|
||
const Version = "broker/eventddb/v0.16.1" | ||
const Version = "broker/eventddb/v0.20.0" |