|
@@ -432,19 +432,37 @@ public class TestDFSClientRetries {
|
|
|
// Make the call to addBlock() get called twice, as if it were retried
|
|
|
// due to an IPC issue.
|
|
|
doAnswer(new Answer<LocatedBlock>() {
|
|
|
- @Override
|
|
|
- public LocatedBlock answer(InvocationOnMock invocation) throws Throwable {
|
|
|
- LocatedBlock ret = (LocatedBlock) invocation.callRealMethod();
|
|
|
+ private int getBlockCount(LocatedBlock ret) throws IOException {
|
|
|
LocatedBlocks lb = cluster.getNameNodeRpc().getBlockLocations(src, 0, Long.MAX_VALUE);
|
|
|
- int blockCount = lb.getLocatedBlocks().size();
|
|
|
assertEquals(lb.getLastLocatedBlock().getBlock(), ret.getBlock());
|
|
|
-
|
|
|
+ return lb.getLocatedBlocks().size();
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public LocatedBlock answer(InvocationOnMock invocation) throws Throwable {
|
|
|
+ LOG.info("Called addBlock: "
|
|
|
+ + Arrays.toString(invocation.getArguments()));
|
|
|
+
|
|
|
+ // call first time
|
|
|
+ // warp NotReplicatedYetException with RemoteException as rpc does.
|
|
|
+ final LocatedBlock ret;
|
|
|
+ try {
|
|
|
+ ret = (LocatedBlock) invocation.callRealMethod();
|
|
|
+ } catch(NotReplicatedYetException e) {
|
|
|
+ throw new RemoteException(e.getClass().getName(), e.getMessage());
|
|
|
+ }
|
|
|
+ final int blockCount = getBlockCount(ret);
|
|
|
+
|
|
|
// Retrying should result in a new block at the end of the file.
|
|
|
// (abandoning the old one)
|
|
|
- LocatedBlock ret2 = (LocatedBlock) invocation.callRealMethod();
|
|
|
- lb = cluster.getNameNodeRpc().getBlockLocations(src, 0, Long.MAX_VALUE);
|
|
|
- int blockCount2 = lb.getLocatedBlocks().size();
|
|
|
- assertEquals(lb.getLastLocatedBlock().getBlock(), ret2.getBlock());
|
|
|
+ // It should not have NotReplicatedYetException.
|
|
|
+ final LocatedBlock ret2;
|
|
|
+ try {
|
|
|
+ ret2 = (LocatedBlock) invocation.callRealMethod();
|
|
|
+ } catch(NotReplicatedYetException e) {
|
|
|
+ throw new AssertionError("Unexpected exception", e);
|
|
|
+ }
|
|
|
+ final int blockCount2 = getBlockCount(ret2);
|
|
|
|
|
|
// We shouldn't have gained an extra block by the RPC.
|
|
|
assertEquals(blockCount, blockCount2);
|