예제 #1
0
  /**
   * Verify that sync() on a cluster node will continue fetching results until no more changes are
   * detected.
   *
   * @throws Exception
   */
  public void testSyncAllChanges() throws Exception {
    // create channel on master and slave
    LockEventChannel channel = master.createLockChannel(DEFAULT_WORKSPACE);
    slave.createLockChannel(DEFAULT_WORKSPACE).setListener(new SimpleEventListener());

    // add blocking consumer to slave, this will block on the first non-empty sync()
    BlockingConsumer consumer = new BlockingConsumer();
    slave.getJournal().register(consumer);

    // add first entry
    LockEvent event = new LockEvent(NodeId.randomId(), true, "admin");
    channel.create(event.getNodeId(), event.isDeep(), event.getUserId()).ended(true);

    // start a manual sync on the slave and ...
    Thread syncOnce =
        new Thread(
            new Runnable() {
              public void run() {
                try {
                  slave.sync();
                } catch (ClusterException e) {
                  /* ignore */
                }
              }
            });
    syncOnce.start();

    // ... wait until it blocks
    consumer.waitUntilBlocked();

    // add second entry
    event = new LockEvent(NodeId.randomId(), true, "admin");
    channel.create(event.getNodeId(), event.isDeep(), event.getUserId()).ended(true);

    // now unblock slave
    consumer.unblock();

    // wait for the sync to finish
    syncOnce.join();

    assertEquals(master.getRevision(), slave.getRevision());
  }