Examples of MigoriDatastore


Examples of com.google.nigori.client.MigoriDatastore

*/
public class MSetGetTest extends AcceptanceTest {

  @Test
  public void putGraph() throws NigoriCryptographyException, IOException, UnauthorisedException {
    MigoriDatastore store = getStore();
    store.register();
    try {
      Index index = new Index("test");
      RevValue a = store.put(index, "a".getBytes());
      RevValue b = store.put(index, "b".getBytes(), a);
      RevValue c = store.put(index, "c".getBytes(), a);
      RevValue d = store.put(index, "d".getBytes(), b, c);
      RevValue e = store.put(index, "e".getBytes(), c, b);
      RevValue f = store.put(index, "f".getBytes(), d);
      RevValue g = store.put(index, "g".getBytes(), e);
      Collection<RevValue> heads = store.get(index);
      assertThat(heads, hasItems(f, g));

      assertTrue(store.removeIndex(index, g.getRevision()));
    } finally {
      store.unregister();
    }
  }
View Full Code Here

Examples of com.google.nigori.client.MigoriDatastore

  public void deterministicEqual() throws NigoriCryptographyException, IOException,
      UnauthorisedException {
    failed = false;
    Thread[] threads = new Thread[THREADS];

    final MigoriDatastore migori = getStore();
    final Index index = new Index("Concurrency");
    assertTrue("Not registered", migori.register());
    try {
      final List<Throwable> exceptionList =
          Collections.synchronizedList(new LinkedList<Throwable>());
      for (int j = 0; j < THREADS; ++j) {
        threads[j] = new Thread() {
          @Override
          public void run() {
            boolean succeeded = false;
            try {

              RevValue last = migori.put(index, Util.int2bin(0));
              for (int i = 0; i < REPEATS; ++i) {
                last = migori.put(index, Util.int2bin(i), last);
              }
              succeeded = true;
            } catch (Throwable e) {
              exceptionList.add(e);
            } finally {
              if (!succeeded && !failed) {
                failed = true;
              }
            }
          }
        };
      }
      startThenJoinThreads(threads);

      ifFailedPrintFailures(failed, exceptionList);

      Collection<RevValue> heads = migori.get(index);
      assertEquals(1, heads.size());
      RevValue head = heads.toArray(new RevValue[1])[0];
      int total = Util.bin2int(head.getValue(), 0);
      assertEquals(REPEATS - 1, total);
      assertTrue(migori.removeIndex(index, head.getRevision()));

    } finally {
      assertTrue("Not unregistered", migori.unregister());
    }
  }
View Full Code Here

Examples of com.google.nigori.client.MigoriDatastore

  public void nonInterferenceOfSeparateHistories() throws NigoriCryptographyException, IOException,
      UnauthorisedException {
    failed = false;
    Thread[] threads = new Thread[THREADS];

    final MigoriDatastore migori = getStore();
    final Index index = new Index("Concurrency");
    assertTrue("Not registered", migori.register());
    try {
      final List<Throwable> exceptionList =
          Collections.synchronizedList(new LinkedList<Throwable>());
      for (int j = 0; j < THREADS; ++j) {
        final int startFactor = j;
        threads[j] = new Thread() {
          @Override
          public void run() {
            boolean succeeded = false;
            try {

              RevValue last = migori.put(index, Util.int2bin(0));
              for (int i = startFactor * REPEATS; i < startFactor * REPEATS + REPEATS; ++i) {
                last = migori.put(index, Util.int2bin(i), last);
              }
              succeeded = true;
            } catch (Throwable e) {
              exceptionList.add(e);
            } finally {
              if (!succeeded && !failed) {
                failed = true;
              }
            }
          }
        };
      }
      startThenJoinThreads(threads);

      ifFailedPrintFailures(failed, exceptionList);

      Collection<RevValue> heads = migori.get(index);
      assertEquals(4, heads.size());
      int total = 0;
      RevValue deleteAt = null;
      for (RevValue head : heads) {
        deleteAt = head;
        int value = Util.bin2int(head.getValue(), 0);
        total += value;
      }
      assertEquals(REPEATS * 10 - 4, total);
      assertNotNull(deleteAt);
      if (deleteAt != null)
        assertTrue(migori.removeIndex(index, deleteAt.getRevision()));

    } finally {
      assertTrue("Not unregistered", migori.unregister());
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.