use of com.cinchapi.concourse.server.storage.db.SegmentStorageSystem in project concourse by cinchapi.
the class CompactorLogicTest method testRunMergeShift.
@Test
public void testRunMergeShift() {
SegmentStorageSystem storage = CompactorTests.getStorageSystem();
for (int i = 0; i < 10; ++i) {
storage.segments().add(createTestSegment());
}
Compactor compactor = new MergeCompactor(storage);
compactor.runShift(0, 1);
Assert.assertEquals(1, compactor.getShiftIndex());
Assert.assertEquals(1, compactor.getShiftCount());
compactor.runShift(0, 3);
Assert.assertEquals(2, compactor.getShiftIndex());
Assert.assertEquals(3, compactor.getShiftCount());
compactor.runShift(9, 1);
Assert.assertEquals(0, compactor.getShiftIndex());
Assert.assertEquals(2, compactor.getShiftCount());
// start over
compactor.runShift(0, 10);
Assert.assertEquals(0, compactor.getShiftIndex());
Assert.assertEquals(1, compactor.getShiftCount());
compactor.runShift(4, 5);
Assert.assertEquals(0, compactor.getShiftIndex());
Assert.assertEquals(6, compactor.getShiftCount());
}
use of com.cinchapi.concourse.server.storage.db.SegmentStorageSystem in project concourse by cinchapi.
the class CompactorLogicTest method testRunFailShift.
@Test
public void testRunFailShift() {
SegmentStorageSystem storage = CompactorTests.getStorageSystem();
for (int i = 0; i < 10; ++i) {
storage.segments().add(createTestSegment());
}
Compactor compactor = new FailCompactor(storage);
compactor.runShift(0, 6);
Assert.assertEquals(1, compactor.getShiftIndex());
Assert.assertEquals(6, compactor.getShiftCount());
compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
Assert.assertEquals(2, compactor.getShiftIndex());
Assert.assertEquals(6, compactor.getShiftCount());
compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
Assert.assertEquals(3, compactor.getShiftIndex());
Assert.assertEquals(6, compactor.getShiftCount());
compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
Assert.assertEquals(4, compactor.getShiftIndex());
Assert.assertEquals(6, compactor.getShiftCount());
compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
Assert.assertEquals(5, compactor.getShiftIndex());
Assert.assertEquals(6, compactor.getShiftCount());
compactor.runShift(compactor.getShiftIndex(), compactor.getShiftCount());
Assert.assertEquals(0, compactor.getShiftIndex());
Assert.assertEquals(7, compactor.getShiftCount());
}
use of com.cinchapi.concourse.server.storage.db.SegmentStorageSystem in project concourse by cinchapi.
the class CompactorTests method getStorageSystem.
/**
* Return a {@link SegmentStorageSystem} to use in a test.
*
* @return the {@link SegmentStorageSystem}
*/
public static SegmentStorageSystem getStorageSystem() {
return new SegmentStorageSystem() {
File fs = new File(FileSystem.tempFile());
List<Segment> segments = new ArrayList<>();
Lock lock = new ReentrantLock();
@Override
public long availableDiskSpace() {
return fs.getUsableSpace();
}
@Override
public Lock lock() {
return lock;
}
@Override
public Path save(Segment segment) {
Path file = Paths.get(FileSystem.tempFile());
segment.transfer(file);
return file;
}
@Override
public List<Segment> segments() {
return segments;
}
@Override
public long totalDiskSpace() {
return fs.getTotalSpace();
}
};
}
use of com.cinchapi.concourse.server.storage.db.SegmentStorageSystem in project concourse by cinchapi.
the class SimilarityCompactorTest method testSanityCheck.
@Test
public void testSanityCheck() {
SegmentStorageSystem storage = CompactorTests.getStorageSystem();
Segment a = Segment.create();
a.acquire(Write.add("name", Convert.javaToThrift("jeff"), 1));
a.acquire(Write.add("name", Convert.javaToThrift("ashleah"), 2));
a.acquire(Write.add("age", Convert.javaToThrift(33), 2));
a.acquire(Write.add("company", Convert.javaToThrift("Cinchapi"), 1));
a.transfer(Paths.get(TestData.getTemporaryTestFile()));
Segment b = Segment.create();
b.acquire(Write.add("name", Convert.javaToThrift("Jeff"), 1));
b.acquire(Write.remove("name", Convert.javaToThrift("jeff"), 1));
b.acquire(Write.remove("name", Convert.javaToThrift("ashleah"), 2));
b.acquire(Write.add("name", Convert.javaToThrift("Jeffery"), 1));
b.acquire(Write.add("company", Convert.javaToThrift("Know Full Well"), 2));
b.acquire(Write.add("age", Convert.javaToThrift(33), 1));
b.acquire(Write.add("age", Convert.javaToThrift(33.0), 1));
b.transfer(Paths.get(TestData.getTemporaryTestFile()));
storage.segments().add(a);
storage.segments().add(b);
// seg0
storage.segments().add(Segment.create());
SimilarityCompactor compactor = new SimilarityCompactor(storage);
compactor.minimumSimilarityThreshold(0);
List<Write> expected = storage.segments().stream().flatMap(segment -> segment.writes()).collect(Collectors.toList());
compactor.executeFullCompaction();
List<Write> actual = storage.segments().stream().flatMap(segment -> segment.writes()).collect(Collectors.toList());
Assert.assertEquals(2, storage.segments().size());
Assert.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && // assert that no data
actual.containsAll(expected));
// lost...
actual.forEach(System.out::println);
for (int i = 0; i < actual.size(); ++i) {
if (i > 0) {
Identifier previous = actual.get(i - 1).getRecord();
Identifier current = actual.get(i).getRecord();
// Assert that, from table view, all records are grouped
// together
Assert.assertTrue(current.longValue() == previous.longValue() || current.longValue() == previous.longValue() + 1);
}
}
Assert.assertEquals(ImmutableList.of(a, b), compactor.garbage());
}
Aggregations