Search in sources :

Example 36 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class FDBRecordContextTest method setTrIdThroughMethod.

@ParameterizedTest(name = "setTrIdThroughMethod [logged = {0}]")
@BooleanSource
public void setTrIdThroughMethod(boolean logged) {
    for (Pair<String, String> idPair : trIds) {
        final String trId = idPair.getLeft();
        final String expectedId = idPair.getRight();
        try (FDBRecordContext context = fdb.openContext(null, null, null, FDBTransactionPriority.DEFAULT, trId)) {
            if (expectedId != null && logged) {
                context.logTransaction();
            }
            context.ensureActive().getReadVersion().join();
            assertEquals(expectedId, context.getTransactionId());
            assertEquals(logged && expectedId != null, context.isLogged());
            context.commit();
        } catch (RuntimeException e) {
            fail("unable to set id to " + trId, e);
        }
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 37 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class FDBRecordContextTest method setTrIdThroughConfig.

@ParameterizedTest(name = "setTrIdThroughConfig [logged = {0}]")
@BooleanSource
public void setTrIdThroughConfig(boolean logged) {
    for (Pair<String, String> idPair : trIds) {
        final String trId = idPair.getLeft();
        final String expectedId = idPair.getRight();
        final FDBRecordContextConfig config = FDBRecordContextConfig.newBuilder().setTransactionId(trId).setLogTransaction(logged).build();
        try (FDBRecordContext context = fdb.openContext(config)) {
            context.ensureActive().getReadVersion().join();
            assertEquals(expectedId, context.getTransactionId());
            assertEquals(logged && expectedId != null, context.isLogged());
            context.commit();
        }
    }
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 38 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class FDBMetaDataStoreTest method noUnionUpdateRecords.

@ParameterizedTest(name = "noUnionUpdateRecords [repeatSaveOrDoUpdate = {0}]")
@BooleanSource
public void noUnionUpdateRecords(boolean repeatSaveOrDoUpdate) {
    int version;
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        metaDataStore.saveRecordMetaData(TestNoUnionProto.getDescriptor());
        context.commit();
        version = metaDataStore.getRecordMetaData().getVersion();
    }
    // Update records with an evolved proto. A new record type is added earlier in the file.
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertEquals(version, metaDataStore.getRecordMetaData().getVersion());
        if (repeatSaveOrDoUpdate) {
            metaDataStore.updateRecords(TestNoUnionEvolvedProto.getDescriptor());
        } else {
            metaDataStore.saveRecordMetaData(TestNoUnionEvolvedProto.getDescriptor());
        }
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MyOtherRecord"));
        assertEquals("_MySimpleRecord", metaDataStore.getRecordMetaData().getUnionDescriptor().findFieldByNumber(1).getName());
        assertEquals("_MyOtherRecord", metaDataStore.getRecordMetaData().getUnionDescriptor().findFieldByNumber(2).getName());
        assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
        context.commit();
    }
    // Renaming a record type is not allowed
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertEquals(version + 1, metaDataStore.getRecordMetaData().getVersion());
        MetaDataException e;
        if (repeatSaveOrDoUpdate) {
            e = assertThrows(MetaDataException.class, () -> metaDataStore.updateRecords(TestNoUnionEvolvedRenamedRecordTypeProto.getDescriptor()));
        } else {
            e = assertThrows(MetaDataException.class, () -> metaDataStore.saveRecordMetaData(TestNoUnionEvolvedRenamedRecordTypeProto.getDescriptor()));
        }
        assertEquals("Record type MySimpleRecord removed", e.getMessage());
        context.commit();
    }
}
Also used : MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 39 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class FDBMetaDataStoreTest method indexes.

@ParameterizedTest(name = "indexes [indexCounterBasedSubspaceKey = {0}]")
@BooleanSource
public void indexes(final boolean indexCounterBasedSubspaceKey) {
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        RecordMetaDataBuilder builder = RecordMetaData.newBuilder();
        if (indexCounterBasedSubspaceKey) {
            builder.enableCounterBasedSubspaceKeys();
        }
        metaDataStore.saveRecordMetaData(builder.setRecords(TestRecords1Proto.getDescriptor()).getRecordMetaData());
        context.commit();
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
    }
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        metaDataStore.addIndex("MySimpleRecord", "testIndex", "rec_no");
        assertNotNull(metaDataStore.getRecordMetaData().getIndex("testIndex"));
        context.commit();
        assertNotNull(metaDataStore.getRecordMetaData().getIndex("testIndex"));
    }
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertNotNull(metaDataStore.getRecordMetaData().getIndex("testIndex"));
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.addIndex("MySimpleRecord", "testIndex", "rec_no"));
        assertEquals("Index testIndex already defined", e.getMessage());
        metaDataStore.dropIndex("testIndex");
        context.commit();
        e = assertThrows(MetaDataException.class, () -> metaDataStore.getRecordMetaData().getIndex("testIndex"));
        assertEquals("Index testIndex not defined", e.getMessage());
    }
    try (FDBRecordContext context = fdb.openContext()) {
        openMetaDataStore(context);
        assertNotNull(metaDataStore.getRecordMetaData().getRecordType("MySimpleRecord"));
        MetaDataException e = assertThrows(MetaDataException.class, () -> metaDataStore.getRecordMetaData().getIndex("testIndex"));
        assertEquals("Index testIndex not defined", e.getMessage());
        e = assertThrows(MetaDataException.class, () -> metaDataStore.dropIndex("testIndex"));
        assertEquals("No index named testIndex defined", e.getMessage());
        context.commit();
    }
}
Also used : RecordMetaDataBuilder(com.apple.foundationdb.record.RecordMetaDataBuilder) MetaDataException(com.apple.foundationdb.record.metadata.MetaDataException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Example 40 with BooleanSource

use of com.apple.test.BooleanSource in project fdb-record-layer by FoundationDB.

the class FDBRecordStoreByteLimitTest method testHitExhaustedDuringSplit.

@BooleanSource
@ParameterizedTest
public void testHitExhaustedDuringSplit(boolean reverse) throws Exception {
    deleteSimpleRecords();
    // Insert a single large record
    final FDBStoredRecord<Message> createdRecord = saveAndSplitSimpleRecord(1L, Strings.repeat("Z", SplitHelper.SPLIT_RECORD_SIZE + 10), 1);
    try (FDBRecordContext context = openContext()) {
        openSimpleRecordStore(context, TEST_SPLIT_HOOK);
        // Create a limit that will be hit while reading the first record
        ScanProperties properties = new ScanProperties(ExecuteProperties.newBuilder().setScannedBytesLimit(1).setIsolationLevel(IsolationLevel.SERIALIZABLE).build(), reverse);
        final RecordCursor<FDBStoredRecord<Message>> messageCursor = recordStore.scanRecords(null, properties);
        RecordCursorResult<FDBStoredRecord<Message>> result = messageCursor.getNext();
        assertTrue(result.hasNext());
        assertEquals(createdRecord, result.get());
        // Limit hit and also exhausted. Either one is a valid response, but the data should be internally
        // consistent (i.e., it should not return a non-end continuation if the source is exhausted)
        result = messageCursor.getNext();
        assertFalse(result.hasNext());
        if (result.getNoNextReason().isSourceExhausted()) {
            assertTrue(result.getContinuation().isEnd(), "second result should be at the end");
            assertNull(result.getContinuation().toBytes());
        } else {
            assertEquals(RecordCursor.NoNextReason.BYTE_LIMIT_REACHED, result.getNoNextReason());
            assertFalse(result.getContinuation().isEnd());
            assertNotNull(result.getContinuation().toBytes());
        }
    }
}
Also used : Message(com.google.protobuf.Message) FDBStoredRecord(com.apple.foundationdb.record.provider.foundationdb.FDBStoredRecord) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) ScanProperties(com.apple.foundationdb.record.ScanProperties) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) BooleanSource(com.apple.test.BooleanSource)

Aggregations

BooleanSource (com.apple.test.BooleanSource)57 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 RecordQuery (com.apple.foundationdb.record.query.RecordQuery)37 RecordQueryPlan (com.apple.foundationdb.record.query.plan.plans.RecordQueryPlan)37 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)36 FDBQueriedRecord (com.apple.foundationdb.record.provider.foundationdb.FDBQueriedRecord)24 Message (com.google.protobuf.Message)23 QueryComponent (com.apple.foundationdb.record.query.expressions.QueryComponent)14 RecordMetaDataBuilder (com.apple.foundationdb.record.RecordMetaDataBuilder)10 LuceneQueryComponent (com.apple.foundationdb.record.query.expressions.LuceneQueryComponent)10 RecordMetaData (com.apple.foundationdb.record.RecordMetaData)9 CascadesPlanner (com.apple.foundationdb.record.query.plan.temp.CascadesPlanner)9 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)9 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)9 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)9 Test (org.junit.jupiter.api.Test)9 TestRecords1Proto (com.apple.foundationdb.record.TestRecords1Proto)7 RecordCursorIterator (com.apple.foundationdb.record.RecordCursorIterator)6 Index (com.apple.foundationdb.record.metadata.Index)6 Tuple (com.apple.foundationdb.tuple.Tuple)6