Skip to content

Commit

Permalink
Test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
kayousterhout committed Apr 29, 2015
1 parent d8a5d36 commit 96080bf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ public class ExternalShuffleBlockHandlerSuite {
TransportClient client = mock(TransportClient.class);

OneForOneStreamManager streamManager;
ExternalShuffleBlockResolver blockManager;
ExternalShuffleBlockResolver blockResolver;
RpcHandler handler;

@Before
public void beforeEach() {
streamManager = mock(OneForOneStreamManager.class);
blockManager = mock(ExternalShuffleBlockResolver.class);
handler = new ExternalShuffleBlockHandler(streamManager, blockManager);
blockResolver = mock(ExternalShuffleBlockResolver.class);
handler = new ExternalShuffleBlockHandler(streamManager, blockResolver);
}

@Test
Expand All @@ -62,7 +62,7 @@ public void testRegisterExecutor() {
ExecutorShuffleInfo config = new ExecutorShuffleInfo(new String[] {"/a", "/b"}, 16, "sort");
byte[] registerMessage = new RegisterExecutor("app0", "exec1", config).toByteArray();
handler.receive(client, registerMessage, callback);
verify(blockManager, times(1)).registerExecutor("app0", "exec1", config);
verify(blockResolver, times(1)).registerExecutor("app0", "exec1", config);

verify(callback, times(1)).onSuccess((byte[]) any());
verify(callback, never()).onFailure((Throwable) any());
Expand All @@ -75,12 +75,12 @@ public void testOpenShuffleBlocks() {

ManagedBuffer block0Marker = new NioManagedBuffer(ByteBuffer.wrap(new byte[3]));
ManagedBuffer block1Marker = new NioManagedBuffer(ByteBuffer.wrap(new byte[7]));
when(blockManager.getBlockData("app0", "exec1", "b0")).thenReturn(block0Marker);
when(blockManager.getBlockData("app0", "exec1", "b1")).thenReturn(block1Marker);
when(blockResolver.getBlockData("app0", "exec1", "b0")).thenReturn(block0Marker);
when(blockResolver.getBlockData("app0", "exec1", "b1")).thenReturn(block1Marker);
byte[] openBlocks = new OpenBlocks("app0", "exec1", new String[] { "b0", "b1" }).toByteArray();
handler.receive(client, openBlocks, callback);
verify(blockManager, times(1)).getBlockData("app0", "exec1", "b0");
verify(blockManager, times(1)).getBlockData("app0", "exec1", "b1");
verify(blockResolver, times(1)).getBlockData("app0", "exec1", "b0");
verify(blockResolver, times(1)).getBlockData("app0", "exec1", "b1");

ArgumentCaptor<byte[]> response = ArgumentCaptor.forClass(byte[].class);
verify(callback, times(1)).onSuccess(response.capture());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@ public class ExternalShuffleCleanupSuite {
public void noCleanupAndCleanup() throws IOException {
TestShuffleDataContext dataContext = createSomeData();

ExternalShuffleBlockResolver manager = new ExternalShuffleBlockResolver(conf, sameThreadExecutor);
manager.registerExecutor("app", "exec0", dataContext.createExecutorInfo("shuffleMgr"));
manager.applicationRemoved("app", false /* cleanup */);
ExternalShuffleBlockResolver resolver =
new ExternalShuffleBlockResolver(conf, sameThreadExecutor);
resolver.registerExecutor("app", "exec0", dataContext.createExecutorInfo("shuffleMgr"));
resolver.applicationRemoved("app", false /* cleanup */);

assertStillThere(dataContext);

manager.registerExecutor("app", "exec1", dataContext.createExecutorInfo("shuffleMgr"));
manager.applicationRemoved("app", true /* cleanup */);
resolver.registerExecutor("app", "exec1", dataContext.createExecutorInfo("shuffleMgr"));
resolver.applicationRemoved("app", true /* cleanup */);

assertCleanedUp(dataContext);
}
Expand Down Expand Up @@ -81,11 +82,12 @@ public void cleanupMultipleExecutors() throws IOException {
TestShuffleDataContext dataContext0 = createSomeData();
TestShuffleDataContext dataContext1 = createSomeData();

ExternalShuffleBlockResolver manager = new ExternalShuffleBlockResolver(conf, sameThreadExecutor);
ExternalShuffleBlockResolver resolver =
new ExternalShuffleBlockResolver(conf, sameThreadExecutor);

manager.registerExecutor("app", "exec0", dataContext0.createExecutorInfo("shuffleMgr"));
manager.registerExecutor("app", "exec1", dataContext1.createExecutorInfo("shuffleMgr"));
manager.applicationRemoved("app", true);
resolver.registerExecutor("app", "exec0", dataContext0.createExecutorInfo("shuffleMgr"));
resolver.registerExecutor("app", "exec1", dataContext1.createExecutorInfo("shuffleMgr"));
resolver.applicationRemoved("app", true);

assertCleanedUp(dataContext0);
assertCleanedUp(dataContext1);
Expand All @@ -96,25 +98,26 @@ public void cleanupOnlyRemovedApp() throws IOException {
TestShuffleDataContext dataContext0 = createSomeData();
TestShuffleDataContext dataContext1 = createSomeData();

ExternalShuffleBlockResolver manager = new ExternalShuffleBlockResolver(conf, sameThreadExecutor);
ExternalShuffleBlockResolver resolver =
new ExternalShuffleBlockResolver(conf, sameThreadExecutor);

manager.registerExecutor("app-0", "exec0", dataContext0.createExecutorInfo("shuffleMgr"));
manager.registerExecutor("app-1", "exec0", dataContext1.createExecutorInfo("shuffleMgr"));
resolver.registerExecutor("app-0", "exec0", dataContext0.createExecutorInfo("shuffleMgr"));
resolver.registerExecutor("app-1", "exec0", dataContext1.createExecutorInfo("shuffleMgr"));

manager.applicationRemoved("app-nonexistent", true);
resolver.applicationRemoved("app-nonexistent", true);
assertStillThere(dataContext0);
assertStillThere(dataContext1);

manager.applicationRemoved("app-0", true);
resolver.applicationRemoved("app-0", true);
assertCleanedUp(dataContext0);
assertStillThere(dataContext1);

manager.applicationRemoved("app-1", true);
resolver.applicationRemoved("app-1", true);
assertCleanedUp(dataContext0);
assertCleanedUp(dataContext1);

// Make sure it's not an error to cleanup multiple times
manager.applicationRemoved("app-1", true);
resolver.applicationRemoved("app-1", true);
assertCleanedUp(dataContext0);
assertCleanedUp(dataContext1);
}
Expand Down

0 comments on commit 96080bf

Please sign in to comment.