use of ai.grakn.kb.internal.GraknTxJanus in project grakn by graknlabs.
the class GraknTxJanusTest method addEntity.
private void addEntity(EntityType type) {
GraknTxJanus graph = janusGraphFactory.open(GraknTxType.WRITE);
type.addEntity();
graph.commit();
}
use of ai.grakn.kb.internal.GraknTxJanus in project grakn by graknlabs.
the class GraknTxJanusTest method whenCreatingDateResource_EnsureDateCanBeRetrieved.
@Test
public void whenCreatingDateResource_EnsureDateCanBeRetrieved() {
when(session.keyspace()).thenReturn(Keyspace.of("case"));
GraknTxJanus graph = new TxFactoryJanus(session).open(GraknTxType.WRITE);
AttributeType<LocalDateTime> dateType = graph.putAttributeType("date", AttributeType.DataType.DATE);
LocalDateTime now = LocalDateTime.now();
Attribute<LocalDateTime> date = dateType.putAttribute(now);
assertEquals(now, date.getValue());
}
use of ai.grakn.kb.internal.GraknTxJanus in project grakn by graknlabs.
the class TxFactoryJanusTest method testSingleton.
@Test
public void testSingleton() {
when(session.keyspace()).thenReturn(Keyspace.of("anothertest"));
TxFactoryJanus factory = new TxFactoryJanus(session);
GraknTxJanus mg1 = factory.open(GraknTxType.BATCH);
JanusGraph tinkerGraphMg1 = mg1.getTinkerPopGraph();
mg1.close();
GraknTxJanus mg2 = factory.open(GraknTxType.WRITE);
JanusGraph tinkerGraphMg2 = mg2.getTinkerPopGraph();
mg2.close();
GraknTxJanus mg3 = factory.open(GraknTxType.BATCH);
assertEquals(mg1, mg3);
assertEquals(tinkerGraphMg1, mg3.getTinkerPopGraph());
assertTrue(mg1.isBatchTx());
assertFalse(mg2.isBatchTx());
assertNotEquals(mg1, mg2);
assertNotEquals(tinkerGraphMg1, tinkerGraphMg2);
StandardJanusGraph standardJanusGraph1 = (StandardJanusGraph) tinkerGraphMg1;
StandardJanusGraph standardJanusGraph2 = (StandardJanusGraph) tinkerGraphMg2;
assertTrue(standardJanusGraph1.getConfiguration().isBatchLoading());
assertFalse(standardJanusGraph2.getConfiguration().isBatchLoading());
}
use of ai.grakn.kb.internal.GraknTxJanus in project grakn by graknlabs.
the class GraknTxJanusTest method whenClosingTheGraph_EnsureTheTransactionIsClosed.
@Test
public void whenClosingTheGraph_EnsureTheTransactionIsClosed() {
when(session.keyspace()).thenReturn(Keyspace.of("test"));
GraknTxJanus graph = new TxFactoryJanus(session).open(GraknTxType.WRITE);
String entityTypeLabel = "Hello";
graph.putEntityType(entityTypeLabel);
assertNotNull(graph.getEntityType(entityTypeLabel));
graph.close();
expectedException.expect(GraknTxOperationException.class);
expectedException.expectMessage(TX_CLOSED_ON_ACTION.getMessage("closed", graph.keyspace()));
// noinspection ResultOfMethodCallIgnored
graph.getEntityType(entityTypeLabel);
}
use of ai.grakn.kb.internal.GraknTxJanus in project grakn by graknlabs.
the class TxFactoryJanusTest method testGraphNotClosed.
@Test
public void testGraphNotClosed() throws InvalidKBException {
when(session.keyspace()).thenReturn(Keyspace.of("stuff"));
TxFactoryJanus factory = new TxFactoryJanus(session);
GraknTxJanus graph = factory.open(GraknTxType.WRITE);
assertFalse(graph.getTinkerPopGraph().isClosed());
graph.putEntityType("A Thing");
graph.close();
graph = factory.open(GraknTxType.WRITE);
assertFalse(graph.getTinkerPopGraph().isClosed());
graph.putEntityType("A Thing");
}
Aggregations