Skip to content
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

feat: Emit tombstones for deleted documents #88

Merged
merged 2 commits into from
Aug 23, 2022

Conversation

tomblench
Copy link
Contributor

Documentation

Update README and CHANGES

Testing

Tested locally by deleting document from Cloudant and observing event with ./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic kafka_test --from-beginning --property print.key=true

{"schema":{"type":"string","optional":false},"payload":"f576db6ebceafaa4d585fa45bd8a3e1e"}	{
  "_deleted": true,
  "_id": "f576db6ebceafaa4d585fa45bd8a3e1e",
  "_rev": "2-30dc7747c854572ca4d0a2f8e6497ffb"
}
{"schema":{"type":"string","optional":false},"payload":"f576db6ebceafaa4d585fa45bd8a3e1e"}	null

@tomblench tomblench force-pushed the 73-source-connector-issue-tombstones branch from fca5481 to ce13258 Compare August 17, 2022 11:17
Copy link
Member

@ricellis ricellis left a comment

Choose a reason for hiding this comment

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

Minor doc suggestions and it would be nice to have a test please.

Schema.STRING_SCHEMA, // key schema
id, // key
docSchema, // value schema
docValue); // value
records.add(sourceRecord);
if (doc.isDeleted() != null && doc.isDeleted()) {
Copy link
Member

Choose a reason for hiding this comment

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

Not specific to this line, but I think it would be worth adding a test for the tombstone to protect against regressing it.

@tomblench tomblench force-pushed the 73-source-connector-issue-tombstones branch from f090c7d to c42052e Compare August 17, 2022 15:25
TODO - tests need cleaning up

Fixes #73
@tomblench tomblench force-pushed the 73-source-connector-issue-tombstones branch from c42052e to 91b0902 Compare August 17, 2022 15:27
Copy link
Member

@ricellis ricellis left a comment

Choose a reason for hiding this comment

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

+1 couple of nits copyright headers/todo comment

expect(mockResult.getLastSeq()).andReturn("100");
expect(changesResultItem.getChanges()).andReturn(Collections.singletonList(change));
expect(changesResultItem.getDoc()).andReturn(document);
expect(changesResultItem.getId()).andReturn(id);
Copy link
Member

Choose a reason for hiding this comment

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

I was surprised to not see ChangesResultItem's isDeleted mocked out here. Of course checking the implementation again I see we are checking the field on the doc instead.
I think the implementation is fine as we have the doc anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes - the test fails if I mock isDeleted but don't set deleted on the document itself.

Assert.assertEquals(2, records.size());
Assert.assertNotNull(records.get(0).value());
Assert.assertNull(records.get(1).value());
// TODO unpack record json and assert on it
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this TODO is necessary, asserting the record value is null is sufficient to know it is a tombstone.

Arguably we could have a second test that validates that we don't get a second record when the change wasn't a deleted doc, but I expect assertions elsewhere are covering that.

@@ -0,0 +1,100 @@
package com.ibm.cloud.cloudant.kafka.connect;
Copy link
Member

Choose a reason for hiding this comment

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

Needs the copyright header

@@ -0,0 +1,10 @@
package com.ibm.cloud.cloudant.kafka.connect;
Copy link
Member

Choose a reason for hiding this comment

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

needs the copyright header

@tomblench tomblench merged commit b4716ba into main Aug 23, 2022
@tomblench tomblench deleted the 73-source-connector-issue-tombstones branch August 23, 2022 09:49
@ricellis ricellis added this to the 0.200.0 milestone Sep 20, 2022
mojito317 pushed a commit that referenced this pull request Oct 6, 2022
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.

2 participants