Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

WIP binder producer error propagation #2502

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package org.springframework.cloud.gcp.stream.binder.pubsub;

import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean;

import com.google.api.core.ApiFutureCallback;
import com.google.api.core.ApiFutures;
import com.google.api.gax.retrying.RetrySettings;
import com.google.cloud.pubsub.v1.Publisher;
import com.google.protobuf.ByteString;
import com.google.pubsub.v1.PubsubMessage;
import org.awaitility.Awaitility;
import org.awaitility.Duration;
import org.junit.Test;

import java.io.IOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

public class TempClientLibraryTest {

/* This test fails on timeout: because client library retries indefinitely, the failed publish never calls
* the onFailure callback. */
@Test
public void failedPublishCallsListener() throws IOException, InterruptedException {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test fails; the future error callback is never invoked.

Publisher publisher = Publisher.newBuilder("projects/elfel-spring/topics/exampleTopic")
Expand Down Expand Up @@ -48,6 +50,47 @@ public void onSuccess(String messageId) {
}


/* This test is identical to the one above, but with overridden retry settings.
Therefore, it works as expected, invoking the onFailure callback. */
@Test
public void failedPublishCallsListener_overriddenRetrySettingsAllowsAsyncPublishToProperlyFail() throws IOException, InterruptedException {
Publisher publisher = Publisher.newBuilder("projects/elfel-spring/topics/exampleTopic")
.setEndpoint("cecicestnespasunendpoint:443")
.setRetrySettings(
RetrySettings.newBuilder()
.setMaxAttempts(3)
.setTotalTimeout(org.threeten.bp.Duration.ofSeconds(10))
.setInitialRpcTimeout(org.threeten.bp.Duration.ofSeconds(10))
.setMaxRpcTimeout(org.threeten.bp.Duration.ofSeconds(20)) // TODO: bad message; try 9; longer not shorter
.build())
Comment on lines +60 to +65
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the minimal set of retry settings that work.

.build();

PubsubMessage message = PubsubMessage.newBuilder()
.setData(ByteString.copyFromUtf8("test message"))
.build();

AtomicBoolean errorSet = new AtomicBoolean(false);

ApiFutures.addCallback(publisher.publish(message),
new ApiFutureCallback<String>() {
@Override
public void onFailure(Throwable throwable) {
System.out.println("Sending throwable to error channel: " + throwable);
errorSet.set(true);
}

@Override
public void onSuccess(String messageId) {
System.out.println("Successfully published message " + messageId);
}
});

Awaitility.await()
.atMost(Duration.TWO_MINUTES)
.until(() -> errorSet.get());

}

@Test
public void successfulPublishCallsListener() throws IOException, InterruptedException {
Publisher publisher = Publisher.newBuilder("projects/elfel-spring/topics/exampleTopic")
Expand Down