Exemplo n.º 1
0
  @Test
  public void testWorkerIsConnectionReady() {
    ConnectionWithStatus connection = Mockito.mock(ConnectionWithStatus.class);
    Mockito.when(connection.status()).thenReturn(ConnectionWithStatus.Status.Ready);
    assertTrue(WorkerState.isConnectionReady(connection));

    Mockito.when(connection.status()).thenReturn(ConnectionWithStatus.Status.Connecting);
    assertFalse(WorkerState.isConnectionReady(connection));

    Mockito.when(connection.status()).thenReturn(ConnectionWithStatus.Status.Closed);
    assertFalse(WorkerState.isConnectionReady(connection));
  }
Exemplo n.º 2
0
 /**
  * (non-Javadoc)
  *
  * @see java.lang.Runnable#run()
  */
 @Override
 public void run() {
   while (state != null && state.equals(WorkerState.LIVE)) {
     long startCycleTime = System.currentTimeMillis();
     TICK_SERVICE.performCycle();
     // calculates the amount of time it took to complete this game cycle
     elapsedCycleTime = (System.currentTimeMillis() - startCycleTime);
     cycleCount++;
     avg += elapsedCycleTime;
     // System.out.println("Cycle: " + cycleCount + ", Time: " + elapsedCycleTime + "ms, Average: "
     // + (avg/cycleCount) + "ms, Ticks: " + TICK_SERVICE.getTicks().size());
     if (GameClock.CYCLE_RATE > elapsedCycleTime) {
       try {
         Thread.sleep(GameClock.CYCLE_RATE - elapsedCycleTime);
       } catch (Exception e) {
         logger.error("Caught Engine Exception on Cycle: " + cycleCount, e);
       }
     } else {
       logger.warn("Skipped game cycle: " + cycleCount);
     }
   }
 }