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

Integration Tests for s3-sink related to Github-issue#1048 #2401

Conversation

deepaksahu562
Copy link
Contributor

Description

Integration tests for #1048

Issues Resolved

Resolves: Integration tests for #1048

Check List

  • New functionality includes testing.
  • New functionality has been documented.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Deepak Sahu <deepak.sahu562@gmail.com>
@deepaksahu562 deepaksahu562 requested a review from a team as a code owner March 24, 2023 16:40
Collection<Record<Event>> records = setEventQueue();
s3SinkService.processRecods(records);
s3SinkService.accumulateBufferEvents(s3SinkWorker);
assertNotNull(recordsGenerator);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this being done here? You should check the impact of the previous statement here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Modified asserting "not null" for the records instead of recordsGenerator.

Collection<Record<Event>> records = setEventQueue();
s3SinkService.processRecords(records);
s3SinkService.accumulateBufferEvents(s3SinkWorker);
verify(s3SinkService, atLeastOnce()).processRecords(records);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please validate if accumulateBufferEvents() worked correctly by checking its functionality. This verification is not that useful

Copy link
Member

@dlvenable dlvenable left a comment

Choose a reason for hiding this comment

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

I made a few comments. At a high-level, the integration test should work this way.

  1. Create the object under test. This is S3Sink itself. Use real objects only. (You can mock the input config classes, that is acceptable).
  2. Generate a bunch of Events, and wrap them in Records.
  3. Call objectUnderTest.output(events)
  4. Perform an S3 list request to get the actual object created. Hint: In step 1, You can configure the key_prefix to use a unique value in each test. Then you can list using that prefix and the work is quite easy.
  5. Verify you found the S3 object
  6. Read the S3 object
  7. Verify the actual data inside the S3 object.

That is the basic overview of any test. You may have some different variations as well. One example might be calling output without enough records to write. Or calling output twice when two calls are needed to write.


RecordsGenerator recordsGenerator = new JsonRecordsGenerator();
assertNotNull(recordsGenerator);
S3SinkWorker s3SinkWorker = new S3SinkWorker(s3Client, s3SinkConfig, recordsGenerator.getCodec(),
Copy link
Member

Choose a reason for hiding this comment

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

We should move this up to testing the S3Sink class itself.

In the S3 source, you will see that we have two sets of tests. This is in part because there are two very significant components involved in the source - S3 and SQS. This is not the case here. So testing only the sink is ideal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Resolved.

@Test
void copy_s3_object_correctly_into_s3_bucket() {

RecordsGenerator recordsGenerator = new JsonRecordsGenerator();
Copy link
Member

Choose a reason for hiding this comment

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

These two lines of code are not providing any value. You can remove them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed two unused files related to RecordsGenerator and JsonRecordsGenerator.

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerator;

class JsonRecordsGenerator implements RecordsGenerator {
Copy link
Member

Choose a reason for hiding this comment

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

You don't need this class. The S3 sink is responsible for generating the JSON - not the test.

You may want to have a JsonRecordsReader which can read an actual object from S3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed two unused files related to RecordsGenerator and JsonRecordsGenerator.

s3Client = S3Client.builder().region(Region.of(System.getProperty("tests.s3source.region"))).build();
String bucket = System.getProperty("tests.s3source.bucket");

s3SinkConfig = mock(S3SinkConfig.class);
Copy link
Member

Choose a reason for hiding this comment

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

This is an integration test and should not be using mocks. Please create real objects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created real objects except for s3SinkConfig class.

@codecov-commenter
Copy link

codecov-commenter commented Apr 5, 2023

Codecov Report

Merging #2401 (c9ca322) into main (8e0fd01) will decrease coverage by 0.14%.
The diff coverage is n/a.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@             Coverage Diff              @@
##               main    #2401      +/-   ##
============================================
- Coverage     93.39%   93.26%   -0.14%     
+ Complexity     2093     2090       -3     
============================================
  Files           247      247              
  Lines          5861     5861              
  Branches        478      478              
============================================
- Hits           5474     5466       -8     
- Misses          262      271       +9     
+ Partials        125      124       -1     

see 2 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@dlvenable dlvenable self-assigned this Apr 12, 2023
int s3ObjectCountAfterIngest = gets3ObjectCount();

Assert.assertNotSame(s3ObjectCountBeforeIngest, s3ObjectCountAfterIngest);
assertThat(s3ObjectCountAfterIngest, greaterThan(s3ObjectCountBeforeIngest));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why greaterThan? Is it not possible to know the exact count?

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.

None yet

4 participants