Package com.taobao.metamorphosis.server.store.MessageStore

Examples of com.taobao.metamorphosis.server.store.MessageStore.SegmentList


    }


    @Test
    public void testGetNearestOffset() throws Exception {
        final SegmentList segmentList = new SegmentList();
        assertEquals(0, segmentList.contents.get().length);
        final File file = new File("testGetNearestOffset.test");
        if (!file.exists()) {
            file.createNewFile();
        }
        final Segment segment1 = new Segment(0, file);
        segment1.fileMessageSet.setHighWaterMarker(1024);
        final Segment segment2 = new Segment(1024, file);
        segment2.fileMessageSet.setHighWaterMarker(1024);
        final Segment segment3 = new Segment(2048, file);
        segment3.fileMessageSet.setHighWaterMarker(1024);
        final Segment segment4 = new Segment(3072, file);
        segment4.fileMessageSet.setHighWaterMarker(1024);

        segmentList.append(segment1);
        segmentList.append(segment2);
        segmentList.append(segment3);
        segmentList.append(segment4);

        try {
            assertEquals(0, this.messageStore.getNearestOffset(-100, segmentList));
            assertEquals(0, this.messageStore.getNearestOffset(0, segmentList));
            assertEquals(0, this.messageStore.getNearestOffset(100, segmentList));
View Full Code Here


    }


    @Test
    public void testFindSegment() throws Exception {
        final SegmentList segmentList = new SegmentList();
        assertEquals(0, segmentList.contents.get().length);
        final File file = new File("testFindSegment.test");
        if (!file.exists()) {
            file.createNewFile();
        }
        final Segment segment1 = new Segment(0, file);
        segment1.fileMessageSet.setHighWaterMarker(1024);
        final Segment segment2 = new Segment(1024, file);
        segment2.fileMessageSet.setHighWaterMarker(1024);
        final Segment segment3 = new Segment(2048, file);
        segment3.fileMessageSet.setHighWaterMarker(1024);
        final Segment segment4 = new Segment(3072, file);
        segment4.fileMessageSet.setHighWaterMarker(1024);

        segmentList.append(segment1);
        segmentList.append(segment2);
        segmentList.append(segment3);
        segmentList.append(segment4);
        try {
            assertSame(segment1, this.messageStore.findSegment(segmentList.view(), 0));
            assertSame(segment1, this.messageStore.findSegment(segmentList.view(), 1));
            assertSame(segment1, this.messageStore.findSegment(segmentList.view(), 1023));
            assertSame(segment2, this.messageStore.findSegment(segmentList.view(), 1024));
            assertSame(segment2, this.messageStore.findSegment(segmentList.view(), 1536));
            assertSame(segment3, this.messageStore.findSegment(segmentList.view(), 2048));
            assertSame(segment3, this.messageStore.findSegment(segmentList.view(), 2049));
            assertSame(segment3, this.messageStore.findSegment(segmentList.view(), 3000));
            assertSame(segment4, this.messageStore.findSegment(segmentList.view(), 3072));
            assertSame(segment4, this.messageStore.findSegment(segmentList.view(), 3073));
            assertNull(this.messageStore.findSegment(segmentList.view(), 4097));
            assertNull(this.messageStore.findSegment(segmentList.view(), 4098));
            assertNull(this.messageStore.findSegment(segmentList.view(), 16 * 1024));
            try {
                this.messageStore.findSegment(segmentList.view(), -1);
                fail();
            }
            catch (final ArrayIndexOutOfBoundsException e) {
                assertTrue(true);
            }
View Full Code Here

    }


    @Test
    public void testAppendSegmentDeleteSegment() throws Exception {
        final SegmentList segmentList = new SegmentList();
        assertEquals(0, segmentList.contents.get().length);
        final File file = new File("testAppendSegmentDeleteSegment.test");
        if (!file.exists()) {
            file.createNewFile();
        }
        final Segment segment1 = new Segment(0, file);
        final Segment segment2 = new Segment(1024, file);
        final Segment segment3 = new Segment(2048, file);
        try {
            segmentList.append(segment1);
            assertEquals(1, segmentList.contents.get().length);
            assertSame(segment1, segmentList.first());
            assertSame(segment1, segmentList.last());
            segmentList.append(segment2);
            assertEquals(2, segmentList.contents.get().length);
            assertSame(segment1, segmentList.first());
            assertSame(segment2, segmentList.last());
            segmentList.append(segment3);
            assertEquals(3, segmentList.contents.get().length);
            assertSame(segment1, segmentList.first());
            assertSame(segment3, segmentList.last());

            segmentList.delete(segment1);
            assertEquals(2, segmentList.contents.get().length);
            assertSame(segment2, segmentList.first());
            assertSame(segment3, segmentList.last());

            segmentList.delete(segment3);
            assertEquals(1, segmentList.contents.get().length);
            assertSame(segment2, segmentList.first());
            assertSame(segment2, segmentList.last());
            // delete not existing
            segmentList.delete(segment3);
            assertEquals(1, segmentList.contents.get().length);
            assertSame(segment2, segmentList.first());
            assertSame(segment2, segmentList.last());

            segmentList.delete(segment2);
            assertEquals(0, segmentList.contents.get().length);
            assertNull(segmentList.first());
            assertNull(segmentList.last());
        }
        finally {
            if (segment1 != null) {
                segment1.fileMessageSet.close();
            }
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.server.store.MessageStore.SegmentList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.