本文整理汇总了Java中org.jmock.lib.concurrent.DeterministicScheduler类的典型用法代码示例。如果您正苦于以下问题:Java DeterministicScheduler类的具体用法?Java DeterministicScheduler怎么用?Java DeterministicScheduler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DeterministicScheduler类属于org.jmock.lib.concurrent包,在下文中一共展示了DeterministicScheduler类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: testStartSuddenDeath
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Test
public void testStartSuddenDeath() {
DeterministicScheduler scheduler = new DeterministicScheduler();
DeterministicStopWatch stopWatch = new DeterministicStopWatch();
List<Message> messages = new ArrayList<>();
SuddenDeath suddenDeath = new SuddenDeath(50, 5, 11, new InternalScheduler(scheduler, stopWatch), messages::add);
suddenDeath.onStartGame(emptyList());
stopWatch.setTime(60 * 1000);
scheduler.tick(300, TimeUnit.MILLISECONDS);
scheduler.tick(5001, TimeUnit.MILLISECONDS);
assertThat(messages).containsExactly(
GmsgMessage.of(format(SuddenDeath.START_MESSAGE_TEMPLATE, 11, 5)),
ClassicStyleAddMessage.of(0, 4),
ClassicStyleAddMessage.of(0, 4),
ClassicStyleAddMessage.of(0, 2),
ClassicStyleAddMessage.of(0, 1),
ClassicStyleAddMessage.of(0, 4),
ClassicStyleAddMessage.of(0, 4),
ClassicStyleAddMessage.of(0, 2),
ClassicStyleAddMessage.of(0, 1)
);
}
开发者ID:nosceon,项目名称:tenorite,代码行数:26,代码来源:SuddenDeathTest.java
示例2: testStopSuddenDeathBeforeDelay
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Test
public void testStopSuddenDeathBeforeDelay() {
DeterministicScheduler scheduler = new DeterministicScheduler();
DeterministicStopWatch stopWatch = new DeterministicStopWatch();
List<Message> messages = new ArrayList<>();
SuddenDeath suddenDeath = new SuddenDeath(50, 5, 11, new InternalScheduler(scheduler, stopWatch), messages::add);
suddenDeath.onStartGame(emptyList());
stopWatch.setTime(60 * 1000);
scheduler.tick(300, TimeUnit.MILLISECONDS);
suddenDeath.onEndGame();
messages.clear();
scheduler.tick(5001, TimeUnit.MILLISECONDS);
assertThat(messages).isEmpty();
}
开发者ID:nosceon,项目名称:tenorite,代码行数:20,代码来源:SuddenDeathTest.java
示例3: testAddReloadBasicsConfig
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Test(timeout = 60000)
public void testAddReloadBasicsConfig() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
DeterministicScheduler mockScheduler = new DeterministicScheduler();
FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
ConfigurationSubscription confSub =
new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
assertEquals(null, conf.getProperty("prop1"));
// add
writer.setProperty("prop1", "1");
writer.save();
// ensure the file change reloading event can be triggered
ensureConfigReloaded();
mockScheduler.tick(100, TimeUnit.MILLISECONDS);
assertEquals("1", conf.getProperty("prop1"));
}
开发者ID:twitter,项目名称:distributedlog,代码行数:21,代码来源:TestConfigurationSubscription.java
示例4: testInitialConfigLoad
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Test(timeout = 60000)
public void testInitialConfigLoad() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
writer.setProperty("prop1", "1");
writer.setProperty("prop2", "abc");
writer.setProperty("prop3", "123.0");
writer.setProperty("prop4", "11132");
writer.setProperty("prop5", "true");
writer.save();
ScheduledExecutorService mockScheduler = new DeterministicScheduler();
FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
ConfigurationSubscription confSub =
new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
assertEquals(1, conf.getInt("prop1"));
assertEquals("abc", conf.getString("prop2"));
assertEquals(123.0, conf.getFloat("prop3"), 0);
assertEquals(11132, conf.getInt("prop4"));
assertEquals(true, conf.getBoolean("prop5"));
}
开发者ID:twitter,项目名称:distributedlog,代码行数:23,代码来源:TestConfigurationSubscription.java
示例5: setup
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Before
public void setup() throws Exception {
memoryPoolBeans.clear();
doReturn(0L).when(configuration).getCheckIntervalInMillis();
doReturn(heapMemoryUsage).when(memoryBean).getHeapMemoryUsage();
scheduler = spy(new DeterministicScheduler());
doReturn(Collections.emptyList()).when(scheduler).shutdownNow();
subject = spy(new MBeanMonitor(heapDumpCreator, configuration,
new Callable<ScheduledExecutorService>() {
@Override
public ScheduledExecutorService call() throws Exception {
return scheduler;
}
}, logger) {
@Override
MemoryMXBean getMemoryMxBean() {
return memoryBean;
}
@Override
List<MemoryPoolMXBean> getMemoryPoolMxBeans() {
return memoryPoolBeans;
}
});
doReturn(jvm).when(subject).findCurrentJvm();
}
开发者ID:SAP,项目名称:java-memory-assistant,代码行数:32,代码来源:MBeanMonitorTest.java
示例6: testWarningMessage
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Test
public void testWarningMessage() {
DeterministicScheduler scheduler = new DeterministicScheduler();
DeterministicStopWatch stopWatch = new DeterministicStopWatch();
List<Message> messages = new ArrayList<>();
SuddenDeath suddenDeath = new SuddenDeath(50, 5, 7, new InternalScheduler(scheduler, stopWatch), messages::add);
suddenDeath.onStartGame(emptyList());
stopWatch.setTime(20 * 1000);
scheduler.tick(300, TimeUnit.MILLISECONDS);
assertThat(messages).containsExactly(GmsgMessage.of("WARNING! Sudden death will begin in 30 seconds"));
}
开发者ID:nosceon,项目名称:tenorite,代码行数:15,代码来源:SuddenDeathTest.java
示例7: setUp
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Before
public void setUp() {
executor = new DeterministicScheduler();
}
开发者ID:spotify,项目名称:completable-futures,代码行数:5,代码来源:CompletableFuturesTest.java
示例8: testExceptionInConfigLoad
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Test(timeout = 60000)
public void testExceptionInConfigLoad() throws Exception {
PropertiesWriter writer = new PropertiesWriter();
writer.setProperty("prop1", "1");
writer.save();
DeterministicScheduler mockScheduler = new DeterministicScheduler();
FileConfigurationBuilder builder = new PropertiesConfigurationBuilder(writer.getFile().toURI().toURL());
ConcurrentConstConfiguration conf = new ConcurrentConstConfiguration(new DistributedLogConfiguration());
List<FileConfigurationBuilder> fileConfigBuilders = Lists.newArrayList(builder);
ConfigurationSubscription confSub =
new ConfigurationSubscription(conf, fileConfigBuilders, mockScheduler, 100, TimeUnit.MILLISECONDS);
final AtomicInteger count = new AtomicInteger(1);
conf.addConfigurationListener(new ConfigurationListener() {
@Override
public void configurationChanged(ConfigurationEvent event) {
LOG.info("config changed {}", event);
// Throw after so we actually see the update anyway.
if (!event.isBeforeUpdate()) {
count.getAndIncrement();
throw new RuntimeException("config listener threw and exception");
}
}
});
int i = 0;
int initial = 0;
while (count.get() == initial) {
writer.setProperty("prop1", Integer.toString(i++));
writer.save();
mockScheduler.tick(100, TimeUnit.MILLISECONDS);
}
initial = count.get();
while (count.get() == initial) {
writer.setProperty("prop1", Integer.toString(i++));
writer.save();
mockScheduler.tick(100, TimeUnit.MILLISECONDS);
}
}
开发者ID:twitter,项目名称:distributedlog,代码行数:42,代码来源:TestConfigurationSubscription.java
示例9: testSimple
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Test
public void testSimple() throws Exception {
HostAndPort hostNameA = HostAndPort.fromString("a:1");
HostAndPort hostNameB = HostAndPort.fromString("b:1");
HostAndPort hostNameC = HostAndPort.fromString("c:1");
HostAndPort hostNameD = HostAndPort.fromString("d:1");
DnsSrvResolver resolver = Mockito.mock(DnsSrvResolver.class);
// Run shutdown code immediately
DeterministicScheduler executor = new DeterministicScheduler();
final Map<HostAndPort, FakeRawMemcacheClient> knownClients = Maps.newHashMap();
SrvKetamaClient.Connector connector = input -> {
FakeRawMemcacheClient fakeRawMemcacheClient = new FakeRawMemcacheClient();
knownClients.put(input, fakeRawMemcacheClient);
return fakeRawMemcacheClient;
};
SrvKetamaClient ketamaClient = new SrvKetamaClient(
"the-srv-record", resolver, executor, 1000, TimeUnit.MILLISECONDS,
connector, 1000, TimeUnit.MILLISECONDS);
executor.tick(1000, TimeUnit.SECONDS);
assertFalse(ketamaClient.isConnected());
Mockito.when(resolver.resolve(Mockito.anyString()))
.thenReturn(ImmutableList.of(result("a"), result("b")));
ketamaClient.updateDNS();
executor.tick(1000, TimeUnit.SECONDS);
assertTrue(ketamaClient.isConnected());
assertTrue(knownClients.get(hostNameA).isConnected());
assertTrue(knownClients.get(hostNameB).isConnected());
Mockito.when(resolver.resolve(Mockito.anyString()))
.thenReturn(ImmutableList.of(result("b"), result("c")));
ketamaClient.updateDNS();
executor.tick(1000, TimeUnit.SECONDS);
assertTrue(ketamaClient.isConnected());
assertFalse(knownClients.get(hostNameA).isConnected());
assertTrue(knownClients.get(hostNameB).isConnected());
assertTrue(knownClients.get(hostNameC).isConnected());
Mockito.when(resolver.resolve(Mockito.anyString()))
.thenReturn(ImmutableList.of(result("c"), result("d")));
ketamaClient.updateDNS();
executor.tick(1000, TimeUnit.SECONDS);
assertTrue(ketamaClient.isConnected());
assertFalse(knownClients.get(hostNameA).isConnected());
assertFalse(knownClients.get(hostNameB).isConnected());
assertTrue(knownClients.get(hostNameC).isConnected());
assertTrue(knownClients.get(hostNameD).isConnected());
ketamaClient.shutdown();
}
开发者ID:spotify,项目名称:folsom,代码行数:60,代码来源:SrvKetamaClientTest.java
示例10: setUp
import org.jmock.lib.concurrent.DeterministicScheduler; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
scheduler = new DeterministicScheduler();
}
开发者ID:spotify,项目名称:futures-extra,代码行数:5,代码来源:TimeoutFutureTest.java
注:本文中的org.jmock.lib.concurrent.DeterministicScheduler类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论