Search in sources :

Example 1 with KeyType

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);
}
Also used : KeyType(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory.KeyType) Test(org.junit.jupiter.api.Test)

Example 2 with KeyType

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);
                }
            }
        }
    }
}
Also used : KeyType(com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory.KeyType) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FDBDatabase(com.apple.foundationdb.record.provider.foundationdb.FDBDatabase) ValueRange(com.apple.foundationdb.record.ValueRange) Transaction(com.apple.foundationdb.Transaction) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) Tuple(com.apple.foundationdb.tuple.Tuple) Test(org.junit.jupiter.api.Test)

Aggregations

KeyType (com.apple.foundationdb.record.provider.foundationdb.keyspace.KeySpaceDirectory.KeyType)2 Test (org.junit.jupiter.api.Test)2 Transaction (com.apple.foundationdb.Transaction)1 ValueRange (com.apple.foundationdb.record.ValueRange)1 FDBDatabase (com.apple.foundationdb.record.provider.foundationdb.FDBDatabase)1 FDBRecordContext (com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext)1 Tuple (com.apple.foundationdb.tuple.Tuple)1 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1