Search in sources :

Example 1 with Options

use of com.vaticle.typedb.core.common.parameters.Options in project grakn by graknlabs.

the class BasicTest method write_different_attributes_in_parallel_successfully.

@Test
public void write_different_attributes_in_parallel_successfully() throws IOException {
    LocalDateTime date_1991_2_3_4_5 = LocalDateTime.of(1991, 2, 3, 4, 5);
    LocalDateTime date_1992_3_4_5_6 = LocalDateTime.of(1992, 3, 4, 5, 6);
    LocalDateTime date_1993_4_5_6_7 = LocalDateTime.of(1993, 4, 5, 6, 7);
    reset_directory_and_create_attribute_types();
    try (TypeDB.DatabaseManager typedb = CoreDatabaseManager.open(options)) {
        try (TypeDB.Session session = typedb.session(database, Arguments.Session.Type.DATA)) {
            TypeDB.Transaction txn1 = session.transaction(Arguments.Transaction.Type.WRITE);
            TypeDB.Transaction txn2 = session.transaction(Arguments.Transaction.Type.WRITE);
            TypeDB.Transaction txn3 = session.transaction(Arguments.Transaction.Type.WRITE);
            isAlive(txn1).put(true);
            isAlive(txn2).put(false);
            age(txn1).put(17);
            age(txn2).put(18);
            age(txn3).put(19);
            score(txn1).put(70.5);
            score(txn2).put(80.6);
            score(txn3).put(90.7);
            name(txn1).put("alice");
            name(txn2).put("bob");
            name(txn3).put("charlie");
            dob(txn1).put(date_1991_2_3_4_5);
            dob(txn2).put(date_1992_3_4_5_6);
            dob(txn3).put(date_1993_4_5_6_7);
            assertEquals(1, isAlive(txn1).getInstances().count());
            assertTrue(isAlive(txn1).getInstances().anyMatch(att -> att.getValue().equals(true)));
            assertEquals(1, isAlive(txn2).getInstances().count());
            assertTrue(isAlive(txn2).getInstances().anyMatch(att -> att.getValue().equals(false)));
            assertEquals(1, age(txn1).getInstances().count());
            assertTrue(age(txn1).getInstances().anyMatch(att -> att.getValue() == 17));
            assertEquals(1, age(txn2).getInstances().count());
            assertTrue(age(txn2).getInstances().anyMatch(att -> att.getValue() == 18));
            assertEquals(1, age(txn3).getInstances().count());
            assertTrue(age(txn3).getInstances().anyMatch(att -> att.getValue() == 19));
            assertEquals(1, score(txn1).getInstances().count());
            assertTrue(score(txn1).getInstances().anyMatch(att -> att.getValue() == 70.5));
            assertEquals(1, score(txn2).getInstances().count());
            assertTrue(score(txn2).getInstances().anyMatch(att -> att.getValue() == 80.6));
            assertEquals(1, score(txn3).getInstances().count());
            assertTrue(score(txn3).getInstances().anyMatch(att -> att.getValue() == 90.7));
            assertEquals(1, name(txn1).getInstances().count());
            assertTrue(name(txn1).getInstances().anyMatch(att -> att.getValue().equals("alice")));
            assertEquals(1, name(txn2).getInstances().count());
            assertTrue(name(txn2).getInstances().anyMatch(att -> att.getValue().equals("bob")));
            assertEquals(1, name(txn3).getInstances().count());
            assertTrue(name(txn3).getInstances().anyMatch(att -> att.getValue().equals("charlie")));
            assertEquals(1, dob(txn1).getInstances().count());
            assertTrue(dob(txn1).getInstances().anyMatch(att -> att.getValue().equals(date_1991_2_3_4_5)));
            assertEquals(1, dob(txn2).getInstances().count());
            assertTrue(dob(txn2).getInstances().anyMatch(att -> att.getValue().equals(date_1992_3_4_5_6)));
            assertEquals(1, dob(txn3).getInstances().count());
            assertTrue(dob(txn3).getInstances().anyMatch(att -> att.getValue().equals(date_1993_4_5_6_7)));
            txn1.commit();
            txn2.commit();
            txn3.commit();
            try (TypeDB.Transaction txn = session.transaction(Arguments.Transaction.Type.READ)) {
                LocalDateTime d1 = LocalDateTime.of(1991, 2, 3, 4, 5);
                LocalDateTime d2 = LocalDateTime.of(1992, 3, 4, 5, 6);
                LocalDateTime d3 = LocalDateTime.of(1993, 4, 5, 6, 7);
                assertEquals(true, isAlive(txn).get(true).getValue());
                assertEquals(false, isAlive(txn).get(false).getValue());
                assertEquals(17, age(txn).get(17).getValue().longValue());
                assertEquals(18, age(txn).get(18).getValue().longValue());
                assertEquals(19, age(txn).get(19).getValue().longValue());
                assertEquals(70.5, score(txn).get(70.5).getValue(), 0.001);
                assertEquals(80.6, score(txn).get(80.6).getValue(), 0.001);
                assertEquals(90.7, score(txn).get(90.7).getValue(), 0.001);
                assertEquals("alice", name(txn).get("alice").getValue());
                assertEquals("bob", name(txn).get("bob").getValue());
                assertEquals("charlie", name(txn).get("charlie").getValue());
                assertEquals(d1, dob(txn).get(d1).getValue());
                assertEquals(d2, dob(txn).get(d2).getValue());
                assertEquals(d3, dob(txn).get(d3).getValue());
                assertEquals(2, isAlive(txn).getInstances().count());
                assertTrue(isAlive(txn).getInstances().anyMatch(att -> att.getValue().equals(true)));
                assertTrue(isAlive(txn).getInstances().anyMatch(att -> att.getValue().equals(false)));
                assertEquals(3, age(txn).getInstances().count());
                assertTrue(age(txn).getInstances().anyMatch(att -> att.getValue() == 17));
                assertTrue(age(txn).getInstances().anyMatch(att -> att.getValue() == 18));
                assertTrue(age(txn).getInstances().anyMatch(att -> att.getValue() == 19));
                assertEquals(3, score(txn).getInstances().count());
                assertTrue(score(txn).getInstances().anyMatch(att -> att.getValue() == 70.5));
                assertTrue(score(txn).getInstances().anyMatch(att -> att.getValue() == 80.6));
                assertTrue(score(txn).getInstances().anyMatch(att -> att.getValue() == 90.7));
                assertEquals(3, name(txn).getInstances().count());
                assertTrue(name(txn).getInstances().anyMatch(att -> att.getValue().equals("alice")));
                assertTrue(name(txn).getInstances().anyMatch(att -> att.getValue().equals("bob")));
                assertTrue(name(txn).getInstances().anyMatch(att -> att.getValue().equals("charlie")));
                assertEquals(3, dob(txn).getInstances().count());
                assertTrue(dob(txn).getInstances().anyMatch(att -> att.getValue().equals(date_1991_2_3_4_5)));
                assertTrue(dob(txn).getInstances().anyMatch(att -> att.getValue().equals(date_1992_3_4_5_6)));
                assertTrue(dob(txn).getInstances().anyMatch(att -> att.getValue().equals(date_1993_4_5_6_7)));
            }
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) LocalDateTime(java.time.LocalDateTime) MB(com.vaticle.typedb.core.common.collection.Bytes.MB) Util.assertNotNulls(com.vaticle.typedb.core.test.integration.util.Util.assertNotNulls) RelationType(com.vaticle.typedb.core.concept.type.RelationType) LONG(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.LONG) Arguments(com.vaticle.typedb.core.common.parameters.Arguments) LogicManager(com.vaticle.typedb.core.logic.LogicManager) Rule(com.vaticle.typedb.core.logic.Rule) STRING(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.STRING) ThingType(com.vaticle.typedb.core.concept.type.ThingType) Assert.fail(org.junit.Assert.fail) Path(java.nio.file.Path) TypeQL(com.vaticle.typeql.lang.TypeQL) CoreDatabaseManager(com.vaticle.typedb.core.database.CoreDatabaseManager) Options(com.vaticle.typedb.core.common.parameters.Options) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Pattern(com.vaticle.typeql.lang.pattern.Pattern) RoleType(com.vaticle.typedb.core.concept.type.RoleType) Consumer(java.util.function.Consumer) TypeDB(com.vaticle.typedb.core.TypeDB) ThingVariable(com.vaticle.typeql.lang.pattern.variable.ThingVariable) Stream(java.util.stream.Stream) Assert.assertNull(org.junit.Assert.assertNull) DATETIME(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DATETIME) Paths(java.nio.file.Paths) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) DOUBLE(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DOUBLE) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) EntityType(com.vaticle.typedb.core.concept.type.EntityType) BOOLEAN(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.BOOLEAN) Assert.assertEquals(org.junit.Assert.assertEquals) Util(com.vaticle.typedb.core.test.integration.util.Util) TypeDB(com.vaticle.typedb.core.TypeDB) Test(org.junit.Test)

Example 2 with Options

use of com.vaticle.typedb.core.common.parameters.Options in project grakn by graknlabs.

the class DatabaseTest method incompatibleDataEncodingThrows.

@Test
public void incompatibleDataEncodingThrows() {
    Path dataDir = Paths.get("test/integration/database/data");
    Path logDir = dataDir.resolve("logs");
    Options.Database options = new Options.Database().dataDir(dataDir).reasonerDebuggerDir(logDir).storageIndexCacheSize(MB).storageDataCacheSize(MB);
    assertThrowsWithMessage(() -> factory.databaseManager(options), INCOMPATIBLE_ENCODING.message("test", 0, Encoding.ENCODING_VERSION));
}
Also used : Path(java.nio.file.Path) Options(com.vaticle.typedb.core.common.parameters.Options) Test(org.junit.Test)

Example 3 with Options

use of com.vaticle.typedb.core.common.parameters.Options in project grakn by graknlabs.

the class TypeDBService method sessionOpen.

@Override
public void sessionOpen(SessionProto.Session.Open.Req request, StreamObserver<SessionProto.Session.Open.Res> responder) {
    try {
        Instant start = Instant.now();
        Arguments.Session.Type sessionType = Arguments.Session.Type.of(request.getType().getNumber());
        Options.Session options = applyDefaultOptions(new Options.Session(), request.getOptions());
        TypeDB.Session session = databaseMgr.session(request.getDatabase(), sessionType, options);
        SessionService sessionSvc = new SessionService(this, session, options);
        sessionServices.put(sessionSvc.UUID(), sessionSvc);
        int duration = (int) Duration.between(start, Instant.now()).toMillis();
        responder.onNext(openRes(sessionSvc.UUID(), duration));
        responder.onCompleted();
    } catch (RuntimeException e) {
        LOG.error(e.getMessage(), e);
        responder.onError(exception(e));
    }
}
Also used : RequestReader.applyDefaultOptions(com.vaticle.typedb.core.server.common.RequestReader.applyDefaultOptions) Options(com.vaticle.typedb.core.common.parameters.Options) Instant(java.time.Instant) TypeDB(com.vaticle.typedb.core.TypeDB)

Example 4 with Options

use of com.vaticle.typedb.core.common.parameters.Options in project grakn by graknlabs.

the class QueryService method execute.

public void execute(TransactionProto.Transaction.Req req) {
    try (FactoryTracingThreadStatic.ThreadTrace ignored = traceOnThread("query")) {
        QueryProto.QueryManager.Req queryReq = req.getQueryManagerReq();
        Options.Query options = new Options.Query();
        applyDefaultOptions(options, queryReq.getOptions());
        applyQueryOptions(options, queryReq.getOptions());
        UUID reqID = byteStringAsUUID(req.getReqId());
        switch(queryReq.getReqCase()) {
            case DEFINE_REQ:
                this.define(queryReq.getDefineReq().getQuery(), options, reqID);
                return;
            case UNDEFINE_REQ:
                this.undefine(queryReq.getUndefineReq().getQuery(), options, reqID);
                return;
            case MATCH_REQ:
                this.match(queryReq.getMatchReq().getQuery(), options, reqID);
                return;
            case MATCH_AGGREGATE_REQ:
                this.matchAggregate(queryReq.getMatchAggregateReq().getQuery(), options, reqID);
                return;
            case MATCH_GROUP_REQ:
                this.matchGroup(queryReq.getMatchGroupReq().getQuery(), options, reqID);
                return;
            case MATCH_GROUP_AGGREGATE_REQ:
                this.matchGroupAggregate(queryReq.getMatchGroupAggregateReq().getQuery(), options, reqID);
                return;
            case INSERT_REQ:
                this.insert(queryReq.getInsertReq().getQuery(), options, reqID);
                return;
            case DELETE_REQ:
                this.delete(queryReq.getDeleteReq().getQuery(), options, reqID);
                return;
            case UPDATE_REQ:
                this.update(queryReq.getUpdateReq().getQuery(), options, reqID);
                return;
            case EXPLAIN_REQ:
                this.explain(queryReq.getExplainReq().getExplainableId(), reqID);
                return;
            case REQ_NOT_SET:
            default:
                throw TypeDBException.of(UNKNOWN_REQUEST_TYPE);
        }
    }
}
Also used : RequestReader.applyQueryOptions(com.vaticle.typedb.core.server.common.RequestReader.applyQueryOptions) RequestReader.applyDefaultOptions(com.vaticle.typedb.core.server.common.RequestReader.applyDefaultOptions) Options(com.vaticle.typedb.core.common.parameters.Options) FactoryTracingThreadStatic(com.vaticle.factory.tracing.client.FactoryTracingThreadStatic) QueryManager(com.vaticle.typedb.core.query.QueryManager) RequestReader.byteStringAsUUID(com.vaticle.typedb.core.server.common.RequestReader.byteStringAsUUID) UUID(java.util.UUID)

Example 5 with Options

use of com.vaticle.typedb.core.common.parameters.Options in project grakn by graknlabs.

the class BasicTest method write_identical_attributes_in_parallel_successfully.

@Test
public void write_identical_attributes_in_parallel_successfully() throws IOException {
    reset_directory_and_create_attribute_types();
    LocalDateTime date_1992_2_3_4_5 = LocalDateTime.of(1991, 2, 3, 4, 5);
    try (TypeDB.DatabaseManager typedb = CoreDatabaseManager.open(options)) {
        try (TypeDB.Session session = typedb.session(database, Arguments.Session.Type.DATA)) {
            TypeDB.Transaction txn1 = session.transaction(Arguments.Transaction.Type.WRITE);
            TypeDB.Transaction txn2 = session.transaction(Arguments.Transaction.Type.WRITE);
            TypeDB.Transaction txn3 = session.transaction(Arguments.Transaction.Type.WRITE);
            isAlive(txn1).put(true);
            isAlive(txn2).put(true);
            isAlive(txn3).put(true);
            age(txn1).put(17);
            age(txn2).put(17);
            age(txn3).put(17);
            score(txn1).put(70.5);
            score(txn2).put(70.5);
            score(txn3).put(70.5);
            name(txn1).put("alice");
            name(txn2).put("alice");
            name(txn3).put("alice");
            dob(txn1).put(date_1992_2_3_4_5);
            dob(txn2).put(date_1992_2_3_4_5);
            dob(txn3).put(date_1992_2_3_4_5);
            assertEquals(1, isAlive(txn1).getInstances().count());
            assertTrue(isAlive(txn1).getInstances().anyMatch(att -> att.getValue().equals(true)));
            assertEquals(1, isAlive(txn2).getInstances().count());
            assertTrue(isAlive(txn2).getInstances().anyMatch(att -> att.getValue().equals(true)));
            assertEquals(1, isAlive(txn3).getInstances().count());
            assertTrue(isAlive(txn2).getInstances().anyMatch(att -> att.getValue().equals(true)));
            assertEquals(1, age(txn1).getInstances().count());
            assertTrue(age(txn1).getInstances().anyMatch(att -> att.getValue() == 17));
            assertEquals(1, age(txn2).getInstances().count());
            assertTrue(age(txn2).getInstances().anyMatch(att -> att.getValue() == 17));
            assertEquals(1, age(txn3).getInstances().count());
            assertTrue(age(txn3).getInstances().anyMatch(att -> att.getValue() == 17));
            assertEquals(1, score(txn1).getInstances().count());
            assertTrue(score(txn1).getInstances().anyMatch(att -> att.getValue() == 70.5));
            assertEquals(1, score(txn2).getInstances().count());
            assertTrue(score(txn2).getInstances().anyMatch(att -> att.getValue() == 70.5));
            assertEquals(1, score(txn3).getInstances().count());
            assertTrue(score(txn3).getInstances().anyMatch(att -> att.getValue() == 70.5));
            assertEquals(1, name(txn1).getInstances().count());
            assertTrue(name(txn1).getInstances().anyMatch(att -> att.getValue().equals("alice")));
            assertEquals(1, name(txn2).getInstances().count());
            assertTrue(name(txn2).getInstances().anyMatch(att -> att.getValue().equals("alice")));
            assertEquals(1, name(txn3).getInstances().count());
            assertTrue(name(txn3).getInstances().anyMatch(att -> att.getValue().equals("alice")));
            assertEquals(1, dob(txn1).getInstances().count());
            assertTrue(dob(txn1).getInstances().anyMatch(att -> att.getValue().equals(date_1992_2_3_4_5)));
            assertEquals(1, dob(txn2).getInstances().count());
            assertTrue(dob(txn2).getInstances().anyMatch(att -> att.getValue().equals(date_1992_2_3_4_5)));
            assertEquals(1, dob(txn3).getInstances().count());
            assertTrue(dob(txn3).getInstances().anyMatch(att -> att.getValue().equals(date_1992_2_3_4_5)));
            txn1.commit();
            txn2.commit();
            txn3.commit();
            try (TypeDB.Transaction txn = session.transaction(Arguments.Transaction.Type.READ)) {
                assertEquals(true, isAlive(txn).get(true).getValue());
                assertEquals(17, age(txn).get(17).getValue().longValue());
                assertEquals(70.5, score(txn).get(70.5).getValue(), 0.001);
                assertEquals("alice", name(txn).get("alice").getValue());
                assertEquals(date_1992_2_3_4_5, dob(txn).get(date_1992_2_3_4_5).getValue());
                assertEquals(1, isAlive(txn).getInstances().count());
                assertTrue(isAlive(txn).getInstances().anyMatch(att -> att.getValue().equals(true)));
                assertEquals(1, age(txn).getInstances().count());
                assertTrue(age(txn).getInstances().anyMatch(att -> att.getValue() == 17));
                assertEquals(1, score(txn).getInstances().count());
                assertTrue(score(txn).getInstances().anyMatch(att -> att.getValue() == 70.5));
                assertEquals(1, name(txn).getInstances().count());
                assertTrue(name(txn).getInstances().anyMatch(att -> att.getValue().equals("alice")));
                assertEquals(1, dob(txn).getInstances().count());
                assertTrue(dob(txn).getInstances().anyMatch(att -> att.getValue().equals(date_1992_2_3_4_5)));
            }
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ConceptManager(com.vaticle.typedb.core.concept.ConceptManager) LocalDateTime(java.time.LocalDateTime) MB(com.vaticle.typedb.core.common.collection.Bytes.MB) Util.assertNotNulls(com.vaticle.typedb.core.test.integration.util.Util.assertNotNulls) RelationType(com.vaticle.typedb.core.concept.type.RelationType) LONG(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.LONG) Arguments(com.vaticle.typedb.core.common.parameters.Arguments) LogicManager(com.vaticle.typedb.core.logic.LogicManager) Rule(com.vaticle.typedb.core.logic.Rule) STRING(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.STRING) ThingType(com.vaticle.typedb.core.concept.type.ThingType) Assert.fail(org.junit.Assert.fail) Path(java.nio.file.Path) TypeQL(com.vaticle.typeql.lang.TypeQL) CoreDatabaseManager(com.vaticle.typedb.core.database.CoreDatabaseManager) Options(com.vaticle.typedb.core.common.parameters.Options) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Pattern(com.vaticle.typeql.lang.pattern.Pattern) RoleType(com.vaticle.typedb.core.concept.type.RoleType) Consumer(java.util.function.Consumer) TypeDB(com.vaticle.typedb.core.TypeDB) ThingVariable(com.vaticle.typeql.lang.pattern.variable.ThingVariable) Stream(java.util.stream.Stream) Assert.assertNull(org.junit.Assert.assertNull) DATETIME(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DATETIME) Paths(java.nio.file.Paths) Attribute(com.vaticle.typedb.core.concept.thing.Attribute) DOUBLE(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DOUBLE) TypeDBException(com.vaticle.typedb.core.common.exception.TypeDBException) AttributeType(com.vaticle.typedb.core.concept.type.AttributeType) EntityType(com.vaticle.typedb.core.concept.type.EntityType) BOOLEAN(com.vaticle.typedb.core.concept.type.AttributeType.ValueType.BOOLEAN) Assert.assertEquals(org.junit.Assert.assertEquals) Util(com.vaticle.typedb.core.test.integration.util.Util) TypeDB(com.vaticle.typedb.core.TypeDB) Test(org.junit.Test)

Aggregations

Options (com.vaticle.typedb.core.common.parameters.Options)7 Path (java.nio.file.Path)5 Test (org.junit.Test)5 TypeDB (com.vaticle.typedb.core.TypeDB)4 MB (com.vaticle.typedb.core.common.collection.Bytes.MB)3 TypeDBException (com.vaticle.typedb.core.common.exception.TypeDBException)3 Arguments (com.vaticle.typedb.core.common.parameters.Arguments)3 ConceptManager (com.vaticle.typedb.core.concept.ConceptManager)3 Attribute (com.vaticle.typedb.core.concept.thing.Attribute)3 AttributeType (com.vaticle.typedb.core.concept.type.AttributeType)3 BOOLEAN (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.BOOLEAN)3 DATETIME (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DATETIME)3 DOUBLE (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.DOUBLE)3 LONG (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.LONG)3 STRING (com.vaticle.typedb.core.concept.type.AttributeType.ValueType.STRING)3 EntityType (com.vaticle.typedb.core.concept.type.EntityType)3 RelationType (com.vaticle.typedb.core.concept.type.RelationType)3 RoleType (com.vaticle.typedb.core.concept.type.RoleType)3 ThingType (com.vaticle.typedb.core.concept.type.ThingType)3 CoreDatabaseManager (com.vaticle.typedb.core.database.CoreDatabaseManager)3