Search in sources :

Example 6 with InterProcessCommunication

use of com.cinchapi.concourse.server.plugin.io.InterProcessCommunication in project concourse by cinchapi.

the class BackgroundThreadTest method testBackgroundExecutorSetsEnvironmentCorrectly.

@Test
public void testBackgroundExecutorSetsEnvironmentCorrectly() throws InterruptedException {
    InterProcessCommunication outgoing = new MessageQueue();
    ConcurrentMap<AccessToken, RemoteMethodResponse> responses = Maps.newConcurrentMap();
    String environment1 = Random.getSimpleString();
    String environment2 = Random.getSimpleString();
    MockConcourseRuntime runtime = new MockConcourseRuntime();
    BackgroundExecutor executor = PluginExecutors.newCachedBackgroundExecutor(outgoing, responses);
    CountDownLatch latch = new CountDownLatch(2);
    final AtomicBoolean passed = new AtomicBoolean(true);
    executor.execute(environment1, () -> {
        try {
            Assert.assertEquals(environment1, runtime.environment());
            latch.countDown();
        } catch (AssertionError e) {
            passed.set(false);
            e.printStackTrace();
        }
    });
    executor.execute(environment2, () -> {
        try {
            Assert.assertEquals(environment2, runtime.environment());
            latch.countDown();
        } catch (AssertionError e) {
            passed.set(false);
            e.printStackTrace();
        }
    });
    latch.await();
    Assert.assertTrue(passed.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MessageQueue(com.cinchapi.concourse.server.plugin.io.MessageQueue) AccessToken(com.cinchapi.concourse.thrift.AccessToken) InterProcessCommunication(com.cinchapi.concourse.server.plugin.io.InterProcessCommunication) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

InterProcessCommunication (com.cinchapi.concourse.server.plugin.io.InterProcessCommunication)6 MessageQueue (com.cinchapi.concourse.server.plugin.io.MessageQueue)5 AccessToken (com.cinchapi.concourse.thrift.AccessToken)4 ByteBuffer (java.nio.ByteBuffer)4 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 AnyStrings (com.cinchapi.common.base.AnyStrings)1 CheckedExceptions (com.cinchapi.common.base.CheckedExceptions)1 Reflection (com.cinchapi.common.reflect.Reflection)1 ConcourseServer (com.cinchapi.concourse.server.ConcourseServer)1 BINARY_QUEUE (com.cinchapi.concourse.server.GlobalState.BINARY_QUEUE)1 FileSystem (com.cinchapi.concourse.server.io.FileSystem)1 JavaApp (com.cinchapi.concourse.server.io.process.JavaApp)1 WriteEvent (com.cinchapi.concourse.server.plugin.data.WriteEvent)1 AfterInstallHook (com.cinchapi.concourse.server.plugin.hook.AfterInstallHook)1 PluginSerializer (com.cinchapi.concourse.server.plugin.io.PluginSerializer)1 Versions (com.cinchapi.concourse.server.plugin.util.Versions)1 ComplexTObject (com.cinchapi.concourse.thrift.ComplexTObject)1 TransactionToken (com.cinchapi.concourse.thrift.TransactionToken)1 Time (com.cinchapi.concourse.time.Time)1 ConcurrentMaps (com.cinchapi.concourse.util.ConcurrentMaps)1