-
Notifications
You must be signed in to change notification settings - Fork 83
Configurable support for rewriting consistency levels on writes #142
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
06be2c6
override consistency level
shari0311 a20e276
remove print
shari0311 84d2edf
rebase to main
shari0311 84b23d8
wip test
shari0311 40bd23d
fix consistency level on codecs
shari0311 079ab5b
implement custom patch consistency logic
shari0311 711bddc
Support batch patch consistency
shari0311 7771a1b
remove unused code
shari0311 f44105d
rephrase cli param
shari0311 56aa9fe
Only override write consistency (#143)
mpenick 1254a33
fix compilation error
shari0311 13f8dc9
Add batch test and a fix (#144)
mpenick f4c3352
Fix leftover typos (#145)
mpenick 994e8bc
rewrite tests to use decode and encode
shari0311 b1dbc17
Merge branch 'set_consistency_level' of github.com:datastax/cql-proxy…
shari0311 712ae04
handle null values
shari0311 65b83bf
Fix test case
shari0311 511c136
dne is getting resolved in lookuphost so changing to random string in…
shari0311 b089420
Add logging for consistency override (#146)
mpenick c15bdef
Merge branch 'main' into set_consistency_level
absurdfarce 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
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,71 @@ | ||
| package parser | ||
|
|
||
| import ( | ||
| "encoding/binary" | ||
| "testing" | ||
|
|
||
| "github.com/datastax/go-cassandra-native-protocol/primitive" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestPatchQueryConsistency(t *testing.T) { | ||
| t.Run("valid QUERY body", func(t *testing.T) { | ||
| query := []byte("SELECT * FROM users;") | ||
| queryLen := uint32(len(query)) | ||
|
|
||
| body := make([]byte, 4+len(query)+2) | ||
| binary.BigEndian.PutUint32(body[0:4], queryLen) | ||
| copy(body[4:], query) | ||
| binary.BigEndian.PutUint16(body[4+len(query):], uint16(primitive.ConsistencyLevelOne)) | ||
|
|
||
| err := PatchQueryConsistency(body, primitive.ConsistencyLevelQuorum) | ||
| assert.NoError(t, err) | ||
|
|
||
| offset := 4 + len(query) | ||
| got := binary.BigEndian.Uint16(body[offset : offset+2]) | ||
| assert.Equal(t, uint16(primitive.ConsistencyLevelQuorum), got) | ||
| }) | ||
|
|
||
| t.Run("too short body", func(t *testing.T) { | ||
| err := PatchQueryConsistency([]byte{0x01, 0x02}, primitive.ConsistencyLevelQuorum) | ||
| assert.Error(t, err) | ||
| }) | ||
|
|
||
| t.Run("not enough space for consistency", func(t *testing.T) { | ||
| body := make([]byte, 4) | ||
| binary.BigEndian.PutUint32(body[0:4], 10) | ||
| err := PatchQueryConsistency(body, primitive.ConsistencyLevelQuorum) | ||
| assert.Error(t, err) | ||
| }) | ||
| } | ||
|
|
||
| func TestPatchExecuteConsistency(t *testing.T) { | ||
| t.Run("valid EXECUTE body", func(t *testing.T) { | ||
| id := []byte{0xCA, 0xFE, 0xBA, 0xBE} | ||
| idLen := len(id) | ||
|
|
||
| body := make([]byte, 2+idLen+2) | ||
| binary.BigEndian.PutUint16(body[0:2], uint16(idLen)) | ||
| copy(body[2:], id) | ||
| binary.BigEndian.PutUint16(body[2+idLen:], uint16(primitive.ConsistencyLevelLocalQuorum)) | ||
|
|
||
| err := PatchExecuteConsistency(body, primitive.ConsistencyLevelAll) | ||
| assert.NoError(t, err) | ||
|
|
||
| offset := 2 + idLen | ||
| got := binary.BigEndian.Uint16(body[offset : offset+2]) | ||
| assert.Equal(t, uint16(primitive.ConsistencyLevelAll), got) | ||
| }) | ||
|
|
||
| t.Run("too short body", func(t *testing.T) { | ||
| err := PatchExecuteConsistency([]byte{0x00}, primitive.ConsistencyLevelOne) | ||
| assert.Error(t, err) | ||
| }) | ||
|
|
||
| t.Run("not enough space for consistency", func(t *testing.T) { | ||
| body := make([]byte, 2) | ||
| binary.BigEndian.PutUint16(body[0:2], 4) | ||
| err := PatchExecuteConsistency(body, primitive.ConsistencyLevelOne) | ||
| assert.Error(t, err) | ||
| }) | ||
| } |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.