use of com.google.api.client.util.Clock in project google-api-java-client by google.
the class GoogleIdTokenVerifierTest method testBuilder.
public void testBuilder() throws Exception {
GoogleIdTokenVerifier.Builder builder = new GoogleIdTokenVerifier.Builder(new GooglePublicKeysManagerTest.PublicCertsMockHttpTransport(), new JacksonFactory()).setIssuer(ISSUER).setAudience(TRUSTED_CLIENT_IDS);
assertEquals(Clock.SYSTEM, builder.getClock());
assertEquals(ISSUER, builder.getIssuer());
assertTrue(TRUSTED_CLIENT_IDS.equals(builder.getAudience()));
Clock clock = new FixedClock(4);
builder.setClock(clock);
assertEquals(clock, builder.getClock());
IdTokenVerifier verifier = builder.build();
assertEquals(clock, verifier.getClock());
assertEquals(ISSUER, verifier.getIssuer());
assertEquals(TRUSTED_CLIENT_IDS, Lists.newArrayList(verifier.getAudience()));
}
use of com.google.api.client.util.Clock in project beam by apache.
the class PubsubTestClientTest method pullOneMessage.
@Test
public void pullOneMessage() throws IOException {
final AtomicLong now = new AtomicLong();
Clock clock = now::get;
IncomingMessage expectedIncomingMessage = IncomingMessage.of(PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8(DATA)).build(), MESSAGE_TIME, REQ_TIME, ACK_ID, MESSAGE_ID);
try (PubsubTestClientFactory factory = PubsubTestClient.createFactoryForPull(clock, SUBSCRIPTION, ACK_TIMEOUT_S, Lists.newArrayList(expectedIncomingMessage))) {
try (PubsubTestClient client = (PubsubTestClient) factory.newClient(null, null, null)) {
now.set(REQ_TIME);
client.advance();
List<IncomingMessage> incomingMessages = client.pull(now.get(), SUBSCRIPTION, 1, true);
assertEquals(1, incomingMessages.size());
assertEquals(expectedIncomingMessage, incomingMessages.get(0));
// Timeout on ACK.
now.addAndGet((ACK_TIMEOUT_S + 10) * 1000);
client.advance();
incomingMessages = client.pull(now.get(), SUBSCRIPTION, 1, true);
assertEquals(1, incomingMessages.size());
assertEquals(IncomingMessage.of(expectedIncomingMessage.message(), expectedIncomingMessage.timestampMsSinceEpoch(), now.get(), expectedIncomingMessage.ackId(), expectedIncomingMessage.recordId()), incomingMessages.get(0));
now.addAndGet(10 * 1000);
client.advance();
// Extend ack
client.modifyAckDeadline(SUBSCRIPTION, ImmutableList.of(ACK_ID), 20);
// Timeout on extended ACK
now.addAndGet(30 * 1000);
client.advance();
incomingMessages = client.pull(now.get(), SUBSCRIPTION, 1, true);
assertEquals(1, incomingMessages.size());
assertEquals(IncomingMessage.of(expectedIncomingMessage.message(), expectedIncomingMessage.timestampMsSinceEpoch(), now.get(), expectedIncomingMessage.ackId(), expectedIncomingMessage.recordId()), incomingMessages.get(0));
// Extend ack
client.modifyAckDeadline(SUBSCRIPTION, ImmutableList.of(ACK_ID), 20);
// Ack
now.addAndGet(15 * 1000);
client.advance();
client.acknowledge(SUBSCRIPTION, ImmutableList.of(ACK_ID));
}
}
}
use of com.google.api.client.util.Clock in project beam by apache.
the class PubsubTestClientTest method testPullThenPublish.
@Test
public void testPullThenPublish() throws IOException {
AtomicLong now = new AtomicLong();
Clock clock = now::get;
PubsubMessage message = PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8(DATA)).build();
IncomingMessage expectedIncomingMessage = IncomingMessage.of(message, MESSAGE_TIME, REQ_TIME, ACK_ID, MESSAGE_ID);
OutgoingMessage expectedOutgoingMessage = OutgoingMessage.of(message, MESSAGE_TIME, MESSAGE_ID);
try (PubsubTestClientFactory factory = PubsubTestClient.createFactoryForPullAndPublish(SUBSCRIPTION, TOPIC, clock, ACK_TIMEOUT_S, ImmutableList.of(expectedIncomingMessage), ImmutableList.of(expectedOutgoingMessage), ImmutableList.of())) {
try (PubsubTestClient client = (PubsubTestClient) factory.newClient(null, null, null)) {
// Pull
now.set(REQ_TIME);
client.advance();
List<IncomingMessage> actualIncomingMessages = client.pull(now.get(), SUBSCRIPTION, 1, true);
now.addAndGet(ACK_TIMEOUT_S - 10);
client.advance();
client.acknowledge(SUBSCRIPTION, ImmutableList.of(ACK_ID));
assertEquals(1, actualIncomingMessages.size());
assertEquals(expectedIncomingMessage, actualIncomingMessages.get(0));
// Publish
IncomingMessage incomingMessage = actualIncomingMessages.get(0);
OutgoingMessage actualOutgoingMessage = OutgoingMessage.of(incomingMessage.message(), incomingMessage.timestampMsSinceEpoch(), incomingMessage.recordId());
client.publish(TOPIC, ImmutableList.of(actualOutgoingMessage));
}
}
}
Aggregations