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());
}
}
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());
}
}
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());
}
}
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;
}
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;
}
Aggregations