Search in sources :

Example 1 with Revision

use of com.google.nigori.common.Revision in project nigori by ucam-cl-dtg.

the class SetGetDeleteTest method getIndices.

@Test
public void getIndices() throws IOException, NigoriCryptographyException, UnauthorisedException {
    NigoriDatastore nigori = getStore();
    try {
        assertTrue("Not registered", nigori.register());
        final Index indexa = new Index("indexa");
        final Index indexb = new Index("indexb");
        final Revision revision = new Revision("a");
        assertTrue("Not put", nigori.put(indexa, revision, toBytes("aa")));
        assertTrue("Not put", nigori.put(indexb, revision, toBytes("bb")));
        try {
            List<Index> indices = nigori.getIndices();
            assertNotNull("No indices", indices);
            assertEquals("Not correct number of indices", 2, indices.size());
            assertThat(indices, hasItem(indexa));
            assertThat(indices, hasItem(indexb));
        } finally {
            nigori.delete(indexa, NULL_DELETE_TOKEN);
            nigori.delete(indexb, NULL_DELETE_TOKEN);
        }
    } finally {
        assertTrue("Not unregistered", nigori.unregister());
    }
}
Also used : Revision(com.google.nigori.common.Revision) NigoriDatastore(com.google.nigori.client.NigoriDatastore) Index(com.google.nigori.common.Index) Test(org.junit.Test)

Example 2 with Revision

use of com.google.nigori.common.Revision in project nigori by ucam-cl-dtg.

the class SetGetDeleteTest method immutableRevisions.

// @Test //TODO(drt24) Do we want to enforce revisions being immutable? Migori doesn't really need
// this due to the way revisions are generated.
public void immutableRevisions() throws IOException, NigoriCryptographyException, UnauthorisedException {
    NigoriDatastore nigori = getStore();
    try {
        assertTrue("Not registered", nigori.register());
        final Index index = new Index("index");
        final Revision revision = new Revision("rev");
        assertTrue("Not put", nigori.put(index, revision, Util.int2bin(0)));
        assertFalse("Could replace revision value", nigori.put(index, revision, Util.int2bin(1)));
        nigori.delete(index, NULL_DELETE_TOKEN);
    } finally {
        assertTrue("Not unregistered", nigori.unregister());
    }
}
Also used : Revision(com.google.nigori.common.Revision) NigoriDatastore(com.google.nigori.client.NigoriDatastore) Index(com.google.nigori.common.Index)

Example 3 with Revision

use of com.google.nigori.common.Revision in project nigori by ucam-cl-dtg.

the class SetGetDeleteTest method getRevisions.

@Test
public void getRevisions() throws IOException, NigoriCryptographyException, UnauthorisedException {
    NigoriDatastore nigori = getStore();
    try {
        assertTrue("Not registered", nigori.register());
        final Index index = new Index("index");
        final Revision a = new Revision("a");
        final Revision b = new Revision("b");
        assertTrue("Not put", nigori.put(index, a, toBytes("aa")));
        assertTrue("Not put", nigori.put(index, b, toBytes("bb")));
        try {
            List<Revision> revisions = nigori.getRevisions(index);
            assertNotNull("No revisions", revisions);
            assertEquals("Not correct number of revisions", 2, revisions.size());
            assertThat(revisions, hasItem(a));
            assertThat(revisions, hasItem(b));
        } finally {
            nigori.delete(index, NULL_DELETE_TOKEN);
        }
    } finally {
        assertTrue("Not unregistered", nigori.unregister());
    }
}
Also used : Revision(com.google.nigori.common.Revision) NigoriDatastore(com.google.nigori.client.NigoriDatastore) Index(com.google.nigori.common.Index) Test(org.junit.Test)

Example 4 with Revision

use of com.google.nigori.common.Revision in project nigori by ucam-cl-dtg.

the class HashMigoriDatastore method put.

@Override
public RevValue put(Index index, byte[] value, RevValue... parents) throws IOException, NigoriCryptographyException, UnauthorisedException {
    byte[] revBytes = generateHash(value, toIDByte(parents));
    Revision rev = new Revision(revBytes);
    RevValue rv = new RevValue(rev, value);
    boolean success = store.put(index, rev, value);
    if (!success) {
        throw new IOException("Could not put into the store");
    }
    return rv;
}
Also used : Revision(com.google.nigori.common.Revision) RevValue(com.google.nigori.common.RevValue) IOException(java.io.IOException)

Example 5 with Revision

use of com.google.nigori.common.Revision in project nigori by ucam-cl-dtg.

the class HashMigoriDatastore method get.

@Override
public List<RevValue> get(Index index) throws NigoriCryptographyException, IOException, UnauthorisedException {
    DAG<Revision> history = getHistory(index);
    if (history == null) {
        return null;
    }
    Collection<Node<Revision>> heads = history.getHeads();
    List<RevValue> answer = new ArrayList<RevValue>();
    for (Node<Revision> rev : heads) {
        Revision revision = rev.getValue();
        byte[] value = getRevision(index, revision);
        // TODO(drt24) value might be null
        if (value != null) {
            answer.add(new RevValue(revision, value));
        }
    }
    return answer;
}
Also used : Revision(com.google.nigori.common.Revision) RevValue(com.google.nigori.common.RevValue) ArrayList(java.util.ArrayList)

Aggregations

Revision (com.google.nigori.common.Revision)8 NigoriDatastore (com.google.nigori.client.NigoriDatastore)5 Index (com.google.nigori.common.Index)5 Test (org.junit.Test)4 RevValue (com.google.nigori.common.RevValue)3 ArrayList (java.util.ArrayList)2 IndexValue (com.google.nigori.client.accept.n.SetGetDeleteTest.IndexValue)1 GetRevisionsResponse (com.google.nigori.common.NigoriMessages.GetRevisionsResponse)1 NotFoundException (com.google.nigori.common.NotFoundException)1 ByteString (com.google.protobuf.ByteString)1 IOException (java.io.IOException)1 Random (java.util.Random)1