segmentstore/server/src/test/java/io/pravega/segmentstore/server/tables/WriterTableProcessorTests.java
/**
     * Tests the {@link WriterTableProcessor#add} method and other general (non-flush) methods.
     */
Tests the  WriterTableProcessor#add method and other general (non-flush) methods.
Tests the WriterTableProcessor#add method and other general ( non - flush ) methods .
@Test
    public void testAdd() throws Exception {
        @Cleanup
        val context = new TestContext();
        Assert.assertFalse("Unexpected value from isClosed.", context.processor.isClosed());
        Assert.assertFalse("Unexpected value from mustFlush.", context.processor.mustFlush());
        Assert.assertEquals("Unexpected LUSN when no data in.", Operation.NO_SEQUENCE_NUMBER, context.processor.getLowestUncommittedSequenceNumber());
        AssertExtensions.assertThrows(
                "add() worked with wrong segment id.",
                () -> context.processor.add(new StreamSegmentAppendOperation(SEGMENT_ID + 1, BufferView.empty(), null)),
                ex -> ex instanceof IllegalArgumentException);
        context.processor.add(generateRandomEntryAppend(0, context));
        Assert.assertFalse("Unexpected value from mustFlush after ignored add().", context.processor.mustFlush());
        Assert.assertEquals("Unexpected LUSN after ignored add().",
                Operation.NO_SEQUENCE_NUMBER, context.processor.getLowestUncommittedSequenceNumber());
        AssertExtensions.assertThrows(
                "add() allowed first append to be after the last indexed offset.",
                () -> context.processor.add(generateRandomEntryAppend(INITIAL_LAST_INDEXED_OFFSET + 1, context)),
                ex -> ex instanceof DataCorruptionException);
        val validAppend = generateRandomEntryAppend(INITIAL_LAST_INDEXED_OFFSET, context);
        context.processor.add(validAppend);
        Assert.assertTrue("Unexpected value from mustFlush after valid add().", context.processor.mustFlush());
        Assert.assertEquals("Unexpected LUSN after valid add().",
                validAppend.getSequenceNumber(), context.processor.getLowestUncommittedSequenceNumber());
        AssertExtensions.assertThrows(
                "add() allowed non-contiguous appends.",
                () -> context.processor.add(generateRandomEntryAppend(validAppend.getLastStreamSegmentOffset() + 1, context)),
                ex -> ex instanceof DataCorruptionException);
        context.metadata.markDeleted();
        Assert.assertFalse("Unexpected value from mustFlush after deletion.", context.processor.mustFlush());
        context.processor.add(generateRandomEntryAppend(validAppend.getLastStreamSegmentOffset(), context));
        Assert.assertEquals("Unexpected LUSN after ignored append due to deletion.",
                validAppend.getSequenceNumber(), context.processor.getLowestUncommittedSequenceNumber());
        context.processor.close();
        Assert.assertTrue("Unexpected value from isClosed after closing.", context.processor.isClosed());
        AssertExtensions.assertThrows(
                "add() worked after closing.",
                () -> context.processor.add(generateRandomEntryAppend(validAppend.getLastStreamSegmentOffset(), context)),
                ex -> ex instanceof ObjectClosedException);
    }
@ Test public void testAdd ( ) throws Exception { @ Cleanup val context = new TestContext ( ) ; Assert . assertFalse ( "Unexpected value from isClosed." , context . processor . isClosed ( ) ) ; Assert . assertFalse ( "Unexpected value from mustFlush." , context . processor . mustFlush ( ) ) ; Assert . assertEquals ( "Unexpected LUSN when no data in." , Operation . NO_SEQUENCE_NUMBER , context . processor . getLowestUncommittedSequenceNumber ( ) ) ; AssertExtensions . assertThrows ( "add() worked with wrong segment id." , ( ) -> context . processor . add ( new StreamSegmentAppendOperation ( SEGMENT_ID + 1 , BufferView . empty ( ) , null ) ) , ex -> ex instanceof IllegalArgumentException ) ; context . processor . add ( generateRandomEntryAppend ( 0 , context ) ) ; Assert . assertFalse ( "Unexpected value from mustFlush after ignored add()." , context . processor . mustFlush ( ) ) ; Assert . assertEquals ( "Unexpected LUSN after ignored add()." , Operation . NO_SEQUENCE_NUMBER , context . processor . getLowestUncommittedSequenceNumber ( ) ) ; AssertExtensions . assertThrows ( "add() allowed first append to be after the last indexed offset." , ( ) -> context . processor . add ( generateRandomEntryAppend ( INITIAL_LAST_INDEXED_OFFSET + 1 , context ) ) , ex -> ex instanceof DataCorruptionException ) ; val validAppend = generateRandomEntryAppend ( INITIAL_LAST_INDEXED_OFFSET , context ) ; context . processor . add ( validAppend ) ; Assert . assertTrue ( "Unexpected value from mustFlush after valid add()." , context . processor . mustFlush ( ) ) ; Assert . assertEquals ( "Unexpected LUSN after valid add()." , validAppend . getSequenceNumber ( ) , context . processor . getLowestUncommittedSequenceNumber ( ) ) ; AssertExtensions . assertThrows ( "add() allowed non-contiguous appends." , ( ) -> context . processor . add ( generateRandomEntryAppend ( validAppend . getLastStreamSegmentOffset ( ) + 1 , context ) ) , ex -> ex instanceof DataCorruptionException ) ; context . metadata . markDeleted ( ) ; Assert . assertFalse ( "Unexpected value from mustFlush after deletion." , context . processor . mustFlush ( ) ) ; context . processor . add ( generateRandomEntryAppend ( validAppend . getLastStreamSegmentOffset ( ) , context ) ) ; Assert . assertEquals ( "Unexpected LUSN after ignored append due to deletion." , validAppend . getSequenceNumber ( ) , context . processor . getLowestUncommittedSequenceNumber ( ) ) ; context . processor . close ( ) ; Assert . assertTrue ( "Unexpected value from isClosed after closing." , context . processor . isClosed ( ) ) ; AssertExtensions . assertThrows ( "add() worked after closing." , ( ) -> context . processor . add ( generateRandomEntryAppend ( validAppend . getLastStreamSegmentOffset ( ) , context ) ) , ex -> ex instanceof ObjectClosedException ) ; }
Tests the {@link WriterTableProcessor#add} method and other general (non-flush) methods.
Tests the { @link WriterTableProcessor#add } method and other general ( non - flush ) methods .
// Mismatched segment ids. // Pre-last indexed offset. // Post-last indexed offset (not allowing gaps) // Non-contiguous appends. // Delete the segment. // Close the processor and verify.