use of ai.grakn.kb.log.CommitLog in project grakn by graknlabs.
the class PostProcessingTest method createAndUploadCountCommitLog.
private void createAndUploadCountCommitLog(Keyspace keyspace, ConceptId conceptId, long count) {
// Create the fake commit log
CommitLog commitLog = CommitLog.createDefault(keyspace);
commitLog.instanceCount().put(conceptId, count);
// Start up the Job
postProcessor.submit(commitLog);
}
use of ai.grakn.kb.log.CommitLog in project grakn by graknlabs.
the class CountPostProcessorTest method whenBreachingTheShardingThreshold_ShardingHappens.
@Test
public void whenBreachingTheShardingThreshold_ShardingHappens() {
// Configure mock to return value which breaches threshold
ConceptId id = ConceptId.of("e");
newInstanceCounts.put(id, 6L);
when(countStorage.incrementInstanceCount(keyspace, id, 6L)).thenReturn(6L);
when(countStorage.incrementInstanceCount(keyspace, id, 0L)).thenReturn(6L);
// Create fake commit log
CommitLog commitLog = CommitLog.create(keyspace, newInstanceCounts, Collections.emptyMap());
// Update The Counts
countPostProcessor.updateCounts(commitLog);
// Check Sharding Takes Place
verify(factoryMock, Mockito.times(1)).tx(keyspace, GraknTxType.WRITE);
verify(countStorage, Mockito.times(1)).incrementShardCount(keyspace, id, 1);
}
use of ai.grakn.kb.log.CommitLog in project grakn by graknlabs.
the class CountPostProcessorTest method whenUpdatingInstanceCounts_EnsureRedisIsUpdated.
@Test
public void whenUpdatingInstanceCounts_EnsureRedisIsUpdated() {
// Create fake commit log
CommitLog commitLog = CommitLog.create(keyspace, newInstanceCounts, Collections.emptyMap());
// Update The Counts
countPostProcessor.updateCounts(commitLog);
// Check the calls
newInstanceCounts.forEach((id, value) -> {
// Redis is updated
verify(countStorage, Mockito.times(1)).getShardCount(keyspace, id);
verify(countStorage, Mockito.times(1)).incrementInstanceCount(keyspace, id, value);
});
// No Sharding takes place
verify(factoryMock, Mockito.times(0)).tx(any(Keyspace.class), any());
}
use of ai.grakn.kb.log.CommitLog in project grakn by graknlabs.
the class GraqlControllerInsertTest method POSTGraqlInsert_CommitLogsAreSubmitted.
@Test
public void POSTGraqlInsert_CommitLogsAreSubmitted() {
String query = "insert $x isa person has name 'Alice';";
CommitLog commitLog = CommitLog.create(tx.keyspace(), Collections.emptyMap(), Collections.emptyMap());
when(tx.commitSubmitNoLogs()).thenReturn(Optional.of(commitLog));
sendRequest(query);
verify(postProcessor, times(1)).submit(commitLog);
}
use of ai.grakn.kb.log.CommitLog in project grakn by graknlabs.
the class CommitLogController method submitConcepts.
@POST
@Path("/kb/{keyspace}/commit_log")
private String submitConcepts(Request req) throws IOException {
CommitLog commitLog = mapper.readValue(req.body(), CommitLog.class);
CompletableFuture.allOf(CompletableFuture.runAsync(() -> postProcessor.submit(commitLog))).join();
return "";
}
Aggregations