use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class WatchdogTest method watchOnClientStreamingRPCTimeout.
@Test
public void watchOnClientStreamingRPCTimeout() {
NoopClientCallStub<WriteObjectRequest, WriteObjectResponse> clientCall = new NoopClientCallStub<>();
StreamObserver<WriteObjectRequest> timeoutStreamObserver = new StreamObserver<>() {
@Override
public void onNext(WriteObjectRequest value) {
logger.atInfo().log("Sleeping for 10 seconds");
sleepUninterruptibly(Duration.ofSeconds(10));
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
StreamObserver<WriteObjectRequest> watch = watchdog.watch(clientCall, timeoutStreamObserver, waitTime);
WriteObjectRequest value = WriteObjectRequest.newBuilder().build();
watch.onNext(value);
assertThat(clientCall.cancelled).isTrue();
assertThat(clientCall.cause).isInstanceOf(TimeoutException.class);
}
use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class WatchdogTest method watchPassThroughClientStreamingRPC.
@Test
public void watchPassThroughClientStreamingRPC() {
ClientCall<WriteObjectRequest, WriteObjectResponse> clientCall = new NoopClientCall<>();
StreamObserverStub<WriteObjectRequest> streamObserver = new StreamObserverStub<>();
StreamObserver<WriteObjectRequest> watch = watchdog.watch(clientCall, streamObserver, waitTime);
assertThat(watchdog).isNotNull();
assertThat(watchdog.getOpenStreams()).hasSize(1);
WriteObjectRequest value = WriteObjectRequest.newBuilder().build();
watch.onNext(value);
assertThat(streamObserver.getObjects()).containsExactly(value);
Throwable t = new TimeoutException("Request timeout out");
watch.onError(t);
assertThat(streamObserver.getErrors()).containsExactly(t);
watch.onCompleted();
assertThat(streamObserver.isCompleted()).isTrue();
assertThat(watchdog.getOpenStreams().isEmpty()).isTrue();
}
use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class WatchdogTest method watchMultipleStreams.
@Test
public void watchMultipleStreams() {
NoopClientCallStub<WriteObjectRequest, WriteObjectResponse> clientCall = new NoopClientCallStub<>();
StreamObserver<WriteObjectRequest> timeoutStreamObserver = new StreamObserver<>() {
@Override
public void onNext(WriteObjectRequest value) {
logger.atInfo().log("Sleeping for 10 seconds");
sleepUninterruptibly(Duration.ofSeconds(10));
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
CancellableContext requestContext = Context.current().withCancellation();
Iterator<ReadObjectResponse> responseIterator = new Iterator<>() {
@Override
public boolean hasNext() {
logger.atInfo().log("Sleeping for 10 seconds");
sleepUninterruptibly(Duration.ofSeconds(10));
return true;
}
@Override
public ReadObjectResponse next() {
return null;
}
};
Iterator<ReadObjectResponse> clientStreamingRPCWatch = watchdog.watch(requestContext, responseIterator, waitTime);
StreamObserver<WriteObjectRequest> serverStreamingRPCWatch = watchdog.watch(clientCall, timeoutStreamObserver, waitTime);
assertThat(watchdog).isNotNull();
assertThat(watchdog.getOpenStreams()).hasSize(2);
boolean actual = clientStreamingRPCWatch.hasNext();
WriteObjectRequest value = WriteObjectRequest.newBuilder().build();
serverStreamingRPCWatch.onNext(value);
assertThat(actual).isTrue();
assertThat(requestContext.isCancelled()).isTrue();
assertThat(clientCall.cancelled).isTrue();
assertThat(clientCall.cause).isInstanceOf(TimeoutException.class);
assertThat(watchdog.getOpenStreams().isEmpty()).isTrue();
}
use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class WatchdogTest method watchOnClientStreamingRPCWithoutTimeout.
@Test
public void watchOnClientStreamingRPCWithoutTimeout() {
NoopClientCallStub<WriteObjectRequest, WriteObjectResponse> clientCall = new NoopClientCallStub<>();
StreamObserver<WriteObjectRequest> timeoutStreamObserver = new StreamObserver<>() {
@Override
public void onNext(WriteObjectRequest value) {
logger.atInfo().log("Sleeping for 10 seconds");
sleepUninterruptibly(Duration.ofSeconds(10));
}
@Override
public void onError(Throwable t) {
}
@Override
public void onCompleted() {
}
};
StreamObserver<WriteObjectRequest> watch = watchdog.watch(clientCall, timeoutStreamObserver, zeroWaitTime);
WriteObjectRequest value = WriteObjectRequest.newBuilder().build();
watch.onNext(value);
assertThat(clientCall.cancelled).isFalse();
assertThat(clientCall.cause).isNull();
}
use of com.google.storage.v2.WriteObjectRequest in project hadoop-connectors by GoogleCloudDataproc.
the class GoogleCloudStorageGrpcWriteChannelTest method writeSendsMultipleInsertObjectRequestsWithChecksums.
@Test
public void writeSendsMultipleInsertObjectRequestsWithChecksums() throws Exception {
AsyncWriteChannelOptions options = AsyncWriteChannelOptions.builder().setGrpcChecksumsEnabled(true).build();
ObjectWriteConditions writeConditions = ObjectWriteConditions.NONE;
GoogleCloudStorageGrpcWriteChannel writeChannel = newWriteChannel(options, writeConditions, /* requesterPaysProject= */
null);
fakeService.setQueryWriteStatusResponses(ImmutableList.of(QueryWriteStatusResponse.newBuilder().setPersistedSize(GCS_MINIMUM_CHUNK_SIZE).build(), QueryWriteStatusResponse.newBuilder().setPersistedSize(2 * GCS_MINIMUM_CHUNK_SIZE).build()).iterator());
ByteString data = createTestData(GCS_MINIMUM_CHUNK_SIZE * 5 / 2);
writeChannel.initialize();
writeChannel.write(data.asReadOnlyByteBuffer());
writeChannel.close();
ArgumentCaptor<WriteObjectRequest> requestCaptor = ArgumentCaptor.forClass(WriteObjectRequest.class);
verify(fakeService, times(1)).startResumableWrite(eq(START_REQUEST), any());
verify(fakeService.insertRequestObserver, times(1)).onNext(requestCaptor.capture());
verify(fakeService.insertRequestObserver, atLeast(1)).onCompleted();
}
Aggregations