Search in sources :

Example 6 with SequencedMessage

use of com.google.cloud.pubsublite.proto.SequencedMessage in project beam by apache.

the class UuidDeduplicationTransformTest method sameUuidsAfterGcOutsideWindowHasBoth.

@Test
public void sameUuidsAfterGcOutsideWindowHasBoth() {
    SequencedMessage message1 = newMessage();
    TestStream<SequencedMessage> messageStream = TestStream.create(ProtoCoder.of(SequencedMessage.class)).advanceWatermarkTo(START).addElements(message1).advanceWatermarkTo(START.plus(UuidDeduplicationOptions.DEFAULT_DEDUPLICATE_DURATION.plus(Duration.millis(1)))).addElements(message1).advanceWatermarkToInfinity();
    PCollection<SequencedMessage> results = pipeline.apply(messageStream).apply(new UuidDeduplicationTransform(UuidDeduplicationOptions.newBuilder().build()));
    PAssert.that(results).containsInAnyOrder(message1, message1);
    pipeline.run();
}
Also used : SequencedMessage(com.google.cloud.pubsublite.proto.SequencedMessage) Test(org.junit.Test)

Example 7 with SequencedMessage

use of com.google.cloud.pubsublite.proto.SequencedMessage in project beam by apache.

the class UuidDeduplicationTransformTest method sameUuidsWithinWindowOnlyOne.

@Test
public void sameUuidsWithinWindowOnlyOne() {
    SequencedMessage message = newMessage();
    TestStream<SequencedMessage> messageStream = TestStream.create(ProtoCoder.of(SequencedMessage.class)).advanceWatermarkTo(START).addElements(message).advanceWatermarkTo(START.plus(Deduplicate.DEFAULT_DURATION.dividedBy(2))).advanceWatermarkToInfinity();
    PCollection<SequencedMessage> results = pipeline.apply(messageStream).apply(new UuidDeduplicationTransform(UuidDeduplicationOptions.newBuilder().build()));
    PAssert.that(results).containsInAnyOrder(message);
    pipeline.run();
}
Also used : SequencedMessage(com.google.cloud.pubsublite.proto.SequencedMessage) Test(org.junit.Test)

Example 8 with SequencedMessage

use of com.google.cloud.pubsublite.proto.SequencedMessage in project beam by apache.

the class SubscriptionPartitionProcessorImpl method runFor.

@Override
@SuppressWarnings("argument.type.incompatible")
public ProcessContinuation runFor(Duration duration) {
    Instant deadline = Instant.now().plus(duration);
    start();
    try (SubscriptionPartitionProcessorImpl closeThis = this) {
        while (!completionFuture.isDone() && deadline.isAfterNow()) {
            @Nullable List<SequencedMessage> messages = transfer.poll(10, TimeUnit.MILLISECONDS);
            if (messages != null) {
                handleMessages(messages);
            }
        }
    } catch (Throwable t) {
        throw ExtractStatus.toCanonical(t).underlying;
    }
    // Determine return code after shutdown.
    if (completionFuture.isDone()) {
        // Call get() to ensure there is no exception.
        try {
            completionFuture.get();
        } catch (Throwable t) {
            throw ExtractStatus.toCanonical(t).underlying;
        }
        // CompletionFuture set with null when tryClaim returned false.
        return ProcessContinuation.stop();
    }
    return ProcessContinuation.resume();
}
Also used : Instant(org.joda.time.Instant) SequencedMessage(com.google.cloud.pubsublite.proto.SequencedMessage) Nullable(javax.annotation.Nullable)

Aggregations

SequencedMessage (com.google.cloud.pubsublite.proto.SequencedMessage)8 Test (org.junit.Test)7 Instant (org.joda.time.Instant)4 PubSubMessage (com.google.cloud.pubsublite.proto.PubSubMessage)2 SubscriptionPath (com.google.cloud.pubsublite.SubscriptionPath)1 TopicPath (com.google.cloud.pubsublite.TopicPath)1 AttributeValues (com.google.cloud.pubsublite.proto.AttributeValues)1 Cursor (com.google.cloud.pubsublite.proto.Cursor)1 ByteString (com.google.protobuf.ByteString)1 Timestamps (com.google.protobuf.util.Timestamps)1 Nullable (javax.annotation.Nullable)1 PipelineResult (org.apache.beam.sdk.PipelineResult)1 ProtoCoder (org.apache.beam.sdk.extensions.protobuf.ProtoCoder)1 UuidDeduplicationOptions (org.apache.beam.sdk.io.gcp.pubsublite.UuidDeduplicationOptions)1 StreamingOptions (org.apache.beam.sdk.options.StreamingOptions)1 PAssert (org.apache.beam.sdk.testing.PAssert)1 TestPipeline (org.apache.beam.sdk.testing.TestPipeline)1 TestPipelineOptions (org.apache.beam.sdk.testing.TestPipelineOptions)1 TestStream (org.apache.beam.sdk.testing.TestStream)1 Deduplicate (org.apache.beam.sdk.transforms.Deduplicate)1