Skip to content

Commit

Permalink
made adjustments to read assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
akashorabek committed Jul 15, 2022
1 parent 134216d commit e952d9a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ public void start(Receiver<V> sparkReceiver) {
}
((HasOffset) sparkReceiver).setStartOffset(startOffset);
sparkReceiver.supervisor().startReceiver();
LOG.info("Spark receiver was started");
try {
TimeUnit.MILLISECONDS.sleep(START_POLL_TIMEOUT_MS);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,10 @@ public Long getEndOffset() {
private void receive() {
Long currentOffset = startOffset;
while (!isStopped()) {
STORED_RECORDS.add(currentOffset.toString());
store((currentOffset++).toString());
if (currentOffset <= 20) {
STORED_RECORDS.add(currentOffset.toString());
store((currentOffset++).toString());
}
try {
TimeUnit.MILLISECONDS.sleep(TIMEOUT_MS);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ public void onStop() {}
private void receive() {
Long currentOffset = 0L;
while (!isStopped()) {
STORED_RECORDS.add(currentOffset.toString());
store((currentOffset++).toString());
if (currentOffset <= 20) {
STORED_RECORDS.add(currentOffset.toString());
store((currentOffset++).toString());
}
try {
TimeUnit.MILLISECONDS.sleep(TIMEOUT_MS);
} catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

import java.util.List;
import org.apache.beam.runners.direct.DirectOptions;
Expand Down Expand Up @@ -114,15 +113,14 @@ public void testReadFromCustomReceiverWithOffset() {
.withGetOffsetFn(Long::valueOf)
.withSparkReceiverBuilder(receiverBuilder);

WithOffsetTestOutputDoFn testDoFn = new WithOffsetTestOutputDoFn();
List<String> storedRecords = CustomReceiverWithOffset.getStoredRecords();
List<String> outputRecords = WithOffsetTestOutputDoFn.getRecords();
List<String> outputRecords = TestOutputDoFn.getRecords();
outputRecords.clear();

p.apply(reader).setCoder(StringUtf8Coder.of()).apply(ParDo.of(testDoFn));
p.run().waitUntilFinish(Duration.standardSeconds(10));
p.apply(reader).setCoder(StringUtf8Coder.of()).apply(ParDo.of(new TestOutputDoFn()));
p.run().waitUntilFinish(Duration.standardSeconds(15));

List<String> expectedRecords = storedRecords.subList(0, storedRecords.size() - 2);
assertTrue(outputRecords.containsAll(expectedRecords));
assertEquals(outputRecords, storedRecords);
}

@Test
Expand All @@ -141,14 +139,13 @@ public void testReadFromCustomReceiverWithoutOffset() {
.withSparkConsumer(new CustomSparkConsumer<>())
.withSparkReceiverBuilder(receiverBuilder);

WithoutOffsetTestOutputDoFn testDoFn = new WithoutOffsetTestOutputDoFn();
List<String> storedRecords = CustomReceiverWithoutOffset.getStoredRecords();
List<String> outputRecords = WithoutOffsetTestOutputDoFn.getRecords();
List<String> outputRecords = TestOutputDoFn.getRecords();
outputRecords.clear();

p.apply(reader).setCoder(StringUtf8Coder.of()).apply(ParDo.of(testDoFn));
p.run().waitUntilFinish(Duration.standardSeconds(10));
p.apply(reader).setCoder(StringUtf8Coder.of()).apply(ParDo.of(new TestOutputDoFn()));
p.run().waitUntilFinish(Duration.standardSeconds(15));

List<String> expectedRecords = storedRecords.subList(0, storedRecords.size() - 2);
assertTrue(outputRecords.containsAll(expectedRecords));
assertEquals(storedRecords, outputRecords);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
import java.util.List;
import org.apache.beam.sdk.transforms.DoFn;

public class WithOffsetTestOutputDoFn extends DoFn<String, String> {
private static final List<String> records = new ArrayList<>();
public class TestOutputDoFn extends DoFn<String, String> {
private static final List<String> RECORDS = new ArrayList<>();

@ProcessElement
public void processElement(@Element String input, DoFn.OutputReceiver<String> output) {
records.add(input);
RECORDS.add(input);
output.output(input);
}

public static List<String> getRecords() {
return records;
return RECORDS;
}
}

This file was deleted.

0 comments on commit e952d9a

Please sign in to comment.