use of java.util.concurrent.atomic.AtomicBoolean in project flink by apache.
the class IOManagerAsyncTest method testExceptionPropagationReader.
@Test
public void testExceptionPropagationReader() {
try {
// use atomic boolean as a boolean reference
final AtomicBoolean handlerCalled = new AtomicBoolean();
final AtomicBoolean exceptionForwarded = new AtomicBoolean();
ReadRequest req = new ReadRequest() {
@Override
public void requestDone(IOException ioex) {
if (ioex instanceof TestIOException) {
exceptionForwarded.set(true);
}
synchronized (handlerCalled) {
handlerCalled.set(true);
handlerCalled.notifyAll();
}
}
@Override
public void read() throws IOException {
throw new TestIOException();
}
};
// test the read queue
RequestQueue<ReadRequest> rq = ioManager.getReadRequestQueue(ioManager.createChannel());
rq.add(req);
// wait until the asynchronous request has been handled
synchronized (handlerCalled) {
while (!handlerCalled.get()) {
handlerCalled.wait();
}
}
assertTrue(exceptionForwarded.get());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
use of java.util.concurrent.atomic.AtomicBoolean in project flink by apache.
the class AsyncCallsTest method testScheduleWithDelay.
@Test
public void testScheduleWithDelay() throws Exception {
// to collect all the thread references
final ReentrantLock lock = new ReentrantLock();
final AtomicBoolean concurrentAccess = new AtomicBoolean(false);
final OneShotLatch latch = new OneShotLatch();
final long delay = 200;
TestEndpoint testEndpoint = new TestEndpoint(akkaRpcService, lock);
testEndpoint.start();
// run something asynchronously
testEndpoint.runAsync(new Runnable() {
@Override
public void run() {
boolean holdsLock = lock.tryLock();
if (holdsLock) {
lock.unlock();
} else {
concurrentAccess.set(true);
}
}
});
final long start = System.nanoTime();
testEndpoint.scheduleRunAsync(new Runnable() {
@Override
public void run() {
boolean holdsLock = lock.tryLock();
if (holdsLock) {
lock.unlock();
} else {
concurrentAccess.set(true);
}
latch.trigger();
}
}, delay, TimeUnit.MILLISECONDS);
latch.await();
final long stop = System.nanoTime();
// validate that no concurrent access happened
assertFalse("Rpc Endpoint had concurrent access", testEndpoint.hasConcurrentAccess());
assertFalse("Rpc Endpoint had concurrent access", concurrentAccess.get());
assertTrue("call was not properly delayed", ((stop - start) / 1000000) >= delay);
}
use of java.util.concurrent.atomic.AtomicBoolean in project flink by apache.
the class CrossTaskTest method testCancelBlockCrossTaskInit.
@Test
public void testCancelBlockCrossTaskInit() {
int keyCnt = 10;
int valCnt = 1;
setOutput(this.output);
addInput(new UniformRecordGenerator(keyCnt, valCnt, false));
addInput(new DelayingInfinitiveInputIterator(100));
getTaskConfig().setDriverStrategy(DriverStrategy.NESTEDLOOP_BLOCKED_OUTER_FIRST);
getTaskConfig().setRelativeMemoryDriver(cross_frac);
final CrossDriver<Record, Record, Record> testTask = new CrossDriver<>();
final AtomicBoolean success = new AtomicBoolean(false);
Thread taskRunner = new Thread() {
@Override
public void run() {
try {
testDriver(testTask, MockCrossStub.class);
success.set(true);
} catch (Exception ie) {
ie.printStackTrace();
}
}
};
taskRunner.start();
TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this);
tct.start();
try {
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
Assert.fail("Joining threads failed");
}
Assert.assertTrue("Exception was thrown despite proper canceling.", success.get());
}
use of java.util.concurrent.atomic.AtomicBoolean in project flink by apache.
the class CrossTaskTest method testCancelBlockCrossTaskCrossing.
@Test
public void testCancelBlockCrossTaskCrossing() {
int keyCnt = 10;
int valCnt = 1;
setOutput(this.output);
addInput(new UniformRecordGenerator(keyCnt, valCnt, false));
addInput(new DelayingInfinitiveInputIterator(100));
getTaskConfig().setDriverStrategy(DriverStrategy.NESTEDLOOP_BLOCKED_OUTER_SECOND);
getTaskConfig().setRelativeMemoryDriver(cross_frac);
final CrossDriver<Record, Record, Record> testTask = new CrossDriver<>();
final AtomicBoolean success = new AtomicBoolean(false);
Thread taskRunner = new Thread() {
@Override
public void run() {
try {
testDriver(testTask, MockCrossStub.class);
success.set(true);
} catch (Exception ie) {
ie.printStackTrace();
}
}
};
taskRunner.start();
TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this);
tct.start();
try {
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
Assert.fail("Joining threads failed");
}
Assert.assertTrue("Exception was thrown despite proper canceling.", success.get());
}
use of java.util.concurrent.atomic.AtomicBoolean in project flink by apache.
the class CachedMatchTaskTest method testCancelHashMatchTaskWhileBuildFirst.
@Test
public void testCancelHashMatchTaskWhileBuildFirst() {
int keyCnt = 20;
int valCnt = 20;
addInput(new DelayingInfinitiveInputIterator(100));
addInput(new UniformRecordGenerator(keyCnt, valCnt, false));
addDriverComparator(this.comparator1);
addDriverComparator(this.comparator2);
getTaskConfig().setDriverPairComparator(RecordPairComparatorFactory.get());
setOutput(new NirvanaOutputList());
getTaskConfig().setDriverStrategy(DriverStrategy.HYBRIDHASH_BUILD_FIRST_CACHED);
getTaskConfig().setRelativeMemoryDriver(1.0f);
final BuildFirstCachedJoinDriver<Record, Record, Record> testTask = new BuildFirstCachedJoinDriver<Record, Record, Record>();
final AtomicBoolean success = new AtomicBoolean(false);
Thread taskRunner = new Thread() {
@Override
public void run() {
try {
testDriver(testTask, MockFailingMatchStub.class);
success.set(true);
} catch (Exception ie) {
ie.printStackTrace();
}
}
};
taskRunner.start();
TaskCancelThread tct = new TaskCancelThread(1, taskRunner, this);
tct.start();
try {
tct.join();
taskRunner.join();
} catch (InterruptedException ie) {
Assert.fail("Joining threads failed");
}
Assert.assertTrue("Test threw an exception even though it was properly canceled.", success.get());
}
Aggregations