// // Verify that intersect() properly handles maps containing extent // buffers whose positions and limits are not necessarily equal to (resp.) // 0 and their capacities. // // This test recreates the circumstances of a bug observed while testing // the ExtentBufferStreamer class. // @Test public void testIntersectChopped() { ByteBuffer b03_06 = ByteBuffer.wrap("def".getBytes()); ByteBuffer b09_12 = ByteBuffer.wrap("jkl".getBytes()); ByteBuffer b15_18 = ByteBuffer.wrap("pqr".getBytes()); ExtentBuffer eb03_06 = new ExtentBuffer(3L, b03_06); ExtentBuffer eb09_12 = new ExtentBuffer(9L, b09_12); ExtentBuffer eb15_18 = new ExtentBuffer(15L, b15_18); ExtentBufferMap fullMap = new ExtentBufferMap(); fullMap.put(eb03_06); fullMap.put(eb09_12); fullMap.put(eb15_18); // // Shorten the middle buffer in the map. // eb09_12.position(1).limit(2); // // Intersect fullMap against an extent that will chop up the first // contained extent buffer and leave the second two intact. // ExtentBufferMap choppedMap = fullMap.intersect(new ExtentImpl(4L, 30L)); ExtentBuffer eb = choppedMap.get(9L); assertNotNull("chopped map should still contain the middle extent", eb); assertEquals("middle extent should have position 1", eb.position(), 1); assertEquals("middle extent should have limit 2", eb.limit(), 2); }