Search in sources :

Example 1 with CommitLog

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);
}
Also used : CommitLog(ai.grakn.kb.log.CommitLog)

Example 2 with 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);
}
Also used : CommitLog(ai.grakn.kb.log.CommitLog) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 3 with CommitLog

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());
}
Also used : Keyspace(ai.grakn.Keyspace) CommitLog(ai.grakn.kb.log.CommitLog) Test(org.junit.Test)

Example 4 with CommitLog

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);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommitLog(ai.grakn.kb.log.CommitLog) Test(org.junit.Test)

Example 5 with 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 "";
}
Also used : CommitLog(ai.grakn.kb.log.CommitLog) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

CommitLog (ai.grakn.kb.log.CommitLog)7 Test (org.junit.Test)5 Keyspace (ai.grakn.Keyspace)3 ConceptId (ai.grakn.concept.ConceptId)3 Set (java.util.Set)2 GraknConfigKey (ai.grakn.GraknConfigKey)1 GraknTxType (ai.grakn.GraknTxType)1 Attribute (ai.grakn.concept.Attribute)1 AttributeType (ai.grakn.concept.AttributeType)1 Concept (ai.grakn.concept.Concept)1 EntityType (ai.grakn.concept.EntityType)1 GraknConfig (ai.grakn.engine.GraknConfig)1 BackgroundTask (ai.grakn.engine.task.BackgroundTask)1 CountPostProcessor (ai.grakn.engine.task.postprocessing.CountPostProcessor)1 IndexPostProcessor (ai.grakn.engine.task.postprocessing.IndexPostProcessor)1 PostProcessor (ai.grakn.engine.task.postprocessing.PostProcessor)1 RedisCountStorage (ai.grakn.engine.task.postprocessing.redisstorage.RedisCountStorage)1 RedisIndexStorage (ai.grakn.engine.task.postprocessing.redisstorage.RedisIndexStorage)1 InvalidKBException (ai.grakn.exception.InvalidKBException)1 EmbeddedGraknSession (ai.grakn.factory.EmbeddedGraknSession)1