Pass executor to scheduler.

This commit is contained in:
akwizgran
2020-08-06 13:11:12 +01:00
parent d5395d3d01
commit 3aa00ecb3d
14 changed files with 128 additions and 92 deletions

View File

@@ -234,7 +234,8 @@ public class PollerImplTest extends BrambleMockTestCase {
oneOf(clock).currentTimeMillis();
will(returnValue(now));
oneOf(scheduler).schedule(with(any(Runnable.class)),
with((long) pollingInterval), with(MILLISECONDS));
with(ioExecutor), with((long) pollingInterval),
with(MILLISECONDS));
will(returnValue(future));
}});
@@ -262,7 +263,8 @@ public class PollerImplTest extends BrambleMockTestCase {
oneOf(clock).currentTimeMillis();
will(returnValue(now));
oneOf(scheduler).schedule(with(any(Runnable.class)),
with((long) pollingInterval), with(MILLISECONDS));
with(ioExecutor), with((long) pollingInterval),
with(MILLISECONDS));
will(returnValue(future));
// Second event
// Get the plugin
@@ -304,7 +306,8 @@ public class PollerImplTest extends BrambleMockTestCase {
oneOf(clock).currentTimeMillis();
will(returnValue(now));
oneOf(scheduler).schedule(with(any(Runnable.class)),
with((long) pollingInterval), with(MILLISECONDS));
with(ioExecutor), with((long) pollingInterval),
with(MILLISECONDS));
will(returnValue(future));
// Second event
// Get the plugin
@@ -320,7 +323,8 @@ public class PollerImplTest extends BrambleMockTestCase {
will(returnValue(now + 1));
oneOf(future).cancel(false);
oneOf(scheduler).schedule(with(any(Runnable.class)),
with((long) pollingInterval - 2), with(MILLISECONDS));
with(ioExecutor), with((long) pollingInterval - 2),
with(MILLISECONDS));
}});
poller.eventOccurred(new ConnectionOpenedEvent(contactId, transportId,
@@ -345,8 +349,8 @@ public class PollerImplTest extends BrambleMockTestCase {
// Schedule a polling task immediately
oneOf(clock).currentTimeMillis();
will(returnValue(now));
oneOf(scheduler).schedule(with(any(Runnable.class)), with(0L),
with(MILLISECONDS));
oneOf(scheduler).schedule(with(any(Runnable.class)),
with(ioExecutor), with(0L), with(MILLISECONDS));
will(returnValue(future));
will(new RunAction());
// Running the polling task schedules the next polling task
@@ -357,7 +361,8 @@ public class PollerImplTest extends BrambleMockTestCase {
oneOf(clock).currentTimeMillis();
will(returnValue(now));
oneOf(scheduler).schedule(with(any(Runnable.class)),
with((long) (pollingInterval * 0.5)), with(MILLISECONDS));
with(ioExecutor), with((long) (pollingInterval * 0.5)),
with(MILLISECONDS));
will(returnValue(future));
// Get the transport properties and connected contacts
oneOf(transportPropertyManager).getRemoteProperties(transportId);
@@ -388,8 +393,8 @@ public class PollerImplTest extends BrambleMockTestCase {
// Schedule a polling task immediately
oneOf(clock).currentTimeMillis();
will(returnValue(now));
oneOf(scheduler).schedule(with(any(Runnable.class)), with(0L),
with(MILLISECONDS));
oneOf(scheduler).schedule(with(any(Runnable.class)),
with(ioExecutor), with(0L), with(MILLISECONDS));
will(returnValue(future));
will(new RunAction());
// Running the polling task schedules the next polling task
@@ -400,7 +405,8 @@ public class PollerImplTest extends BrambleMockTestCase {
oneOf(clock).currentTimeMillis();
will(returnValue(now));
oneOf(scheduler).schedule(with(any(Runnable.class)),
with((long) (pollingInterval * 0.5)), with(MILLISECONDS));
with(ioExecutor), with((long) (pollingInterval * 0.5)),
with(MILLISECONDS));
will(returnValue(future));
// Get the transport properties and connected contacts
oneOf(transportPropertyManager).getRemoteProperties(transportId);
@@ -429,8 +435,8 @@ public class PollerImplTest extends BrambleMockTestCase {
// Schedule a polling task immediately
oneOf(clock).currentTimeMillis();
will(returnValue(now));
oneOf(scheduler).schedule(with(any(Runnable.class)), with(0L),
with(MILLISECONDS));
oneOf(scheduler).schedule(with(any(Runnable.class)),
with(ioExecutor), with(0L), with(MILLISECONDS));
will(returnValue(future));
// The plugin is deactivated before the task runs - cancel the task
oneOf(future).cancel(false);
@@ -454,7 +460,8 @@ public class PollerImplTest extends BrambleMockTestCase {
oneOf(clock).currentTimeMillis();
will(returnValue(now));
oneOf(scheduler).schedule(with(any(Runnable.class)),
with((long) pollingInterval), with(MILLISECONDS));
with(ioExecutor), with((long) pollingInterval),
with(MILLISECONDS));
will(returnValue(future));
}});
}

View File

@@ -123,8 +123,8 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
e.getPendingContactState() == OFFLINE)));
// Capture the poll task
oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
with(MILLISECONDS));
with(any(Executor.class)), with(POLLING_INTERVAL_MS),
with(POLLING_INTERVAL_MS), with(MILLISECONDS));
will(new CaptureArgumentAction<>(capturePollTask, Runnable.class,
0));
}});
@@ -159,8 +159,8 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
e.getPendingContactState() == FAILED)));
// Schedule the poll task
oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
with(MILLISECONDS));
with(any(Executor.class)), with(POLLING_INTERVAL_MS),
with(POLLING_INTERVAL_MS), with(MILLISECONDS));
}});
rendezvousPoller.startService();
@@ -468,8 +468,8 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
will(returnValue(emptyList()));
// Capture the poll task
oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
with(MILLISECONDS));
with(any(Executor.class)), with(POLLING_INTERVAL_MS),
with(POLLING_INTERVAL_MS), with(MILLISECONDS));
will(new CaptureArgumentAction<>(capturePollTask, Runnable.class,
0));
}});
@@ -545,8 +545,8 @@ public class RendezvousPollerImplTest extends BrambleMockTestCase {
e.getPendingContactState() == OFFLINE)));
// Capture the poll task
oneOf(scheduler).scheduleWithFixedDelay(with(any(Runnable.class)),
with(POLLING_INTERVAL_MS), with(POLLING_INTERVAL_MS),
with(MILLISECONDS));
with(any(Executor.class)), with(POLLING_INTERVAL_MS),
with(POLLING_INTERVAL_MS), with(MILLISECONDS));
will(new CaptureArgumentAction<>(capturePollTask, Runnable.class,
0));
}});

View File

@@ -117,7 +117,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
new TransportKeySet(keySetId, contactId, null, updated)));
// Schedule a key update at the start of the next time period
oneOf(scheduler).schedule(with(any(Runnable.class)),
with(timePeriodLength - 1), with(MILLISECONDS));
with(dbExecutor), with(timePeriodLength - 1),
with(MILLISECONDS));
}});
transportKeyManager.start(txn);
@@ -420,7 +421,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
}
// Schedule a key update at the start of the next time period
oneOf(scheduler).schedule(with(any(Runnable.class)),
with(timePeriodLength), with(MILLISECONDS));
with(dbExecutor), with(timePeriodLength),
with(MILLISECONDS));
will(new RunAction());
oneOf(dbExecutor).execute(with(any(Runnable.class)));
will(new RunAction());
@@ -445,7 +447,8 @@ public class TransportKeyManagerImplTest extends BrambleMockTestCase {
new TransportKeySet(keySetId, contactId, null, updated)));
// Schedule a key update at the start of the next time period
oneOf(scheduler).schedule(with(any(Runnable.class)),
with(timePeriodLength), with(MILLISECONDS));
with(dbExecutor), with(timePeriodLength),
with(MILLISECONDS));
}});
transportKeyManager.start(txn);