Skip to content

Windowed Table: Unit testing#252

Merged
apourchet merged 4 commits intomainfrom
apourchet-window-table-test
Feb 28, 2024
Merged

Windowed Table: Unit testing#252
apourchet merged 4 commits intomainfrom
apourchet-window-table-test

Conversation

@apourchet
Copy link
Contributor

@apourchet apourchet commented Feb 27, 2024

Fixed the BSON parsing bug that was not yet hit by the integration tests. Without the proper @BsonCreator constructor, our document retrieval and parsing from MongoDB were never getting their ID fields populated correctly.

Fixed the BSON parsing bug that was hidden by the KS state store caching
mechanism. Without the proper @BsonCreator constructor, our document
retrieval and parsing from MongoDB were never getting their ID fields
populated correctly.
Copy link
Contributor

@agavra agavra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! Thanks @apourchet

public WindowDoc() {
}

@BsonCreator
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need to do the same for KVDoc? I can't remember if you said that's going to be a separate PR or not. Also for KVDoc I noticed there's @BsonId annotation on the id field, is that necessary/needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some testing on KVDoc independently and it looks like @BsonId isn't doing what we want it to. I wanted to see what the feedback was on this Window stuff before applying the same logic to the KVDoc (since it's already in use in production).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: none of the Mongo stuff is in production yet, the KV store that we have in prod is based on Scylla. So now is the time to make any changes we want/need

var kvs = new ArrayList<KeyValue<WindowedKey, byte[]>>();
it.forEachRemaining(kvs::add);

assertThat(kvs, Matchers.hasSize(1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: since we're trying to fetch a range, can we verify that multiple values can be returned instead of just one?

I know that's unrelated to this PR, but since this is somewhat of an integration test I think it's worth covering that part as well

it.forEachRemaining(kvs::add);

assertThat(kvs, Matchers.hasSize(1));
assertThat(kvs.get(0).key.key, Matchers.equalTo(windowedKey.key));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this the thing that was failing on main?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, it's the range test that's failing on main. The reason behind the failure is that the WindowKey was being populated using the .id field, which throws NullPointer as it's never populated by the Bson decoder.

@BsonProperty(VALUE) byte[] value,
@BsonProperty(EPOCH) long epoch
) {
this.id = id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just want to make sure I understand the actual fix here -- I did notice the this.id = id was missing and added that in #251 but IIUC you're saying that even with this, we still have a bug -- due to missing Bson annotations, essentially?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this locally, which goes back to failing the new test:

public class WindowDoc {

@@ -43,11 +41,10 @@ public class WindowDoc {
   public WindowDoc() {
   }

-  @BsonCreator
   public WindowDoc(
-      @BsonProperty(ID) BasicDBObject id,
-      @BsonProperty(VALUE) byte[] value,
-      @BsonProperty(EPOCH) long epoch
+      BasicDBObject id,
+      byte[] value,
+      long epoch
   ) {
     this.id = id;
     this.value = value;

So it looks like the Bson decoder needs the actual annotations and not just the right constructor signature.

Copy link
Contributor

@ableegoldman ableegoldman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM -- still curious why this bug surfaced for session stores but not the others. I did check and our integration tests do a flush on every record, so (un?)fortunately I don't think the CommitBuffer serving all the records in the tests is the answer.

@apourchet
Copy link
Contributor Author

LGTM -- still curious why this bug surfaced for session stores but not the others. I did check and our integration tests do a flush on every record, so (un?)fortunately I don't think the CommitBuffer serving all the records in the tests is the answer.

I believe the reason we didn't catch this earlier is that none of the integration tests call out to the MongoWindowedTable range queries, which means we are never creating WindowedKey from the raw WindowDoc. More specifically, this line is never hit:
https://github.com/responsivedev/responsive-pub/blob/main/kafka-client/src/main/java/dev/responsive/kafka/internal/db/mongo/MongoWindowedTable.java#L451

      segmentIterators.add(
          Iterators.kv(fetchResults.iterator(), MongoWindowedTable::windowFromDoc)
      );

@apourchet apourchet merged commit 59e5682 into main Feb 28, 2024
@apourchet apourchet deleted the apourchet-window-table-test branch February 28, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants