Example usage for java.util.concurrent ScheduledThreadPoolExecutor submit

List of usage examples for java.util.concurrent ScheduledThreadPoolExecutor submit

Introduction

In this page you can find the example usage for java.util.concurrent ScheduledThreadPoolExecutor submit.

Prototype

public <T> Future<T> submit(Callable<T> task) 

Source Link

Usage

From source file:com.btoddb.chronicle.plunkers.HdfsPlunkerImplTest.java

@Test
public void testInitThenHandleEventThenShutdown(@Mocked final HdfsFileFactory fileFactory,
        @Injectable final ScheduledThreadPoolExecutor closeExec, // don't want other executors affected
        @Mocked final HdfsFileContext aContext, @Mocked final HdfsTextFileImpl aFile,
        @Mocked final ScheduledFuture<Void> aFuture) throws Exception {
    final List<Event> events = Arrays.asList(
            new Event("the-body").withHeader("msgId", "msg1").withHeader("customer", "customer1"),
            new Event("the-body").withHeader("msgId", "msg2").withHeader("customer", "customer2"));

    new NonStrictExpectations() {
        {//  ww  w  .  j av  a 2  s .co  m
            for (int i = 1; i <= 2; i++) {
                HdfsFile hdfsFile = new HdfsTextFileImpl();
                //                hdfsFile.init(anyString, anyString, (EventSerializer) any); times = 1;
                hdfsFile.write(events.get(i - 1));
                times = 1;

                fileFactory.createFile(withSubstring("customer" + i), anyString);
                times = 1;
                result = hdfsFile;

                HdfsFileContext context = new HdfsFileContext(hdfsFile);
                context.getHdfsFile();
                times = 1;
                result = hdfsFile;

                context.readLock();
                times = 1;
                context.readUnlock();
                times = 1;
            }
            closeExec.submit((Runnable) any);
            times = 2;
        }
    };

    plunker.setFileFactory(fileFactory);
    plunker.setCloseExec(closeExec);
    plunker.init(config);
    plunker.handleInternal(events);
    plunker.shutdown();
}