Skip to content

Commit e776320

Browse files
author
Ajay Kannan
committed
add test for nonretryable DatastoreException
1 parent 8928c49 commit e776320

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ public void testKeyFactory() {
640640
}
641641

642642
@Test
643-
public void testRetries() throws Exception {
643+
public void testRetryableException() throws Exception {
644644
DatastoreV1.LookupRequest requestPb =
645645
DatastoreV1.LookupRequest.newBuilder().addKey(KEY1.toPb()).build();
646646
DatastoreV1.LookupResponse responsePb = DatastoreV1.LookupResponse.newBuilder()
@@ -664,7 +664,31 @@ public void testRetries() throws Exception {
664664
}
665665

666666
@Test
667-
public void testRuntimeExceptionHandling() throws Exception {
667+
public void testNonRetryableException() throws Exception {
668+
DatastoreV1.LookupRequest requestPb =
669+
DatastoreV1.LookupRequest.newBuilder().addKey(KEY1.toPb()).build();
670+
DatastoreRpcFactory rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class);
671+
DatastoreRpc rpcMock = EasyMock.createStrictMock(DatastoreRpc.class);
672+
EasyMock.expect(rpcFactoryMock.create(EasyMock.anyObject(DatastoreOptions.class)))
673+
.andReturn(rpcMock);
674+
EasyMock.expect(rpcMock.lookup(requestPb))
675+
.andThrow(new DatastoreRpc.DatastoreRpcException(Reason.PERMISSION_DENIED))
676+
.times(1);
677+
EasyMock.replay(rpcFactoryMock, rpcMock);
678+
RetryParams retryParams = RetryParams.builder().retryMinAttempts(2).build();
679+
DatastoreOptions options = this.options.toBuilder()
680+
.retryParams(retryParams)
681+
.serviceRpcFactory(rpcFactoryMock)
682+
.build();
683+
Datastore datastore = DatastoreFactory.instance().get(options);
684+
thrown.expect(DatastoreException.class);
685+
thrown.expectMessage(Reason.PERMISSION_DENIED.description());
686+
datastore.get(KEY1);
687+
EasyMock.verify(rpcFactoryMock, rpcMock);
688+
}
689+
690+
@Test
691+
public void testRuntimeException() throws Exception {
668692
DatastoreV1.LookupRequest requestPb =
669693
DatastoreV1.LookupRequest.newBuilder().addKey(KEY1.toPb()).build();
670694
DatastoreRpcFactory rpcFactoryMock = EasyMock.createStrictMock(DatastoreRpcFactory.class);

0 commit comments

Comments
 (0)