-
Notifications
You must be signed in to change notification settings - Fork 20
refactor outbound sender to allow for multiple modes of dispatch #614
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
piccione99
wants to merge
9
commits into
main
Choose a base branch
from
stream
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ae6f8c5
test
piccione99 552e980
switch internal license out
piccione99 bfdc24e
fix factory and unit tests
piccione99 a0d5570
fix test
piccione99 54c9fbb
add stream sender
piccione99 ef66d97
finish wiring for stream senders
piccione99 30883a5
fix tests
piccione99 72250f8
more tests
piccione99 47cbc87
unit tests
piccione99 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,30 @@ | ||
| // SPDX-FileCopyrightText: 2021 Comcast Cable Communications Management, LLC | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "container/ring" | ||
|
|
||
| "github.com/xmidt-org/wrp-go/v3" | ||
| ) | ||
|
|
||
| type Dispatcher interface { | ||
| QueueOverflow() | ||
| Send(urls *ring.Ring, secret, acceptType string, msg *wrp.Message) | ||
| } | ||
|
|
||
| func DispatcherFactory(webhook bool, obs *CaduceusOutboundSender) Dispatcher { | ||
|
|
||
| if webhook { | ||
| return &WebhookDispatcher{ | ||
| obs: obs, | ||
| } | ||
| } | ||
|
|
||
| // TODO | ||
| return &WebhookDispatcher{ | ||
| obs: obs, | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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,40 @@ | ||
| // SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package batch | ||
|
|
||
| import () | ||
|
|
||
| func GetBatch[T any](start int, batchSize int, items []T) ([]T, bool) { | ||
| var batch []T | ||
| more := true | ||
| if (len(items) - start) <= batchSize { | ||
| batch = items[start:] | ||
| more = false | ||
| } else { | ||
| batch = items[start : start+batchSize] | ||
| } | ||
|
|
||
| return batch, more | ||
| } | ||
|
|
||
| func GetBatches[T any](batchSize int, items []T) [][]T { | ||
| batches := [][]T{} | ||
|
|
||
| if len(items) == 0 { | ||
| return batches | ||
| } | ||
|
|
||
| notDone := true | ||
| start := 0 | ||
| for notDone { | ||
| items, more := GetBatch(start, batchSize, items) | ||
| notDone = more | ||
| start += batchSize | ||
|
|
||
| batches = append(batches, items) | ||
| } | ||
|
|
||
| return batches | ||
|
|
||
| } |
This file contains hidden or 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,8 @@ | ||
| // SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package batch | ||
|
|
||
| type BatchSubmitter[T any] interface { | ||
| SubmitBatch(events []T) error | ||
| } |
This file contains hidden or 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,115 @@ | ||
| // SPDX-FileCopyrightText: 2023 Comcast Cable Communications Management, LLC | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package batch | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestGetBatch(t *testing.T) { | ||
| batchSize := 5 | ||
|
|
||
| items := []string{} | ||
| batchOfItems, more := GetBatch(0, batchSize, items) | ||
| assert.False(t, more) | ||
| assert.Equal(t, 0, len(batchOfItems)) | ||
|
|
||
| items = []string{"a", "b", "c", "d"} | ||
| batchOfItems, more = GetBatch(0, batchSize, items) | ||
| assert.False(t, more) | ||
| assert.Equal(t, 4, len(batchOfItems)) | ||
|
|
||
| items = []string{"a", "b", "c", "d", "e"} | ||
| batchOfItems, more = GetBatch(0, batchSize, items) | ||
| assert.False(t, more) | ||
| assert.Equal(t, 5, len(batchOfItems)) | ||
|
|
||
| items = []string{"a", "b", "c", "d", "e", "f"} | ||
| batchOfItems, more = GetBatch(0, batchSize, items) | ||
| assert.True(t, more) | ||
| assert.Equal(t, 5, len(batchOfItems)) | ||
| batchOfItems, more = GetBatch(0+batchSize, batchSize, items) | ||
| assert.False(t, more) | ||
| assert.Equal(t, 1, len(batchOfItems)) | ||
| } | ||
|
|
||
| func TestGetLargeBatch(t *testing.T) { | ||
| batchSize := 5 | ||
|
|
||
| start := 0 | ||
| items := []string{"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"} | ||
| batchOfItems, more := GetBatch(start, batchSize, items) | ||
| assert.True(t, more) | ||
| assert.Equal(t, 5, len(batchOfItems)) | ||
|
|
||
| start += batchSize | ||
| batchOfItems, more = GetBatch(start, batchSize, items) | ||
| assert.True(t, more) | ||
| assert.Equal(t, 5, len(batchOfItems)) | ||
|
|
||
| start += batchSize | ||
| batchOfItems, more = GetBatch(start, batchSize, items) | ||
| assert.False(t, more) | ||
| assert.Equal(t, 1, len(batchOfItems)) | ||
| } | ||
|
|
||
| func TestGetBatches100Items(t *testing.T) { | ||
| batchSize := 25 | ||
|
|
||
| items := []string{} | ||
|
|
||
| for i := 0; i < 100; i++ { | ||
| items = append(items, fmt.Sprintf("%d", i)) | ||
| } | ||
|
|
||
| batches := GetBatches(batchSize, items) | ||
| assert.Equal(t, 4, len(batches)) | ||
| assert.Equal(t, 25, len(batches[0])) | ||
| assert.Equal(t, 25, len(batches[1])) | ||
| assert.Equal(t, 25, len(batches[2])) | ||
| assert.Equal(t, 25, len(batches[3])) | ||
| } | ||
|
|
||
| func TestGetBatchesEmptyItems(t *testing.T) { | ||
| batchSize := 25 | ||
|
|
||
| items := []string{} | ||
|
|
||
| batches := GetBatches(batchSize, items) | ||
| assert.Equal(t, 0, len(batches)) | ||
| } | ||
|
|
||
| func TestGetBatchesLessThanOne(t *testing.T) { | ||
| batchSize := 5 | ||
|
|
||
| items := []string{"a", "b", "c", "d"} | ||
|
|
||
| batches := GetBatches(batchSize, items) | ||
| assert.Equal(t, 1, len(batches)) | ||
| assert.Equal(t, 4, len(batches[0])) | ||
| } | ||
|
|
||
| func TestGetBatchesExactlyOne(t *testing.T) { | ||
| batchSize := 5 | ||
|
|
||
| items := []string{"a", "b", "c", "d", "e"} | ||
|
|
||
| batches := GetBatches(batchSize, items) | ||
| assert.Equal(t, 1, len(batches)) | ||
| assert.Equal(t, 5, len(batches[0])) | ||
| } | ||
|
|
||
| func TestGetBatchesOneOver(t *testing.T) { | ||
| batchSize := 5 | ||
|
|
||
| items := []string{"a", "b", "c", "d", "e", "f"} | ||
|
|
||
| batches := GetBatches(batchSize, items) | ||
| assert.Equal(t, 2, len(batches)) | ||
| assert.Equal(t, 5, len(batches[0])) | ||
| assert.Equal(t, 1, len(batches[1])) | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is removed