Skip to content

Commit 11350be

Browse files
author
Ajay Kannan
committed
---
yaml --- r: 6161 b: refs/heads/tswast-patch-1 c: 8928c49 h: refs/heads/master i: 6159: 11e54c3
1 parent 1324045 commit 11350be

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: abb421e7fbc259a411d94f169f6d3f8c2a5d038c
60+
refs/heads/tswast-patch-1: 8928c498a3c90586990c13e5496e406c064cd35a
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/DatastoreTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@
4141
import org.junit.AfterClass;
4242
import org.junit.Before;
4343
import org.junit.BeforeClass;
44+
import org.junit.Rule;
4445
import org.junit.Test;
46+
import org.junit.rules.ExpectedException;
4547
import org.junit.runner.RunWith;
4648
import org.junit.runners.JUnit4;
4749

@@ -102,6 +104,9 @@ public class DatastoreTest {
102104

103105
private static LocalGcdHelper gcdHelper;
104106

107+
@Rule
108+
public ExpectedException thrown = ExpectedException.none();
109+
105110
@BeforeClass
106111
public static void beforeClass() throws IOException, InterruptedException {
107112
if (!LocalGcdHelper.isActive(PROJECT_ID)) {
@@ -635,7 +640,7 @@ public void testKeyFactory() {
635640
}
636641

637642
@Test
638-
public void testRetires() throws Exception {
643+
public void testRetries() throws Exception {
639644
DatastoreV1.LookupRequest requestPb =
640645
DatastoreV1.LookupRequest.newBuilder().addKey(KEY1.toPb()).build();
641646
DatastoreV1.LookupResponse responsePb = DatastoreV1.LookupResponse.newBuilder()
@@ -657,4 +662,27 @@ public void testRetires() throws Exception {
657662
assertEquals(ENTITY1, entity);
658663
EasyMock.verify(rpcFactoryMock, rpcMock);
659664
}
665+
666+
@Test
667+
public void testRuntimeExceptionHandling() 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+
String exceptionMessage = "Artificial runtime exception";
675+
EasyMock.expect(rpcMock.lookup(requestPb))
676+
.andThrow(new RuntimeException(exceptionMessage));
677+
EasyMock.replay(rpcFactoryMock, rpcMock);
678+
DatastoreOptions options = this.options.toBuilder()
679+
.retryParams(RetryParams.getDefaultInstance())
680+
.serviceRpcFactory(rpcFactoryMock)
681+
.build();
682+
Datastore datastore = DatastoreFactory.instance().get(options);
683+
thrown.expect(DatastoreException.class);
684+
thrown.expectMessage(exceptionMessage);
685+
datastore.get(KEY1);
686+
EasyMock.verify(rpcFactoryMock, rpcMock);
687+
}
660688
}

0 commit comments

Comments
 (0)