final String sourceSegmentName = "SourceSegment"; @Cleanup val baseStorage = new TestStorage(); @Cleanup val s = new RollingStorage(baseStorage, DEFAULT_ROLLING_POLICY);
final int failAtIndex = 1; @Cleanup val baseStorage = new TestStorage(); @Cleanup val s = new RollingStorage(baseStorage, DEFAULT_ROLLING_POLICY); baseStorage.delete(baseStorage.openRead(failOnDelete)); s.delete(writeHandle); Assert.assertFalse("Expecting the segment to be deleted.", s.exists(SEGMENT_NAME));
val baseStorage = new TestStorage(); @Cleanup val s = new RollingStorage(baseStorage, DEFAULT_ROLLING_POLICY);
val baseStorage = new TestStorage(); @Cleanup val s = new RollingStorage(baseStorage, DEFAULT_ROLLING_POLICY);
/** * Tests the case when Create was interrupted after it created the Header file but before populating it. */ @Test public void testCreateRecovery() throws Exception { @Cleanup val baseStorage = new TestStorage(); @Cleanup val s = new RollingStorage(baseStorage, DEFAULT_ROLLING_POLICY); s.initialize(1); // Create an empty header file. This simulates a create() operation that failed mid-way. baseStorage.create(StreamSegmentNameUtils.getHeaderSegmentName(SEGMENT_NAME)); Assert.assertFalse("Not expecting Segment to exist.", s.exists(SEGMENT_NAME)); AssertExtensions.assertThrows( "Not expecting Segment to exist (getStreamSegmentInfo).", () -> s.getStreamSegmentInfo(SEGMENT_NAME), ex -> ex instanceof StreamSegmentNotExistsException); AssertExtensions.assertThrows( "Not expecting Segment to exist (openHandle).", () -> s.openRead(SEGMENT_NAME), ex -> ex instanceof StreamSegmentNotExistsException); // Retry the operation and verify everything is in place. s.create(SEGMENT_NAME); val si = s.getStreamSegmentInfo(SEGMENT_NAME); Assert.assertEquals("Expected the Segment to have been created.", 0, si.getLength()); }
/** * Tests the ability to truncate Sealed Segments. */ @Test public void testTruncateSealed() throws Exception { // Write small and large writes, alternatively. @Cleanup val baseStorage = new TestStorage(); @Cleanup val s = new RollingStorage(baseStorage, DEFAULT_ROLLING_POLICY); s.initialize(1); // Create a Segment, write some data, then seal it. s.create(SEGMENT_NAME); val appendHandle = (RollingSegmentHandle) s.openWrite(SEGMENT_NAME); val writeStream = new ByteArrayOutputStream(); populate(s, appendHandle, writeStream); s.seal(appendHandle); byte[] writtenData = writeStream.toByteArray(); val truncateHandle = (RollingSegmentHandle) s.openWrite(SEGMENT_NAME); Assert.assertTrue("Handle not read-only after sealing.", truncateHandle.isReadOnly()); Assert.assertTrue("Handle not sealed after sealing.", truncateHandle.isSealed()); // Test that truncate works in this scenario. testProgressiveTruncate(truncateHandle, truncateHandle, writtenData, s, baseStorage); }
@Override public void delete(SegmentHandle handle) throws StreamSegmentNotExistsException { maybeThrow(handle.getSegmentName(), this.deleteFailure); super.delete(handle); }
@Override public void concat(SegmentHandle targetHandle, long offset, String sourceSegment) throws StreamSegmentException { maybeThrow(sourceSegment, this.concatFailure); super.concat(targetHandle, offset, sourceSegment); }