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