@Test public void testRuntimeException() { String exceptionMessage = "Artificial runtime exception"; EasyMock.expect( computeRpcMock.getDiskType( DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andThrow(new RuntimeException(exceptionMessage)); EasyMock.replay(computeRpcMock); compute = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(ComputeException.class); thrown.expectMessage(exceptionMessage); compute.getDiskType(DISK_TYPE_ID); } }
@Test public void testRetryableException() { EasyMock.expect( computeRpcMock.getDiskType( DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andThrow(new ComputeException(500, "InternalError")) .andReturn(DISK_TYPE.toPb()); EasyMock.replay(computeRpcMock); compute = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); DiskType diskType = compute.getDiskType(DISK_TYPE_ID); assertEquals(DISK_TYPE, diskType); }
@Test public void testNonRetryableException() { String exceptionMessage = "Not Implemented"; EasyMock.expect( computeRpcMock.getDiskType( DISK_TYPE_ID.getZone(), DISK_TYPE_ID.getType(), EMPTY_RPC_OPTIONS)) .andThrow(new ComputeException(501, exceptionMessage)); EasyMock.replay(computeRpcMock); compute = options .toBuilder() .setRetrySettings(ServiceOptions.getDefaultRetrySettings()) .build() .getService(); thrown.expect(ComputeException.class); thrown.expectMessage(exceptionMessage); compute.getDiskType(DISK_TYPE_ID); }
ComputeOptions otherOptions = options .toBuilder() .setProjectId("p2") .setRetrySettings(ServiceOptions.getDefaultRetrySettings())
.setRetrySettings(ServiceOptions.getNoRetrySettings()) .build(); Compute otherService = options.toBuilder().build().getService(); globalOperation = new Operation.Builder(otherService)