4141import org .junit .AfterClass ;
4242import org .junit .Before ;
4343import org .junit .BeforeClass ;
44- import org .junit .Rule ;
4544import org .junit .Test ;
46- import org .junit .rules .ExpectedException ;
4745import org .junit .runner .RunWith ;
4846import org .junit .runners .JUnit4 ;
4947
@@ -104,9 +102,6 @@ public class DatastoreTest {
104102
105103 private static LocalGcdHelper gcdHelper ;
106104
107- @ Rule
108- public ExpectedException thrown = ExpectedException .none ();
109-
110105 @ BeforeClass
111106 public static void beforeClass () throws IOException , InterruptedException {
112107 if (!LocalGcdHelper .isActive (PROJECT_ID )) {
@@ -640,7 +635,7 @@ public void testKeyFactory() {
640635 }
641636
642637 @ Test
643- public void testRetryableException () throws Exception {
638+ public void testRetires () throws Exception {
644639 DatastoreV1 .LookupRequest requestPb =
645640 DatastoreV1 .LookupRequest .newBuilder ().addKey (KEY1 .toPb ()).build ();
646641 DatastoreV1 .LookupResponse responsePb = DatastoreV1 .LookupResponse .newBuilder ()
@@ -662,51 +657,4 @@ public void testRetryableException() throws Exception {
662657 assertEquals (ENTITY1 , entity );
663658 EasyMock .verify (rpcFactoryMock , rpcMock );
664659 }
665-
666- @ Test
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 {
692- DatastoreV1 .LookupRequest requestPb =
693- DatastoreV1 .LookupRequest .newBuilder ().addKey (KEY1 .toPb ()).build ();
694- DatastoreRpcFactory rpcFactoryMock = EasyMock .createStrictMock (DatastoreRpcFactory .class );
695- DatastoreRpc rpcMock = EasyMock .createStrictMock (DatastoreRpc .class );
696- EasyMock .expect (rpcFactoryMock .create (EasyMock .anyObject (DatastoreOptions .class )))
697- .andReturn (rpcMock );
698- String exceptionMessage = "Artificial runtime exception" ;
699- EasyMock .expect (rpcMock .lookup (requestPb ))
700- .andThrow (new RuntimeException (exceptionMessage ));
701- EasyMock .replay (rpcFactoryMock , rpcMock );
702- DatastoreOptions options = this .options .toBuilder ()
703- .retryParams (RetryParams .getDefaultInstance ())
704- .serviceRpcFactory (rpcFactoryMock )
705- .build ();
706- Datastore datastore = DatastoreFactory .instance ().get (options );
707- thrown .expect (DatastoreException .class );
708- thrown .expectMessage (exceptionMessage );
709- datastore .get (KEY1 );
710- EasyMock .verify (rpcFactoryMock , rpcMock );
711- }
712660}
0 commit comments