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