Package com.google.nigori.common

Examples of com.google.nigori.common.RevValue


      List<RevValue> answer = new ArrayList<RevValue>(revisions.size());
      for (RevisionValue revisionValue : revisions) {
        byte[] revisionciphertext = revisionValue.getRevision().toByteArray();
        byte[] valueciphertext = revisionValue.getValue().toByteArray();
        if (encKey == null) {
          answer.add(new RevValue(keyManager.decrypt(revisionciphertext), keyManager
              .decrypt(valueciphertext)));
        } else {
          answer.add(new RevValue(keyManager.decrypt(encKey, revisionciphertext), keyManager
              .decrypt(encKey, valueciphertext)));
        }
      }
      return answer;
    } catch (NotFoundException e) {
View Full Code Here


    final String jsonGet =
        MessageLibrary.getRequestAsJson(serverName, keyManager.signer(), key, null);
    expectedCallsForJsonRequest(jsonGet, MessageLibrary.REQUEST_GET);
    expectedCallsToAuthenticateUser(publicHash);
    expect(database.getRecord(eq(user), aryEq(key))).andReturn(
        Arrays.asList(new RevValue[] {new RevValue(revision, value)}));
    ServletOutputStream out = expectedCallsForJsonResponse();
    Capture<byte[]> result = new Capture<byte[]>();
    Capture<Integer> size = new Capture<Integer>();
    out.write(capture(result), eq(0), capture(size));
    out.flush();
View Full Code Here

        List<RevValue> revValues = new ArrayList<RevValue>();
        while (set.next()){
          byte[] rev = set.getBytes("rev");
          byte[] value = set.getBytes("val");
          revValues.add(new RevValue(rev,value));
        }
        return revValues;
      } finally {
        queryStatement.close();
      }
View Full Code Here

    public final RevValue revvalue;
    public final boolean later;

    public IndexValue(String index, String revision, String value, boolean later) {
      this.index = new Index(index);
      this.revvalue = new RevValue(toBytes(revision), toBytes(value));
      this.later = later;
    }
View Full Code Here

  @Test
  public void mergeTwoEquiv() throws IOException, NigoriCryptographyException,
      UnauthorisedException {
    Collection<RevValue> heads = new ArrayList<RevValue>();
    byte[] test = MessageLibrary.toBytes("test");
    RevValue rv = new RevValue(Revision.EMPTY, test);
    RevValue rv1 = new RevValue(Revision.EMPTY, test);
    heads.add(rv);
    heads.add(rv1);
    MigoriDatastore store = createMock(MigoriDatastore.class);
    expect(store.put(eq(INDEX), aryEq(test), eq(rv), eq(rv1))).andReturn(rv);
    replay(store);
    RevValue value = merger.merge(store, INDEX, heads);
    verify(store);
    assertEquals(rv, value);
  }
View Full Code Here

  public void mergeTwoEquivOneGreater() throws IOException, NigoriCryptographyException,
      UnauthorisedException {
    Collection<RevValue> heads = new ArrayList<RevValue>();
    byte[] test = MessageLibrary.toBytes("test");
    byte[] test1 = MessageLibrary.toBytes("test1");
    RevValue rv = new RevValue(Revision.EMPTY, test);
    RevValue rv1 = new RevValue(Revision.EMPTY, test);
    RevValue rv2 = new RevValue(Revision.EMPTY, test1);
    heads.add(rv);
    heads.add(rv1);
    heads.add(rv2);
    MigoriDatastore store = createMock(MigoriDatastore.class);
    expect(store.put(eq(INDEX), aryEq(test), eq(rv), eq(rv1))).andReturn(rv);
    expect(store.put(eq(INDEX), aryEq(test1), eq(rv), eq(rv2))).andReturn(rv2);
    replay(store);
    RevValue value = merger.merge(store, INDEX, heads);
    verify(store);
    assertEquals(rv2, value);
  }
View Full Code Here

  @Test
  public void mergeTwoDiff() throws IOException, NigoriCryptographyException, UnauthorisedException {
    Collection<RevValue> heads = new ArrayList<RevValue>();
    byte[] test = MessageLibrary.toBytes("test");
    byte[] test1 = MessageLibrary.toBytes("test1");
    RevValue rv = new RevValue(Revision.EMPTY, test);
    RevValue rv1 = new RevValue(Revision.EMPTY, test1);
    heads.add(rv);
    heads.add(rv1);
    MigoriDatastore store = createMock(MigoriDatastore.class);
    expect(store.put(eq(INDEX), aryEq(test1), eq(rv), eq(rv1))).andReturn(rv1);
    replay(store);
    RevValue value = merger.merge(store, INDEX, heads);
    verify(store);
    assertEquals(rv1, value);
  }
View Full Code Here

  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

          @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

          @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

Related Classes of com.google.nigori.common.RevValue

Copyright © 2018 www.massapicom. 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.