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