Search in sources :

Example 16 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class RedisCountStorageTest method whenChangingCountsOnRedis_EnsureValueIsChanges.

@Test
public void whenChangingCountsOnRedis_EnsureValueIsChanges() {
    Keyspace keyspace1 = SampleKBLoader.randomKeyspace();
    Keyspace keyspace2 = SampleKBLoader.randomKeyspace();
    ConceptId roach = ConceptId.of("Roach");
    ConceptId ciri = ConceptId.of("Ciri");
    assertEquals(0, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace1, roach)));
    assertEquals(0, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace2, roach)));
    redis.incrementCount(RedisCountStorage.getKeyNumInstances(keyspace1, roach), 1);
    assertEquals(1, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace1, roach)));
    assertEquals(0, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace2, roach)));
    redis.incrementCount(RedisCountStorage.getKeyNumInstances(keyspace2, ciri), 1);
    assertEquals(0, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace1, ciri)));
    assertEquals(1, redis.getCount(RedisCountStorage.getKeyNumInstances(keyspace2, ciri)));
}
Also used : Keyspace(ai.grakn.Keyspace) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 17 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class GraknTxTest method whenAttemptingToMutateReadOnlyGraph_Throw.

@Test
public void whenAttemptingToMutateReadOnlyGraph_Throw() {
    Keyspace keyspace = Keyspace.of("myreadonlygraph");
    String entityType = "My Entity Type";
    String roleType1 = "My Role Type 1";
    String roleType2 = "My Role Type 2";
    String relationType1 = "My Relationship Type 1";
    String relationType2 = "My Relationship Type 2";
    String resourceType = "My Attribute Type";
    // Fail Some Mutations
    tx = EmbeddedGraknSession.create(keyspace, Grakn.IN_MEMORY).open(GraknTxType.READ);
    failMutation(tx, () -> tx.putEntityType(entityType));
    failMutation(tx, () -> tx.putRole(roleType1));
    failMutation(tx, () -> tx.putRelationshipType(relationType1));
    // Pass some mutations
    tx.close();
    tx = EmbeddedGraknSession.create(keyspace, Grakn.IN_MEMORY).open(GraknTxType.WRITE);
    EntityType entityT = tx.putEntityType(entityType);
    entityT.addEntity();
    Role roleT1 = tx.putRole(roleType1);
    Role roleT2 = tx.putRole(roleType2);
    RelationshipType relationT1 = tx.putRelationshipType(relationType1).relates(roleT1);
    RelationshipType relationT2 = tx.putRelationshipType(relationType2).relates(roleT2);
    AttributeType<String> resourceT = tx.putAttributeType(resourceType, AttributeType.DataType.STRING);
    tx.commit();
    // Fail some mutations again
    tx = EmbeddedGraknSession.create(keyspace, Grakn.IN_MEMORY).open(GraknTxType.READ);
    failMutation(tx, entityT::addEntity);
    failMutation(tx, () -> resourceT.putAttribute("A resource"));
    failMutation(tx, () -> tx.putEntityType(entityType));
    failMutation(tx, () -> entityT.plays(roleT1));
    failMutation(tx, () -> relationT1.relates(roleT2));
    failMutation(tx, () -> relationT2.relates(roleT1));
}
Also used : EntityType(ai.grakn.concept.EntityType) Role(ai.grakn.concept.Role) Keyspace(ai.grakn.Keyspace) RelationshipType(ai.grakn.concept.RelationshipType) Test(org.junit.Test)

Example 18 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class IndexPostProcessorTest method whenPostProcessingIndices_EnsureFixingMethodIsCalled.

@Test
public void whenPostProcessingIndices_EnsureFixingMethodIsCalled() {
    // Setup mocks
    Keyspace keyspace = Keyspace.of("whatakeyspace");
    EmbeddedGraknTx<?> tx = mock(EmbeddedGraknTx.class);
    when(tx.duplicateResourcesExist(any(), any())).thenReturn(true);
    when(tx.keyspace()).thenReturn(keyspace);
    String index = "index1";
    Set<ConceptId> ids = Stream.of("a", "b", "c").map(ConceptId::of).collect(Collectors.toSet());
    // Call post processor
    indexPostProcessor.mergeDuplicateConcepts(tx, index, ids);
    // Check method calls
    verify(tx, Mockito.times(1)).fixDuplicateResources(index, ids);
}
Also used : Keyspace(ai.grakn.Keyspace) ConceptId(ai.grakn.concept.ConceptId) Test(org.junit.Test)

Example 19 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class JsonMigratorTest method setup.

@Before
public void setup() {
    Keyspace keyspace = SampleKBLoader.randomKeyspace();
    factory = Grakn.session(engine.uri(), keyspace);
    migrator = new MigratorBuilder().setUri(engine.uri()).setKeyspace(keyspace).setRetries(0).setFailFast(false).build();
}
Also used : Keyspace(ai.grakn.Keyspace) MigratorBuilder(ai.grakn.migration.base.MigratorBuilder) Before(org.junit.Before)

Example 20 with Keyspace

use of ai.grakn.Keyspace in project grakn by graknlabs.

the class BatchExecutorClientIT method whenEngineRESTFailsWhileLoadingWithRetryTrue_LoaderRetriesAndWaits.

@Ignore("Randomly failing test which is slowing down dev. This should be fixed")
@Test
public void whenEngineRESTFailsWhileLoadingWithRetryTrue_LoaderRetriesAndWaits() throws Exception {
    List<Observable<QueryResponse>> all = new ArrayList<>();
    int n = 20;
    try (BatchExecutorClient loader = loader(MAX_DELAY)) {
        for (int i = 0; i < n; i++) {
            all.add(loader.add(query(), keyspace, true).doOnError(ex -> System.out.println("Error " + ex)));
            if (i % 5 == 0) {
                Thread.sleep(200);
                System.out.println("Restarting engine");
                engine.server().getHttpHandler().stopHTTP();
                Thread.sleep(200);
                engine.server().getHttpHandler().startHTTP();
            }
        }
        int completed = allObservable(all).toBlocking().first().size();
        assertEquals(n, completed);
    }
    if (GraknTestUtil.usingJanus()) {
        try (GraknTx graph = session.open(GraknTxType.READ)) {
            assertEquals(n, graph.getEntityType("name_tag").instances().count());
        }
    }
}
Also used : HystrixRequestLog(com.netflix.hystrix.HystrixRequestLog) Stream.generate(java.util.stream.Stream.generate) GraknTestUtil(ai.grakn.util.GraknTestUtil) Keyspace(ai.grakn.Keyspace) Role(ai.grakn.concept.Role) Assume.assumeFalse(org.junit.Assume.assumeFalse) InsertQuery(ai.grakn.graql.InsertQuery) Graql(ai.grakn.graql.Graql) ConcurrencyUtil.allObservable(ai.grakn.util.ConcurrencyUtil.allObservable) QueryResponse(ai.grakn.client.QueryResponse) Mockito.spy(org.mockito.Mockito.spy) EntityType(ai.grakn.concept.EntityType) Observable(rx.Observable) ArrayList(java.util.ArrayList) AttributeType(ai.grakn.concept.AttributeType) GraknTx(ai.grakn.GraknTx) GraknClient(ai.grakn.client.GraknClient) ClassRule(org.junit.ClassRule) ExpectedException(org.junit.rules.ExpectedException) EngineContext(ai.grakn.test.rule.EngineContext) Before(org.junit.Before) GraknTxType(ai.grakn.GraknTxType) Graql.var(ai.grakn.graql.Graql.var) BatchExecutorClient(ai.grakn.client.BatchExecutorClient) HystrixEventType(com.netflix.hystrix.HystrixEventType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) UUID(java.util.UUID) GraknTestUtil.usingTinker(ai.grakn.util.GraknTestUtil.usingTinker) HystrixCommand(com.netflix.hystrix.HystrixCommand) List(java.util.List) Rule(org.junit.Rule) Ignore(org.junit.Ignore) EmbeddedGraknSession(ai.grakn.factory.EmbeddedGraknSession) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) SampleKBLoader.randomKeyspace(ai.grakn.util.SampleKBLoader.randomKeyspace) Assert.assertEquals(org.junit.Assert.assertEquals) GraknTx(ai.grakn.GraknTx) EmbeddedGraknTx(ai.grakn.kb.internal.EmbeddedGraknTx) ArrayList(java.util.ArrayList) BatchExecutorClient(ai.grakn.client.BatchExecutorClient) ConcurrencyUtil.allObservable(ai.grakn.util.ConcurrencyUtil.allObservable) Observable(rx.Observable) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

Keyspace (ai.grakn.Keyspace)30 Test (org.junit.Test)14 GraknTx (ai.grakn.GraknTx)9 GraknTxType (ai.grakn.GraknTxType)7 ConceptId (ai.grakn.concept.ConceptId)7 List (java.util.List)6 BatchExecutorClient (ai.grakn.client.BatchExecutorClient)5 Timer (com.codahale.metrics.Timer)5 LoggerFactory (org.slf4j.LoggerFactory)5 GraknSession (ai.grakn.GraknSession)4 Role (ai.grakn.concept.Role)4 InsertQuery (ai.grakn.graql.InsertQuery)4 SimpleURI (ai.grakn.util.SimpleURI)4 Before (org.junit.Before)4 Logger (org.slf4j.Logger)4 GraknClient (ai.grakn.client.GraknClient)3 AttributeType (ai.grakn.concept.AttributeType)3 EntityType (ai.grakn.concept.EntityType)3 RelationshipType (ai.grakn.concept.RelationshipType)3 Graql (ai.grakn.graql.Graql)3