예제 #1
0
  public void merge(Revision base, Revision fork) {
    if (base != fork || base != head.get()) {
      while (!head.compareAndSet(base, fork)) {
        Revision h = head.get();
        fork = base.merge(h, fork, conflictResolver, foreignKeyResolver);
        base = h;
      }

      for (Runnable listener : listeners.get()) {
        listener.run();
      }
    }
  }
예제 #2
0
  @Test
  public void test() {
    RevisionServer rawServer =
        new SimpleRevisionServer(ConflictResolvers.Restrict, ForeignKeyResolvers.Restrict);

    MyTaskHandler handler = new MyTaskHandler();

    RevisionServer asyncServer =
        Servers.asynchronousRevisionServer(
            rawServer, ConflictResolvers.Restrict, ForeignKeyResolvers.Restrict, handler);

    Column<Integer> number = new Column<Integer>(Integer.class);
    Column<String> name = new Column<String>(String.class);
    Table numbers = new Table(cols(number));

    Revision base = rawServer.head();
    rawServer.merge(base, base.builder().table(numbers).row(11).update(name, "once").commit());

    assertEquals("once", rawServer.head().query(name, numbers.primaryKey, 11));

    assertEquals(null, asyncServer.head().query(name, numbers.primaryKey, 11));

    handler.flush();

    assertEquals("once", rawServer.head().query(name, numbers.primaryKey, 11));

    assertEquals("once", asyncServer.head().query(name, numbers.primaryKey, 11));

    base = asyncServer.head();
    asyncServer.merge(base, base.builder().table(numbers).row(12).update(name, "twelve").commit());

    base = asyncServer.head();
    asyncServer.merge(base, base.builder().table(numbers).row(12).update(name, "doce").commit());

    base = rawServer.head();
    rawServer.merge(base, base.builder().table(numbers).row(10).update(name, "diez").commit());

    assertEquals("diez", rawServer.head().query(name, numbers.primaryKey, 10));

    assertEquals(null, asyncServer.head().query(name, numbers.primaryKey, 10));

    assertEquals("once", rawServer.head().query(name, numbers.primaryKey, 11));

    assertEquals("once", asyncServer.head().query(name, numbers.primaryKey, 11));

    assertEquals("doce", rawServer.head().query(name, numbers.primaryKey, 12));

    assertEquals("doce", asyncServer.head().query(name, numbers.primaryKey, 12));

    handler.flush();

    assertEquals("diez", rawServer.head().query(name, numbers.primaryKey, 10));

    assertEquals("diez", asyncServer.head().query(name, numbers.primaryKey, 10));

    assertEquals("once", rawServer.head().query(name, numbers.primaryKey, 11));

    assertEquals("once", asyncServer.head().query(name, numbers.primaryKey, 11));

    assertEquals("doce", rawServer.head().query(name, numbers.primaryKey, 12));

    assertEquals("doce", asyncServer.head().query(name, numbers.primaryKey, 12));
  }