Search in sources :

Example 11 with AtomicBoolean

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());
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IOException(java.io.IOException) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with AtomicBoolean

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);
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) OneShotLatch(org.apache.flink.core.testutils.OneShotLatch) Test(org.junit.Test)

Example 13 with AtomicBoolean

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DelayingInfinitiveInputIterator(org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 14 with AtomicBoolean

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DelayingInfinitiveInputIterator(org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Example 15 with AtomicBoolean

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());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DelayingInfinitiveInputIterator(org.apache.flink.runtime.operators.testutils.DelayingInfinitiveInputIterator) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Record(org.apache.flink.types.Record) UniformRecordGenerator(org.apache.flink.runtime.operators.testutils.UniformRecordGenerator) NirvanaOutputList(org.apache.flink.runtime.operators.testutils.NirvanaOutputList) ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) TaskCancelThread(org.apache.flink.runtime.operators.testutils.TaskCancelThread) Test(org.junit.Test)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2412 Test (org.junit.Test)1002 CountDownLatch (java.util.concurrent.CountDownLatch)394 IOException (java.io.IOException)336 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)301 ArrayList (java.util.ArrayList)214 AtomicReference (java.util.concurrent.atomic.AtomicReference)202 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)108 Test (org.testng.annotations.Test)106 List (java.util.List)98 Ignite (org.apache.ignite.Ignite)98 AtomicLong (java.util.concurrent.atomic.AtomicLong)94 HashMap (java.util.HashMap)93 ExecutorService (java.util.concurrent.ExecutorService)90 Map (java.util.Map)88 ExecutionException (java.util.concurrent.ExecutionException)87 File (java.io.File)68 Random (java.util.Random)68 CyclicBarrier (java.util.concurrent.CyclicBarrier)68 HashSet (java.util.HashSet)63