Search in sources :

Example 11 with GraknSession

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

the class GraknTxTest method whenOpeningDifferentTypesOfGraphsOnTheSameThread_Throw.

@Test
public void whenOpeningDifferentTypesOfGraphsOnTheSameThread_Throw() {
    String keyspace = "akeyspacewithkeys";
    GraknSession session = Grakn.session(Grakn.IN_MEMORY, keyspace);
    GraknTx graph = session.open(GraknTxType.READ);
    failAtOpeningTx(session, GraknTxType.WRITE, keyspace);
    failAtOpeningTx(session, GraknTxType.BATCH, keyspace);
    graph.close();
    // noinspection ResultOfMethodCallIgnored
    session.open(GraknTxType.BATCH);
    failAtOpeningTx(session, GraknTxType.WRITE, keyspace);
    failAtOpeningTx(session, GraknTxType.READ, keyspace);
}
Also used : GraknTx(ai.grakn.GraknTx) GraknSession(ai.grakn.GraknSession) EmbeddedGraknSession(ai.grakn.factory.EmbeddedGraknSession) Test(org.junit.Test)

Example 12 with GraknSession

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

the class AttributeTypeTest method whenCreatingAResourceTypeOfTypeDate_EnsureTheTimeZoneIsSetTOADefaultAndDoesNotAffectRetreival.

@Test
public void whenCreatingAResourceTypeOfTypeDate_EnsureTheTimeZoneIsSetTOADefaultAndDoesNotAffectRetreival() {
    // offset the time to GMT-8
    TimeZone.setDefault(TimeZone.getTimeZone("GMT-8"));
    // get the local time (without timezone)
    LocalDateTime rightNow = LocalDateTime.now();
    // now add the timezone to the graph
    try (GraknSession session = Grakn.session(Grakn.IN_MEMORY, "somethingmorerandom")) {
        try (GraknTx graph = session.open(GraknTxType.WRITE)) {
            AttributeType<LocalDateTime> aTime = graph.putAttributeType("aTime", AttributeType.DataType.DATE);
            aTime.putAttribute(rightNow);
            graph.commit();
        }
    }
    // offset the time to GMT where the colleague is working
    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
    // the colleague extracts the LocalTime which should be the same
    try (GraknSession session = Grakn.session(Grakn.IN_MEMORY, "somethingmorerandom")) {
        try (GraknTx graph = session.open(GraknTxType.WRITE)) {
            AttributeType aTime = graph.getAttributeType("aTime");
            LocalDateTime databaseTime = (LocalDateTime) ((Attribute) aTime.instances().iterator().next()).getValue();
            // localTime should not have changed as it should not be sensitive to timezone
            assertEquals(rightNow, databaseTime);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) GraknTx(ai.grakn.GraknTx) AttributeType(ai.grakn.concept.AttributeType) GraknSession(ai.grakn.GraknSession) Test(org.junit.Test)

Example 13 with GraknSession

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

the class GraknTxs method generate.

@Override
public GraknTx generate() {
    // TODO: Generate more keyspaces
    // We don't do this now because creating lots of keyspaces seems to slow the system tx
    String keyspace = gen().make(MetasyntacticStrings.class).generate(random, status);
    GraknSession factory = Grakn.session(Grakn.IN_MEMORY, keyspace);
    int size = status.size();
    startSummary();
    txSummary.append("size: ").append(size).append("\n");
    closeGraph(lastGeneratedGraph);
    // Clear tx before retrieving
    tx = factory.open(GraknTxType.WRITE);
    tx.admin().delete();
    tx = factory.open(GraknTxType.WRITE);
    for (int i = 0; i < size; i++) {
        mutateOnce();
    }
    // Close graphs randomly, unless parameter is set
    boolean shouldOpen = open != null ? open : random.nextBoolean();
    if (!shouldOpen)
        tx.close();
    setLastGeneratedGraph(tx);
    return tx;
}
Also used : GraknSession(ai.grakn.GraknSession) StringUtil.valueToString(ai.grakn.util.StringUtil.valueToString)

Aggregations

GraknSession (ai.grakn.GraknSession)13 GraknTx (ai.grakn.GraknTx)9 Test (org.junit.Test)9 Keyspace (ai.grakn.Keyspace)3 AttributeType (ai.grakn.concept.AttributeType)3 EntityType (ai.grakn.concept.EntityType)2 RelationshipType (ai.grakn.concept.RelationshipType)2 Role (ai.grakn.concept.Role)2 EmbeddedGraknSession (ai.grakn.factory.EmbeddedGraknSession)2 Var (ai.grakn.graql.Var)2 VarPattern (ai.grakn.graql.VarPattern)2 Grakn (ai.grakn.Grakn)1 GraknSystemProperty (ai.grakn.GraknSystemProperty)1 GraknTxType (ai.grakn.GraknTxType)1 BatchExecutorClient (ai.grakn.client.BatchExecutorClient)1 GraknClient (ai.grakn.client.GraknClient)1 ConceptId (ai.grakn.concept.ConceptId)1 Entity (ai.grakn.concept.Entity)1 GetQuery (ai.grakn.graql.GetQuery)1 Graql (ai.grakn.graql.Graql)1