Skip to content

Commit 74b8158

Browse files
committed
Created RpcBatch interface for opacity of batch.
Added core unit test for BatchResult. Added javadoc for BatchResult generics. Changed prefix of newCallback methods. Fixed method javadoc.
1 parent e51b987 commit 74b8158

8 files changed

Lines changed: 313 additions & 129 deletions

File tree

gcloud-java-core/src/main/java/com/google/gcloud/BatchResult.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package com.google.gcloud;
1818

19+
import static com.google.common.base.Preconditions.checkState;
20+
1921
/**
20-
* This class holds a single result of a batch call.
22+
* This class holds a single result of a batch call. {@code T} is the type of the result and
23+
* {@code E} is the type of the service-dependent exception thrown when processing error occurs.
2124
*/
2225
public abstract class BatchResult<T, E extends BaseServiceException> {
2326

@@ -40,9 +43,7 @@ public boolean submitted() {
4043
* @throws E if an error occurred when processing this request
4144
*/
4245
public T get() throws E {
43-
if (!submitted()) {
44-
throw new IllegalStateException("Batch has not been submitted yet");
45-
}
46+
checkState(submitted(), "Batch has not been submitted yet");
4647
if (error != null) {
4748
throw error;
4849
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2015 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.gcloud;
18+
19+
import static org.junit.Assert.assertFalse;
20+
import static org.junit.Assert.assertSame;
21+
import static org.junit.Assert.assertTrue;
22+
import static org.junit.Assert.fail;
23+
24+
import org.junit.Before;
25+
import org.junit.Test;
26+
27+
public class BatchResultTest {
28+
29+
private BatchResult<Boolean, BaseServiceException> RESULT;
30+
31+
@Before
32+
public void setUp() {
33+
RESULT = new BatchResult<Boolean, BaseServiceException>() {};
34+
}
35+
36+
@Test
37+
public void testSuccess() {
38+
assertFalse(RESULT.submitted());
39+
try {
40+
RESULT.get();
41+
fail("This was not submitted yet.");
42+
} catch (IllegalStateException ex) {
43+
// expected
44+
}
45+
RESULT.success(true);
46+
assertTrue(RESULT.get());
47+
}
48+
49+
@Test
50+
public void testError() {
51+
assertFalse(RESULT.submitted());
52+
try {
53+
RESULT.get();
54+
fail("This was not submitted yet.");
55+
} catch (IllegalStateException ex) {
56+
// expected
57+
}
58+
BaseServiceException ex = new BaseServiceException(0, "message", "reason", false);
59+
RESULT.error(ex);
60+
try {
61+
RESULT.get();
62+
fail("This is a failed operation and should have thrown a DnsException.");
63+
} catch (BaseServiceException real) {
64+
assertSame(ex, real);
65+
}
66+
}
67+
68+
// todo(mderka) test notify when implemented
69+
70+
}

0 commit comments

Comments
 (0)