use of won.bot.framework.bot.Bot in project webofneeds by researchstudio-sat.
the class BotTests method testIsInitializedMultiThreaded.
/**
* Makes sure that the initialize cannot be entered by more than one thread.
*/
@Test
public void testIsInitializedMultiThreaded() throws BrokenBarrierException, InterruptedException {
// set of threads that managed to enter the initialize method
final Set<Thread> threadsInInit = Collections.synchronizedSet(new HashSet<Thread>());
// bot impl that remembers which thread entered the initialize method
final Bot bot = new DebugBot() {
@Override
protected void doInitialize() {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
threadsInInit.add(Thread.currentThread());
}
};
// start 10 threads that initialize the bot
int numThreads = 10;
final Random rnd = new Random(System.currentTimeMillis());
final CyclicBarrier barrier = new CyclicBarrier(numThreads + 1);
for (int i = 0; i < numThreads; i++) {
Thread thread = new Thread() {
@Override
public void run() {
try {
Thread.sleep(rnd.nextInt(100));
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
bot.initialize();
} catch (Exception e) {
e.printStackTrace();
}
try {
barrier.await();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (BrokenBarrierException e) {
e.printStackTrace();
}
}
};
thread.start();
}
barrier.await();
// make sure the bot is initialized
Assert.assertTrue(bot.getLifecyclePhase().isActive());
// make sure it was initialized only once
Assert.assertTrue(threadsInInit.size() == 1);
}
use of won.bot.framework.bot.Bot in project webofneeds by researchstudio-sat.
the class BotTests method testIsShutdown.
@Test
public void testIsShutdown() {
Bot bot = new DebugBot();
try {
bot.shutdown();
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertTrue(bot.getLifecyclePhase().isDown());
}
use of won.bot.framework.bot.Bot in project webofneeds by researchstudio-sat.
the class BotTests method testIsInitialized.
@Test
public void testIsInitialized() {
Bot bot = new DebugBot();
try {
bot.initialize();
} catch (Exception e) {
e.printStackTrace();
}
Assert.assertTrue(bot.getLifecyclePhase().isActive());
}
Aggregations