Search in sources :

Example 1 with GraknTxJanus

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

Example 2 with GraknTxJanus

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());
}
Also used : LocalDateTime(java.time.LocalDateTime) GraknTxJanus(ai.grakn.kb.internal.GraknTxJanus) Test(org.junit.Test)

Example 3 with GraknTxJanus

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());
}
Also used : GraknTxJanus(ai.grakn.kb.internal.GraknTxJanus) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) JanusGraph(org.janusgraph.core.JanusGraph) StandardJanusGraph(org.janusgraph.graphdb.database.StandardJanusGraph) Test(org.junit.Test)

Example 4 with GraknTxJanus

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

Example 5 with GraknTxJanus

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");
}
Also used : GraknTxJanus(ai.grakn.kb.internal.GraknTxJanus) Test(org.junit.Test)

Aggregations

GraknTxJanus (ai.grakn.kb.internal.GraknTxJanus)6 Test (org.junit.Test)5 InvalidKBException (ai.grakn.exception.InvalidKBException)1 LocalDateTime (java.time.LocalDateTime)1 HashSet (java.util.HashSet)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 Future (java.util.concurrent.Future)1 JanusGraph (org.janusgraph.core.JanusGraph)1 StandardJanusGraph (org.janusgraph.graphdb.database.StandardJanusGraph)1