-
Notifications
You must be signed in to change notification settings - Fork 874
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
JAVA-3084: Add integration test coverage for ExtraTypeCodecs #1679
Conversation
01bf391
to
e74025d
Compare
.get(field.name, codec)) | ||
.isEqualTo(value); | ||
} | ||
} |
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.
It's not essential, but opening a new codec for each codec we want to test is probably more than we need to do here. We can apply codecs at read time directly to a row and if we use prepared statements we can also supply a codec when we generate a BoundStatement from a PreparedStatement. Using that approach we can do everything through a single session:
private <T> void insertAndRead(TableField field, T value, TypeCodec<T> codec) {
CqlSession session = SESSION_RULE.session();
PreparedStatement psi =
session.prepare(
String.format("INSERT INTO extra_type_codecs_it (key, %s) VALUES (?, ?)", field.name));
// write value under new key using provided codec
UUID key = UUID.randomUUID();
session.execute(psi.boundStatementBuilder().setUuid(0, key).set(1, value, codec).build());
PreparedStatement pss =
session.prepare(
String.format("SELECT %s FROM extra_type_codecs_it WHERE key = ?", field.name));
// read value using provided codec
assertThat(
session
.execute(pss.boundStatementBuilder().setUuid(0, key).build())
.one()
.get(field.name, codec))
.isEqualTo(value);
}
The above passes for me locally against C* 4.0.0.
This is not a particularly efficient way to use prepared statements, but it's probably somewhat better than having to open and close a session for each type. As I mentioned above it's not essential (although it probably is a bit faster); there's nothing wrong with what you have now.
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.
Thanks. Updated insertAndRead
to use single session with bound statements per your suggestion. If the tests pass I'll merge this one :)
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.
I like the overall approach taken here; this is a solid implementation and a clever way to handle the various types of codecs involved. Left a comment on how to do this without having to open a session for each codec but it's not strictly required.
Nice work!
Test failures unrelated - merging |
No description provided.