use of com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory.KeyType in project fdb-record-layer by FoundationDB.
the class KeySpaceDirectoryTest method testValueOfEveryTypeReallyIsEveryType.
// Catch if someone adds a new type to make sure that we account for it in this test harness
@Test
public void testValueOfEveryTypeReallyIsEveryType() {
List<KeyType> keyTypes = Lists.newArrayList(KeyType.values());
Iterator<KeyType> iter = keyTypes.iterator();
while (iter.hasNext()) {
KeyType keyType = iter.next();
for (KeyTypeValue value : valueOfEveryType) {
if (value.keyType == keyType) {
iter.remove();
break;
}
}
}
assertTrue(keyTypes.isEmpty(), "A new type has been added that is not being tested: " + keyTypes);
}
use of com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory.KeyType in project fdb-record-layer by FoundationDB.
the class KeySpaceDirectoryTest method testListAnyValue.
@Test
public void testListAnyValue() throws Exception {
// Create a root directory called "a" with subdirs of every type (no constants for now)
Long rootValue = random.nextLong();
KeySpaceDirectory dirA = new KeySpaceDirectory("a", KeyType.LONG, rootValue);
for (KeyTypeValue kv : valueOfEveryType) {
dirA.addSubdirectory(new KeySpaceDirectory(kv.keyType.toString(), kv.keyType));
}
KeySpace root = new KeySpace(dirA);
final FDBDatabase database = FDBDatabaseFactory.instance().getDatabase();
final Map<KeyType, List<Tuple>> valuesForType = new HashMap<>();
// Create an entry in the keyspace with a row for every type that we support
try (FDBRecordContext context = database.openContext()) {
Transaction tr = context.ensureActive();
for (KeyTypeValue kv : valueOfEveryType) {
List<Tuple> values = new ArrayList<>();
for (int i = 0; i < 5; i++) {
Object value = kv.generator.get();
Tuple tupleValue = Tuple.from(value);
if (!values.contains(tupleValue)) {
values.add(tupleValue);
// final results.
for (int j = 0; j < 5; j++) {
tr.set(Tuple.from(rootValue, value, j).pack(), Tuple.from(i).pack());
}
}
}
valuesForType.put(kv.keyType, values);
}
context.commit();
}
try (FDBRecordContext context = database.openContext()) {
for (KeyTypeValue kv : valueOfEveryType) {
if (kv.keyType != KeyType.NULL) {
List<Tuple> values = valuesForType.get(kv.keyType);
for (Pair<ValueRange<Object>, List<Tuple>> testCase : listRangeTestCases(values)) {
testListRange(testCase.getLeft(), testCase.getRight(), context, root, kv.keyType);
}
}
}
}
}
Aggregations