Search in sources :

Example 81 with RecordCoreException

use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.

the class ProbableIntersectionCursorTest method errorAndLimitInChild.

@Test
public void errorAndLimitInChild() {
    CompletableFuture<Integer> future = new CompletableFuture<>();
    RecordCursor<Integer> cursor = ProbableIntersectionCursor.create(Collections::singletonList, Arrays.asList(continuation -> RecordCursor.fromList(Arrays.asList(1, 2), continuation).limitRowsTo(1), continuation -> RecordCursor.fromFuture(future)), null, null);
    CompletableFuture<RecordCursorResult<Integer>> cursorResultFuture = cursor.onNext();
    final RecordCoreException ex = new RecordCoreException("something bad happened!");
    future.completeExceptionally(ex);
    ExecutionException executionException = assertThrows(ExecutionException.class, cursorResultFuture::get);
    assertNotNull(executionException.getCause());
    assertSame(ex, executionException.getCause());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) RowLimitedCursor(com.apple.foundationdb.record.cursors.RowLimitedCursor) LoggerFactory(org.slf4j.LoggerFactory) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) Function(java.util.function.Function) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) TestLogMessageKeys(com.apple.foundationdb.record.logging.TestLogMessageKeys) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FirableCursor(com.apple.foundationdb.record.cursors.FirableCursor) Matchers.lessThan(org.hamcrest.Matchers.lessThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) BloomFilter(com.google.common.hash.BloomFilter) Set(java.util.Set) Collectors(java.util.stream.Collectors) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Stream(java.util.stream.Stream) RecordCursorProto(com.apple.foundationdb.record.RecordCursorProto) RecordCursor(com.apple.foundationdb.record.RecordCursor) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) CompletableFuture(java.util.concurrent.CompletableFuture) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) Collections(java.util.Collections) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest)

Example 82 with RecordCoreException

use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.

the class ProbableIntersectionCursorTest method errorInChild.

@Test
public void errorInChild() {
    CompletableFuture<Integer> future = new CompletableFuture<>();
    RecordCursor<Integer> cursor = ProbableIntersectionCursor.create(Collections::singletonList, Arrays.asList(continuation -> RecordCursor.fromList(Arrays.asList(1, 2), continuation), continuation -> RecordCursor.fromFuture(future)), null, null);
    CompletableFuture<RecordCursorResult<Integer>> cursorResultFuture = cursor.onNext();
    final RecordCoreException ex = new RecordCoreException("something bad happened!");
    future.completeExceptionally(ex);
    ExecutionException executionException = assertThrows(ExecutionException.class, cursorResultFuture::get);
    assertNotNull(executionException.getCause());
    assertSame(ex, executionException.getCause());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IntStream(java.util.stream.IntStream) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) RowLimitedCursor(com.apple.foundationdb.record.cursors.RowLimitedCursor) LoggerFactory(org.slf4j.LoggerFactory) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Random(java.util.Random) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncUtil(com.apple.foundationdb.async.AsyncUtil) Function(java.util.function.Function) Iterators(com.google.common.collect.Iterators) HashSet(java.util.HashSet) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) KeyValueLogMessage(com.apple.foundationdb.record.logging.KeyValueLogMessage) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) TestLogMessageKeys(com.apple.foundationdb.record.logging.TestLogMessageKeys) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FirableCursor(com.apple.foundationdb.record.cursors.FirableCursor) Matchers.lessThan(org.hamcrest.Matchers.lessThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) BloomFilter(com.google.common.hash.BloomFilter) Set(java.util.Set) Collectors(java.util.stream.Collectors) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) List(java.util.List) Stream(java.util.stream.Stream) RecordCursorProto(com.apple.foundationdb.record.RecordCursorProto) RecordCursor(com.apple.foundationdb.record.RecordCursor) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) CompletableFuture(java.util.concurrent.CompletableFuture) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) Collections(java.util.Collections) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest)

Example 83 with RecordCoreException

use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.

the class UnorderedUnionCursorTest method errorAndLimitInChild.

@Test
public void errorAndLimitInChild() {
    CompletableFuture<Integer> future = new CompletableFuture<>();
    RecordCursor<Integer> cursor = UnorderedUnionCursor.create(Arrays.asList(continuation -> RecordCursor.fromList(Arrays.asList(1, 2), continuation).limitRowsTo(1), continuation -> RecordCursor.fromFuture(future)), null, null);
    RecordCursorResult<Integer> cursorResult = cursor.getNext();
    assertEquals(1, (int) cursorResult.get());
    CompletableFuture<RecordCursorResult<Integer>> cursorResultFuture = cursor.onNext();
    final RecordCoreException ex = new RecordCoreException("something bad happened!");
    future.completeExceptionally(ex);
    ExecutionException executionException = assertThrows(ExecutionException.class, cursorResultFuture::get);
    assertNotNull(executionException.getCause());
    assertSame(ex, executionException.getCause());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) FDBTestBase(com.apple.foundationdb.record.provider.foundationdb.FDBTestBase) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) FirableCursor(com.apple.foundationdb.record.cursors.FirableCursor) RecordCursorIterator(com.apple.foundationdb.record.RecordCursorIterator) Tag(org.junit.jupiter.api.Tag) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) ValueSource(org.junit.jupiter.params.provider.ValueSource) Iterator(java.util.Iterator) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Tags(com.apple.test.Tags) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Collectors(java.util.stream.Collectors) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) RecordCursor(com.apple.foundationdb.record.RecordCursor) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) CompletableFuture(java.util.concurrent.CompletableFuture) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest)

Example 84 with RecordCoreException

use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.

the class UnorderedUnionCursorTest method errorInChild.

@Test
public void errorInChild() {
    CompletableFuture<Integer> future = new CompletableFuture<>();
    RecordCursor<Integer> cursor = UnorderedUnionCursor.create(Arrays.asList(continuation -> RecordCursor.fromList(Arrays.asList(1, 2), continuation), continuation -> RecordCursor.fromFuture(future)), null, null);
    RecordCursorResult<Integer> cursorResult = cursor.getNext();
    assertEquals(1, (int) cursorResult.get());
    cursorResult = cursor.getNext();
    assertEquals(2, (int) cursorResult.get());
    CompletableFuture<RecordCursorResult<Integer>> cursorResultFuture = cursor.onNext();
    final RecordCoreException ex = new RecordCoreException("something bad happened!");
    future.completeExceptionally(ex);
    ExecutionException executionException = assertThrows(ExecutionException.class, cursorResultFuture::get);
    assertNotNull(executionException.getCause());
    assertSame(ex, executionException.getCause());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) CompletableFuture(java.util.concurrent.CompletableFuture) Function(java.util.function.Function) FDBTestBase(com.apple.foundationdb.record.provider.foundationdb.FDBTestBase) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) FirableCursor(com.apple.foundationdb.record.cursors.FirableCursor) RecordCursorIterator(com.apple.foundationdb.record.RecordCursorIterator) Tag(org.junit.jupiter.api.Tag) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Nonnull(javax.annotation.Nonnull) ValueSource(org.junit.jupiter.params.provider.ValueSource) Iterator(java.util.Iterator) FDBStoreTimer(com.apple.foundationdb.record.provider.foundationdb.FDBStoreTimer) Tags(com.apple.test.Tags) Matchers.lessThanOrEqualTo(org.hamcrest.Matchers.lessThanOrEqualTo) Collectors(java.util.stream.Collectors) Assertions.assertSame(org.junit.jupiter.api.Assertions.assertSame) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) RecordCursor(com.apple.foundationdb.record.RecordCursor) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) RecordCoreException(com.apple.foundationdb.record.RecordCoreException) CompletableFuture(java.util.concurrent.CompletableFuture) RecordCursorResult(com.apple.foundationdb.record.RecordCursorResult) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) RecordCursorTest(com.apple.foundationdb.record.RecordCursorTest)

Example 85 with RecordCoreException

use of com.apple.foundationdb.record.RecordCoreException in project fdb-record-layer by FoundationDB.

the class StringInterningLayerTest method testCreate.

@Test
void testCreate() {
    try (FDBRecordContext context = database.openContext()) {
        StringInterningLayer interningLayer = new StringInterningLayer(testSubspace);
        String toIntern = "some-string";
        byte[] metadata = Tuple.from("some-metadata").pack();
        ResolverResult interned = interningLayer.create(context, toIntern, metadata).join();
        assertArrayEquals(interned.getMetadata(), metadata, "we see the metadata with the interned value");
        Optional<ResolverResult> maybeRead = interningLayer.read(context, toIntern).join();
        assertIsPresentWithValue("we read the value", maybeRead, interned);
        Optional<String> maybeReverseRead = interningLayer.readReverse(context, interned.getValue()).join();
        assertIsPresentWithValue("the reverse lookup works", maybeReverseRead, toIntern);
        try {
            interningLayer.create(context, toIntern, null).join();
            fail("should throw exception");
        } catch (CompletionException ex) {
            assertThat(ex.getCause(), is(instanceOf(RecordCoreException.class)));
            assertThat(ex.getCause().getMessage(), containsString("value already exists in interning layer"));
            RecordCoreException cause = (RecordCoreException) ex.getCause();
            assertThat("exception log info has the key", cause.getLogInfo(), hasEntry("value", toIntern));
        }
    }
}
Also used : RecordCoreException(com.apple.foundationdb.record.RecordCoreException) FDBRecordContext(com.apple.foundationdb.record.provider.foundationdb.FDBRecordContext) CompletionException(java.util.concurrent.CompletionException) ResolverResult(com.apple.foundationdb.record.provider.foundationdb.keyspace.ResolverResult) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

RecordCoreException (com.apple.foundationdb.record.RecordCoreException)121 Nonnull (javax.annotation.Nonnull)58 Test (org.junit.jupiter.api.Test)42 Index (com.apple.foundationdb.record.metadata.Index)37 List (java.util.List)35 Nullable (javax.annotation.Nullable)31 Tuple (com.apple.foundationdb.tuple.Tuple)29 ArrayList (java.util.ArrayList)27 KeyExpression (com.apple.foundationdb.record.metadata.expressions.KeyExpression)26 CompletableFuture (java.util.concurrent.CompletableFuture)25 Collectors (java.util.stream.Collectors)24 Collections (java.util.Collections)22 GroupingKeyExpression (com.apple.foundationdb.record.metadata.expressions.GroupingKeyExpression)19 Set (java.util.Set)19 Function (java.util.function.Function)19 IndexEntry (com.apple.foundationdb.record.IndexEntry)17 TupleRange (com.apple.foundationdb.record.TupleRange)17 IndexTypes (com.apple.foundationdb.record.metadata.IndexTypes)17 RecordCursor (com.apple.foundationdb.record.RecordCursor)16 AsyncUtil (com.apple.foundationdb.async.AsyncUtil)15