val headerHandle = new TestHandle(HEADER_NAME, true); val h = new RollingSegmentHandle(headerHandle, DEFAULT_ROLLING_POLICY, new ArrayList<>());
val headerHandle = new TestHandle(HEADER_NAME, true); val h = new RollingSegmentHandle(headerHandle, DEFAULT_ROLLING_POLICY, new ArrayList<>()); AssertExtensions.assertThrows( "addChunk allowed adding a read-only ActiveSegmentHandle.", () -> h.addChunk(new SegmentChunk("s", 0L), new TestHandle("s", true)), ex -> ex instanceof IllegalArgumentException); AssertExtensions.assertThrows( "addChunk allowed adding an ActiveSegmentHandle with different name..", () -> h.addChunk(new SegmentChunk("s", 0L), new TestHandle("s2", false)), ex -> ex instanceof IllegalArgumentException); Assert.assertEquals("Not expecting any SegmentChunks to be added.", 0, h.chunks().size()); h.addChunk(chunk, new TestHandle("s1", false)); chunk.setLength(123L); Assert.assertEquals("Unexpected value for length() after adding one SegmentChunk.", () -> h.addChunk(new SegmentChunk("s2", chunk.getLastOffset() + 1), new TestHandle("s2", false)), ex -> ex instanceof IllegalArgumentException); val chunk2 = new SegmentChunk("s2", chunk.getLastOffset()); chunk2.setLength(234L); h.addChunk(chunk2, new TestHandle("s2", false)); Assert.assertEquals("Unexpected number of registered SegmentChunks.", 2, h.chunks().size()); Assert.assertEquals("Unexpected value for length() after adding two SegmentChunk.",
val headerHandle = new TestHandle(HEADER_NAME, true); val h = new RollingSegmentHandle(headerHandle, DEFAULT_ROLLING_POLICY, new ArrayList<>()); Assert.assertNull("Unexpected lastChunk for empty handle.", h.lastChunk()); () -> h.setActiveChunkHandle(new TestHandle("foo", false)), ex -> ex instanceof IllegalStateException); h.addChunk(new SegmentChunk(chunkName, 0L), new TestHandle(chunkName, false)); AssertExtensions.assertThrows( "setActiveChunkHandle accepted a handle that does not match the last SegmentChunk's name.", () -> h.setActiveChunkHandle(new TestHandle("foo", false)), ex -> ex instanceof IllegalArgumentException); () -> h.setActiveChunkHandle(new TestHandle(chunkName, true)), ex -> ex instanceof IllegalArgumentException); val activeHandle = new TestHandle(chunkName, false); h.setActiveChunkHandle(activeHandle); Assert.assertEquals("Unexpected value from getActiveChunkHandle.", activeHandle, h.getActiveChunkHandle());
/** * Tests the ability of the Handle to refresh based on information from another similar handle. */ @Test public void testRefresh() { val headerHandle = new TestHandle(HEADER_NAME, true); val target = new RollingSegmentHandle(headerHandle, DEFAULT_ROLLING_POLICY, Collections.singletonList(new SegmentChunk("s1", 0L))); val source = new RollingSegmentHandle(headerHandle, DEFAULT_ROLLING_POLICY, Arrays.asList( new SegmentChunk("s1", 0L), new SegmentChunk("s2", 100L))); source.chunks().get(0).setLength(100); source.markSealed(); source.setHeaderLength(1000); source.setActiveChunkHandle(new TestHandle(source.lastChunk().getName(), false)); target.refresh(source); Assert.assertEquals("Unexpected getHeaderLength()", source.getHeaderLength(), target.getHeaderLength()); AssertExtensions.assertListEquals("Unexpected chunks()", source.chunks(), target.chunks(), Object::equals); Assert.assertTrue("Unexpected isSealed.", target.isSealed()); Assert.assertNull("Not expecting any ActiveSegmentHandle to be copied.", target.getActiveChunkHandle()); }