Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Better error messages when tests fail.
  • Loading branch information
Marcelo Vanzin committed Aug 20, 2015
commit 4d19ed51616ff6019bcb3b762d82823ced49b675
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

import com.google.common.collect.Lists;
import org.junit.After;
Expand Down Expand Up @@ -188,7 +188,7 @@ public void testAppIsolation() throws Exception {
client1 = clientFactory.createClient(TestUtils.getLocalHost(),
blockServer.getPort());

final AtomicBoolean gotSecurityException = new AtomicBoolean(false);
final AtomicReference<Throwable> exception = new AtomicReference<>();

BlockFetchingListener listener = new BlockFetchingListener() {
@Override
Expand All @@ -197,9 +197,8 @@ public synchronized void onBlockFetchSuccess(String blockId, ManagedBuffer data)
}

@Override
public synchronized void onBlockFetchFailure(String blockId, Throwable exception) {
gotSecurityException.set(
exception.getMessage().contains(SecurityException.class.getName()));
public synchronized void onBlockFetchFailure(String blockId, Throwable t) {
exception.set(t);
notifyAll();
}
};
Expand All @@ -211,8 +210,7 @@ public synchronized void onBlockFetchFailure(String blockId, Throwable exception
fetcher.start();
listener.wait();
}
assertTrue("Should have failed to fetch blocks from non-authorized app.",
gotSecurityException.get());
checkSecurityException(exception.get());

// Register an executor so that the next steps work.
ExecutorShuffleInfo executorInfo = new ExecutorShuffleInfo(
Expand Down Expand Up @@ -243,19 +241,18 @@ public synchronized void onSuccess(int chunkIndex, ManagedBuffer buffer) {
}

@Override
public synchronized void onFailure(int chunkIndex, Throwable e) {
gotSecurityException.set(e.getMessage().contains(SecurityException.class.getName()));
public synchronized void onFailure(int chunkIndex, Throwable t) {
exception.set(t);
notifyAll();
}
};

gotSecurityException.set(false);
exception.set(null);
synchronized (callback) {
client2.fetchChunk(streamId, 0, callback);
callback.wait();
}
assertTrue("Should have failed to fetch blocks from non-authorized stream.",
gotSecurityException.get());
checkSecurityException(exception.get());
} finally {
if (client1 != null) {
client1.close();
Expand All @@ -282,4 +279,10 @@ public StreamManager getStreamManager() {
return new OneForOneStreamManager();
}
}

private void checkSecurityException(Throwable t) {
assertNotNull("No exception was caught.", t);
assertTrue("Expected SecurityException.",
t.getMessage().contains(SecurityException.class.getName()));
}
}