Search in sources :

Example 1 with MessageListener

use of org.cryptomator.ui.util.SingleInstanceManager.MessageListener in project cryptomator by cryptomator.

the class SingleInstanceManagerTest method testOneMessage.

@Test
public void testOneMessage() throws Exception {
    ExecutorService exec = Executors.newCachedThreadPool();
    try {
        final LocalInstance server = SingleInstanceManager.startLocalInstance(appKey, exec);
        final Optional<RemoteInstance> r = SingleInstanceManager.getRemoteInstance(appKey);
        CountDownLatch latch = new CountDownLatch(1);
        final MessageListener listener = spy(new MessageListener() {

            @Override
            public void handleMessage(String message) {
                latch.countDown();
            }
        });
        server.registerListener(listener);
        assertTrue(r.isPresent());
        String message = "Is this thing on?";
        assertTrue(r.get().sendMessage(message, 1000));
        System.out.println("wrote message");
        latch.await(10, TimeUnit.SECONDS);
        verify(listener).handleMessage(message);
    } finally {
        exec.shutdownNow();
    }
}
Also used : LocalInstance(org.cryptomator.ui.util.SingleInstanceManager.LocalInstance) ExecutorService(java.util.concurrent.ExecutorService) MessageListener(org.cryptomator.ui.util.SingleInstanceManager.MessageListener) RemoteInstance(org.cryptomator.ui.util.SingleInstanceManager.RemoteInstance) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecutorService (java.util.concurrent.ExecutorService)1 LocalInstance (org.cryptomator.ui.util.SingleInstanceManager.LocalInstance)1 MessageListener (org.cryptomator.ui.util.SingleInstanceManager.MessageListener)1 RemoteInstance (org.cryptomator.ui.util.SingleInstanceManager.RemoteInstance)1 Test (org.junit.Test)1