Fix test and poller instantiation

This commit is contained in:
goapunk
2018-05-23 14:28:51 +02:00
parent c6b88b51f0
commit 3793cb841b
2 changed files with 8 additions and 10 deletions

View File

@@ -108,6 +108,13 @@ class PluginManagerImpl implements PluginManager, Service {
@Override @Override
public void startService() throws ServiceException { public void startService() throws ServiceException {
if (used.getAndSet(true)) throw new IllegalStateException(); if (used.getAndSet(true)) throw new IllegalStateException();
// Instantiate the poller
if (pluginConfig.shouldPoll()) {
LOG.info("Starting poller");
Poller poller = new Poller(ioExecutor, scheduler, connectionManager,
connectionRegistry, this, random, clock);
eventBus.addListener(poller);
}
// Instantiate the simplex plugins and start them asynchronously // Instantiate the simplex plugins and start them asynchronously
LOG.info("Starting simplex plugins"); LOG.info("Starting simplex plugins");
for (SimplexPluginFactory f : pluginConfig.getSimplexFactories()) { for (SimplexPluginFactory f : pluginConfig.getSimplexFactories()) {
@@ -140,13 +147,6 @@ class PluginManagerImpl implements PluginManager, Service {
ioExecutor.execute(new PluginStarter(d, startLatch)); ioExecutor.execute(new PluginStarter(d, startLatch));
} }
} }
// Instantiate the poller
if (pluginConfig.shouldPoll()) {
LOG.info("Starting poller");
Poller poller = new Poller(ioExecutor, scheduler, connectionManager,
connectionRegistry, this, random, clock);
eventBus.addListener(poller);
}
} }
@Override @Override

View File

@@ -40,9 +40,7 @@ public class PluginManagerImplTest extends BrambleTestCase {
setThreadingPolicy(new Synchroniser()); setThreadingPolicy(new Synchroniser());
}}; }};
Executor ioExecutor = Executors.newSingleThreadExecutor(); Executor ioExecutor = Executors.newSingleThreadExecutor();
RejectedExecutionHandler policy = ScheduledExecutorService scheduler = context.mock(ScheduledExecutorService.class);
new ScheduledThreadPoolExecutor.DiscardPolicy();
ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1, policy);
SecureRandom random = new SecureRandom(); SecureRandom random = new SecureRandom();
Clock clock = context.mock(Clock.class); Clock clock = context.mock(Clock.class);
EventBus eventBus = context.mock(EventBus.class); EventBus eventBus = context.mock(EventBus.class);