@BeforeMethod
 public void setUp() throws Exception {
   threadPool = new ThreadPool();
   store = createStore();
   store.deleteContent();
   storeReplica = createStoreReplica();
   storeReplica.deleteContent();
   engine = createEngine(store, createTranslog());
   engine.start();
   replicaEngine = createEngine(storeReplica, createTranslogReplica());
   replicaEngine.start();
 }
Example #2
0
 public static void main(String[] args) {
   // Starts the game
   Engine.start();
   // Tutorial.readMap();
   // Runs the game
   Engine.menu();
 }
Example #3
0
  @Test(timeout = 30000)
  public void testNoDeadlockIfTransportExceptionOccurs() throws InterruptedException {
    // NOTE: This test is EXPECTED to print a NoSuchFileException
    // stacktrace. It can be ignored.
    String loc = TestData.DATA_DIR + File.separator + Time.now();
    final Engine engine = new Engine(loc + File.separator + "buffer", loc + File.separator + "db");
    engine.start();
    for (int i = 0; i < 1000; i++) {
      engine.accept(Write.add("foo", Convert.javaToThrift("bar"), i));
    }
    FileSystem.deleteDirectory(loc);
    Thread a =
        new Thread(
            new Runnable() {

              @Override
              public void run() {
                engine.find("foo", Operator.EQUALS, Convert.javaToThrift("bar"));
              }
            });
    Thread.sleep(2000); // this is an arbitrary amount. In 2 seconds, at
    // least one page should have transported...
    a.start();
    a.join();
    engine.stop();
    Assert.assertTrue(true); // if we reach here, this means that the Engine
    // was able to break out of the transport
    // exception
    System.out.println("[INFO] You can ignore the NoSuchFileException stack trace above");
  }
  @Test
  public void testAbstractFactory() {

    CarFactory carFactory = new LuxuryCarFactory();
    Engine engine = carFactory.createEngine();
    engine.run();
    engine.start();
  }
 @Before
 public void setUp() throws Exception {
   super.setUp();
   defaultSettings =
       ImmutableSettings.builder()
           .put(RobinEngine.INDEX_COMPOUND_ON_FLUSH, getRandom().nextBoolean())
           .build(); // TODO randomize more settings
   threadPool = new ThreadPool();
   store = createStore();
   store.deleteContent();
   storeReplica = createStoreReplica();
   storeReplica.deleteContent();
   engineSettingsService = new IndexSettingsService(shardId.index(), EMPTY_SETTINGS);
   engine = createEngine(engineSettingsService, store, createTranslog());
   engine.start();
   replicaSettingsService = new IndexSettingsService(shardId.index(), EMPTY_SETTINGS);
   replicaEngine = createEngine(replicaSettingsService, storeReplica, createTranslogReplica());
   replicaEngine.start();
 }
Example #6
0
 @Test
 public void testNoBufferTransportBlockingIfWritesAreWithinThreshold() {
   String loc = TestData.DATA_DIR + File.separator + Time.now();
   final Engine engine = new Engine(loc + File.separator + "buffer", loc + File.separator + "db");
   Variables.register("now", Time.now());
   engine.start();
   engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong());
   engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong());
   engine.stop();
   Assert.assertFalse(engine.bufferTransportThreadHasEverPaused.get());
   FileSystem.deleteDirectory(loc);
 }
Example #7
0
 @Test
 public void testBufferTransportBlockingIfWritesAreNotWithinThreshold() {
   String loc = TestData.DATA_DIR + File.separator + Time.now();
   final Engine engine = new Engine(loc + File.separator + "buffer", loc + File.separator + "db");
   engine.start();
   engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong());
   Threads.sleep(
       Engine.BUFFER_TRANSPORT_THREAD_ALLOWABLE_INACTIVITY_THRESHOLD_IN_MILLISECONDS + 10);
   engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong());
   Assert.assertTrue(engine.bufferTransportThreadHasEverPaused.get());
   engine.stop();
   FileSystem.deleteDirectory(loc);
 }
Example #8
0
  /**
   * JVM main entry method.
   *
   * @param arguments Command-line arguments
   */
  public static void main(String... arguments) {

    /* parse command line. */
    Parameters parameters = CliFactory.parseArguments(Parameters.class, arguments);

    /* create the state manager. */
    StateManager stateManager = new StateManager(parameters.getStateDirectory());

    /* create the engine. */
    Engine engine = new Engine(stateManager);

    /* start a watcher. */
    ChainWatcher chainWatcher = new ChainWatcher(engine, parameters.getChainDirectory());
    chainWatcher.start();

    /* start the engine. */
    engine.start();
  }
Example #9
0
  @Test
  public void testBufferTransportThreadWillRestartIfHung() {
    int frequency = Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_FREQUENCY_IN_MILLISECONDS;
    int threshold = Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_THRESOLD_IN_MILLISECONDS;
    final AtomicBoolean done = new AtomicBoolean(false);
    try {
      Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_FREQUENCY_IN_MILLISECONDS = 100;
      Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_THRESOLD_IN_MILLISECONDS = 500;
      int lag = 5000;
      String loc = TestData.DATA_DIR + File.separator + Time.now();
      final Engine engine =
          new Engine(loc + File.separator + "buffer", loc + File.separator + "db");
      engine.bufferTransportThreadSleepInMs =
          Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_THRESOLD_IN_MILLISECONDS + lag;
      engine.start();
      Thread thread =
          new Thread(
              new Runnable() {

                @Override
                public void run() {
                  while (!done.get()) {
                    engine.add(TestData.getString(), TestData.getTObject(), TestData.getLong());
                  }
                }
              });
      thread.start();
      Threads.sleep(
          (int) (1.2 * Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_THRESOLD_IN_MILLISECONDS)
              + Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_FREQUENCY_IN_MILLISECONDS);
      Assert.assertTrue(engine.bufferTransportThreadHasEverAppearedHung.get());
      Threads.sleep(
          (int) (Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_THRESOLD_IN_MILLISECONDS * 1.2));
      Assert.assertTrue(engine.bufferTransportThreadHasEverBeenRestarted.get());
      engine.stop();
      FileSystem.deleteDirectory(loc);
    } finally {
      done.set(true);
      Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_FREQUENCY_IN_MILLISECONDS = frequency;
      Engine.BUFFER_TRANSPORT_THREAD_HUNG_DETECTION_THRESOLD_IN_MILLISECONDS = threshold;
    }
  }
Example #10
0
 @Test
 public void testNoDuplicateDataIfUnexpectedShutdownOccurs() throws Exception {
   Engine engine = (Engine) store;
   Buffer buffer = (Buffer) engine.buffer;
   Database db = (Database) engine.destination;
   Method method = buffer.getClass().getDeclaredMethod("canTransport");
   method.setAccessible(true);
   int count = 0;
   while (!(boolean) method.invoke(buffer)) {
     engine.add("count", Convert.javaToThrift(count), Integer.valueOf(count).longValue());
     count++;
   }
   for (int i = 0; i < count - 2; i++) { // leave one write on the page so
     // buffer doesn't automatically
     // call db.triggerSync()
     buffer.transport(db);
   }
   db.triggerSync();
   engine = new Engine(buffer.getBackingStore(), db.getBackingStore());
   engine.start(); // Simulate unexpected shutdown by "restarting" the
   // Engine
   while ((boolean) method.invoke(engine.buffer)) { // wait until the first
     // page in the buffer
     // (which contains the
     // same data that was
     // previously
     // transported) is done
     // transporting again
     Random.sleep();
   }
   for (int i = 0; i < count; i++) {
     Assert.assertTrue(
         engine
             .find("count", Operator.EQUALS, Convert.javaToThrift(i))
             .contains(Integer.valueOf(i).longValue()));
   }
 }
Example #11
0
 public static void main(String[] args) {
   CarFactory factory = new LuxuryCarFactory();
   Engine e = factory.createEngine();
   e.run();
   e.start();
 }
Example #12
0
  @Override
  public void start(Stage primaryStage) {
    try {
      screen = primaryStage;
      screen.setOnCloseRequest(
          e -> {
            engine.interrupt();
          });

      lives = new SimpleDoubleProperty(1);
      lives.addListener(
          e -> {
            if (lives.get() == 0) {
              engine.interrupt();
              newGame.setText("Start new game");
              changeScene();
            }
          });

      logo = new Image(getClass().getResourceAsStream("logo.png"), 256, 256, true, true);
      logoView = new ImageView(logo);
      menu = new StackPane(logoView);

      livesText = new Text(String.valueOf((int) lives.get()));
      slowDownsText = new Text(String.valueOf(slowDownCount));
      score = new Text("Score");
      scorePoints = new Text(String.valueOf(points));

      livesText.setFill(Color.BEIGE);
      slowDownsText.setFill(Color.BEIGE);
      score.setFill(Color.BEIGE);
      scorePoints.setFill(Color.BEIGE);

      live = new Image(getClass().getResourceAsStream("live.png"));
      slowDown = new Image(getClass().getResourceAsStream("slowdown.png"));

      spotView = new ImageView(new Image(getClass().getResourceAsStream("spot.png")));
      liveView = new ImageView(live);
      slowDownView = new ImageView(slowDown);
      liveCounterView = new ImageView(live);
      slowDownCounterView = new ImageView(slowDown);

      spotView.setVisible(false);
      liveView.setVisible(false);
      slowDownView.setVisible(false);

      spotView.setOnMouseClicked(
          e -> {
            spotView.setVisible(false);
            clicked = true;
            points++;
            if (time > 400) {
              time -= 20;
            }
            scorePoints.setText(String.valueOf(points * 10));
          });

      liveView.setOnMouseClicked(
          e -> {
            liveView.setVisible(false);
            clicked = true;
            points++;
            lives.set(lives.get() + 1);
            livesText.setText(String.valueOf((int) lives.get()));
            scorePoints.setText(String.valueOf(points * 10));
          });

      slowDownView.setOnMouseClicked(
          e -> {
            slowDownView.setVisible(false);
            clicked = true;
            points++;
            slowDownCount++;
            slowDownsText.setText(String.valueOf(slowDownCount));
            scorePoints.setText(String.valueOf(points * 10));
          });

      slowDownCounterView.setOnMouseClicked(
          e -> {
            if (slowDownCount > 0) {
              slowDownCount--;
              slowDownsText.setText(String.valueOf(slowDownCount));
              time += 150;
            }
          });

      Separator sepOne = new Separator(Orientation.VERTICAL);
      sepOne.setOpacity(0.1);

      Separator sepTwo = new Separator(Orientation.VERTICAL);
      sepTwo.setOpacity(0.1);

      HBox header =
          new HBox(
              5,
              liveCounterView,
              livesText,
              sepOne,
              slowDownCounterView,
              slowDownsText,
              sepTwo,
              score,
              scorePoints);
      header.setAlignment(Pos.CENTER_LEFT);
      header.setStyle(
          "-fx-background-color:linear-gradient(#242424 50%, #2D2D2D 75%, #3C3C3C 100%);");
      header.setPadding(new Insets(3, 1, 3, 1));

      playField = new StackPane(spotView, liveView, slowDownView);
      playField.setAlignment(Pos.TOP_LEFT);
      playField.setStyle(
          "-fx-background-color: linear-gradient(#9d9e9d 5%, #6b6a6b 20%, #343534 80%, #242424 100%);");

      root = new BorderPane(playField, header, null, null, null);
      root.setStyle("-fx-border-color: #13BFF8");

      playScene = new Scene(root, 300, 500);

      newGame = new Button("Start");
      newGame.setStyle(
          "-fx-background-color: linear-gradient(TRANSPARENT 50%, #FFFFFF 100%);  -fx-text-fill: #FFFFFF; -fx-min-width: 128px;");
      newGame.setOnMouseEntered(
          e ->
              newGame.setStyle(
                  "-fx-background-color: linear-gradient(TRANSPARENT 10%, #FFFFFF 100%);  -fx-text-fill: #FFFFFF; -fx-min-width: 128px;"));
      newGame.setOnMouseExited(
          e ->
              newGame.setStyle(
                  "-fx-background-color: linear-gradient(TRANSPARENT 50%, #FFFFFF 100%);  -fx-text-fill: #FFFFFF; -fx-min-width: 128px;"));
      newGame.setTranslateY(80);
      newGame.setOnMouseClicked(
          e -> {
            points = 0;
            time = 1500;
            clicked = false;
            slowDownCount = 0;
            lives.set(1);
            livesText.setText(String.valueOf((int) lives.get()));
            screen.setScene(playScene);
            engine = new Engine(this);
            engine.start();
          });
      menu.getChildren().add(newGame);

      menuScene = new Scene(menu, 256, 256);
      menu.setStyle(
          "-fx-background-color: linear-gradient(#9d9e9d 5%, #6b6a6b 20%, #343534 80%, #242424 100%); -fx-border-color: #13BFF8;");

      primaryStage.setScene(menuScene);
      primaryStage.setResizable(false);
      primaryStage.initStyle(StageStyle.UNDECORATED);
      primaryStage.show();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Example #13
0
 public TwoMedia(String title, String world) {
   super(title, world, true, false);
   engine = new Engine(this);
   engine.start();
 }
Example #14
0
  public void start() {

    engine = new Engine(this);

    engine.start();
  }