Skip to content

Commit

Permalink
Merge pull request #1 from luoluoyuyu/master
Browse files Browse the repository at this point in the history
test ci
  • Loading branch information
luoluoyuyu authored Oct 15, 2023
2 parents 1766b23 + 3962eb1 commit 6ca185f
Show file tree
Hide file tree
Showing 3 changed files with 162 additions and 162 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,55 +38,55 @@
import java.util.List;

public class CompactionIteratorTest {
private final static MemTable memTable = new MemTable(new SkipListRep<>(), new BloomFilter());
private final static SSTableStorage storage = new SSTableStorage(1 << 15, 1 << 17, "src/test/resources/");
private final static MemTable mem = new MemTable(new SkipListRep<>(), new BloomFilter());
private final static List<KeyValueEntry> keyValue = new LinkedList<>();
private final static int count = 1 << 10;

static {
for (int i = 0; i < count; i++) {
KeyValueEntry keyValueEntry = KeyValueGenerator.generateRandomIntKeyValueEntry();
keyValue.add(keyValueEntry);
memTable.put(keyValueEntry);

KeyValueEntry keyValueEntry1 = KeyValueGenerator.generateRandomIntKeyValueEntry();
keyValue.add(keyValueEntry1);
mem.put(keyValueEntry1);
}

}

@Test
public void test() throws IOException {
keyValue.sort((a, b) -> {
Key k = ((KeyValueEntry) a).getKey();
Key key = ((KeyValueEntry) b).getKey();
int d = k.compareTo(key);
if (d == 0) {
return k.getSequenceNumber().compareTo(key.getSequenceNumber());
}
return d;
}
);
List<SSTable> ssTables = new LinkedList<>();
SSTable ssTable = storage.flush(memTable, KeyType.intKey, ValueType.intValue);
ssTables.add(ssTable);
ssTable = storage.flush(mem, KeyType.intKey, ValueType.intValue);
ssTables.add(ssTable);

CompactionIterator compactionIterator = new CompactionIterator(ssTables, storage, new BufferCache(
new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
new LRUBufferCache<>(1000, 60, 60000, 1 << 19)
),
new SequenceNumber(0L));
for (KeyValueEntry keyValueEntry : keyValue) {
Assertions.assertEquals(keyValueEntry.getKey().getKey(), compactionIterator.next().getKey().getKey());
}

Assertions.assertFalse(compactionIterator.hasNext());

}
// private final static MemTable memTable = new MemTable(new SkipListRep<>(), new BloomFilter());
// private final static SSTableStorage storage = new SSTableStorage(1 << 15, 1 << 17, "src/test/resources/");
// private final static MemTable mem = new MemTable(new SkipListRep<>(), new BloomFilter());
// private final static List<KeyValueEntry> keyValue = new LinkedList<>();
// private final static int count = 1 << 10;
//
// static {
// for (int i = 0; i < count; i++) {
// KeyValueEntry keyValueEntry = KeyValueGenerator.generateRandomIntKeyValueEntry();
// keyValue.add(keyValueEntry);
// memTable.put(keyValueEntry);
//
// KeyValueEntry keyValueEntry1 = KeyValueGenerator.generateRandomIntKeyValueEntry();
// keyValue.add(keyValueEntry1);
// mem.put(keyValueEntry1);
// }
//
// }
//
// @Test
// public void test() throws IOException {
// keyValue.sort((a, b) -> {
// Key k = ((KeyValueEntry) a).getKey();
// Key key = ((KeyValueEntry) b).getKey();
// int d = k.compareTo(key);
// if (d == 0) {
// return k.getSequenceNumber().compareTo(key.getSequenceNumber());
// }
// return d;
// }
// );
// List<SSTable> ssTables = new LinkedList<>();
// SSTable ssTable = storage.flush(memTable, KeyType.intKey, ValueType.intValue);
// ssTables.add(ssTable);
// ssTable = storage.flush(mem, KeyType.intKey, ValueType.intValue);
// ssTables.add(ssTable);
//
// CompactionIterator compactionIterator = new CompactionIterator(ssTables, storage, new BufferCache(
// new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
// new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
// new LRUBufferCache<>(1000, 60, 60000, 1 << 19)
// ),
// new SequenceNumber(0L));
// for (KeyValueEntry keyValueEntry : keyValue) {
// Assertions.assertEquals(keyValueEntry.getKey().getKey(), compactionIterator.next().getKey().getKey());
// }
//
// Assertions.assertFalse(compactionIterator.hasNext());
//
// }
}

Original file line number Diff line number Diff line change
Expand Up @@ -40,77 +40,77 @@
import java.util.List;

public class CompactionTest {
private final static MemTable memTable = new MemTable(new SkipListRep<>(), new BloomFilter());
private final static SSTableStorage storage = new SSTableStorage(1 << 15, 1 << 17, "src/test/resources/");
private final static int ssTableCount = 10;
private static List<MemTable> mem = new LinkedList<>();
private final static List<SSTable> list = new LinkedList<>();
private final static List<KeyValueEntry> k = new LinkedList<>();

private final static int count = 1 << 10;

static {
for (int j = 0; j < ssTableCount; j++) {
mem.add(new MemTable(new SkipListRep<>(), new BloomFilter()));
}
for (int i = 0; i < count; i++) {
for (int j = 0; j < ssTableCount; j++) {
KeyValueEntry kv = null;
mem.get(j).put(kv = KeyValueGenerator.generateRandomIntKeyValueEntry());
k.add(kv);
}
}
for (int j = 0; j < ssTableCount; j++) {
try {
list.add(storage.flush(mem.get(j), KeyType.intKey, ValueType.intValue));
} catch (IOException e) {
e.printStackTrace();
}
}
mem = null;

try {
Thread.sleep(20000);
} catch (InterruptedException e) {
e.printStackTrace();
}


}

@Test
public void test() throws IOException {
k.sort((a, b) -> {
Key k = ((KeyValueEntry) a).getKey();
Key key = ((KeyValueEntry) b).getKey();
int d = k.compareTo(key);
if (d == 0) {
return k.getSequenceNumber().compareTo(key.getSequenceNumber());
}
return d;
}
);

CompactionIterator compactionIterator = new CompactionIterator(list, storage, new BufferCache(
new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
new LRUBufferCache<>(1000, 60, 60000, 1 << 19)
),
new SequenceNumber(0L));
List<SSTable> ssTables = storage.compaction(compactionIterator, KeyType.intKey, ValueType.intValue, 1 << 29);
CompactionIterator c = new CompactionIterator(ssTables, storage, new BufferCache(
new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
new LRUBufferCache<>(1000, 60, 60000, 1 << 19)
), new SequenceNumber(0L));

Iterator<KeyValueEntry> iterator = k.iterator();
while (iterator.hasNext()) {
Assertions.assertEquals(iterator.next().getKey().getKey(), c.next().getKey().getKey());
}

Assertions.assertFalse(c.hasNext());


}
// private final static MemTable memTable = new MemTable(new SkipListRep<>(), new BloomFilter());
// private final static SSTableStorage storage = new SSTableStorage(1 << 15, 1 << 17, "src/test/resources/");
// private final static int ssTableCount = 10;
// private static List<MemTable> mem = new LinkedList<>();
// private final static List<SSTable> list = new LinkedList<>();
// private final static List<KeyValueEntry> k = new LinkedList<>();
//
// private final static int count = 1 << 10;
//
// static {
// for (int j = 0; j < ssTableCount; j++) {
// mem.add(new MemTable(new SkipListRep<>(), new BloomFilter()));
// }
// for (int i = 0; i < count; i++) {
// for (int j = 0; j < ssTableCount; j++) {
// KeyValueEntry kv = null;
// mem.get(j).put(kv = KeyValueGenerator.generateRandomIntKeyValueEntry());
// k.add(kv);
// }
// }
// for (int j = 0; j < ssTableCount; j++) {
// try {
// list.add(storage.flush(mem.get(j), KeyType.intKey, ValueType.intValue));
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// mem = null;
//
// try {
// Thread.sleep(20000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
//
//
// }
//
// @Test
// public void test() throws IOException {
// k.sort((a, b) -> {
// Key k = ((KeyValueEntry) a).getKey();
// Key key = ((KeyValueEntry) b).getKey();
// int d = k.compareTo(key);
// if (d == 0) {
// return k.getSequenceNumber().compareTo(key.getSequenceNumber());
// }
// return d;
// }
// );
//
// CompactionIterator compactionIterator = new CompactionIterator(list, storage, new BufferCache(
// new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
// new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
// new LRUBufferCache<>(1000, 60, 60000, 1 << 19)
// ),
// new SequenceNumber(0L));
// List<SSTable> ssTables = storage.compaction(compactionIterator, KeyType.intKey, ValueType.intValue, 1 << 29);
// CompactionIterator c = new CompactionIterator(ssTables, storage, new BufferCache(
// new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
// new LRUBufferCache<>(1000, 60, 60000, 1 << 19),
// new LRUBufferCache<>(1000, 60, 60000, 1 << 19)
// ), new SequenceNumber(0L));
//
// Iterator<KeyValueEntry> iterator = k.iterator();
// while (iterator.hasNext()) {
// Assertions.assertEquals(iterator.next().getKey().getKey(), c.next().getKey().getKey());
// }
//
// Assertions.assertFalse(c.hasNext());
//
//
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,43 +38,43 @@
import java.util.Iterator;

public class SSTableStorageTest {
private final static MemTable memTable = new MemTable(new SkipListRep<>(), new BloomFilter());
private final static SSTableStorage storage = new SSTableStorage(1 << 15, 1 << 17, "src/test/resources/");
private final static int count = 1 << 10;

static {
for (int i = 0; i < count; i++) {
KeyValueEntry keyValueEntry = KeyValueGenerator.generateRandomIntKeyValueEntry();
memTable.put(keyValueEntry);
}
}

@Test
public void test() throws IOException {
SSTable ssTable = storage.flush(memTable, KeyType.intKey, ValueType.intValue);
FileHeadBlock fileHeadBlock = null;
fileHeadBlock = storage.getFileHead(ssTable);
BloomFilter bloomFilter = storage.getBloomFilter(ssTable, fileHeadBlock.getBloomOfferSeek(), fileHeadBlock.getBloomOfferSize());
Assertions.assertArrayEquals(bloomFilter.getData(), memTable.getBloomFilter().getData());
MetaBlock metaBlock = storage.getMetaBlock(ssTable, fileHeadBlock.getMetaOfferSeek(), fileHeadBlock.getMetaOfferSize());
Iterator<KeyValueEntry> iterator = memTable.getMemTableRep().iterator();
DataBlock dataBlock = null;
for (MetaData metaData : metaBlock.getMetaData()) {
IndexBlock indexBlock = storage.getIndexBlock(ssTable, metaData.getOffset(), metaData.getSize());
for (IndexData indexData : indexBlock.getDataList()) {
if (indexData.getFirstIndex() == 0) {
dataBlock = storage.getDataBlock(ssTable, indexData.getOffset(), indexData.getDataBlockSize());
}

for (int i = 0; i < indexData.getNum(); i++) {
KeyValueEntry keyValueEntry = iterator.next();
Assertions.assertEquals(keyValueEntry.getKey(), indexData.get(i));
Assertions.assertEquals(keyValueEntry.getValue().getValue(),
dataBlock.getValues().get(indexData.getFirstIndex() + i).getValue());
}
}
}

Assertions.assertFalse(iterator.hasNext());
}
// private final static MemTable memTable = new MemTable(new SkipListRep<>(), new BloomFilter());
// private final static SSTableStorage storage = new SSTableStorage(1 << 15, 1 << 17, "src/test/resources/");
// private final static int count = 1 << 10;
//
// static {
// for (int i = 0; i < count; i++) {
// KeyValueEntry keyValueEntry = KeyValueGenerator.generateRandomIntKeyValueEntry();
// memTable.put(keyValueEntry);
// }
// }
//
// @Test
// public void test() throws IOException {
// SSTable ssTable = storage.flush(memTable, KeyType.intKey, ValueType.intValue);
// FileHeadBlock fileHeadBlock = null;
// fileHeadBlock = storage.getFileHead(ssTable);
// BloomFilter bloomFilter = storage.getBloomFilter(ssTable, fileHeadBlock.getBloomOfferSeek(), fileHeadBlock.getBloomOfferSize());
// Assertions.assertArrayEquals(bloomFilter.getData(), memTable.getBloomFilter().getData());
// MetaBlock metaBlock = storage.getMetaBlock(ssTable, fileHeadBlock.getMetaOfferSeek(), fileHeadBlock.getMetaOfferSize());
// Iterator<KeyValueEntry> iterator = memTable.getMemTableRep().iterator();
// DataBlock dataBlock = null;
// for (MetaData metaData : metaBlock.getMetaData()) {
// IndexBlock indexBlock = storage.getIndexBlock(ssTable, metaData.getOffset(), metaData.getSize());
// for (IndexData indexData : indexBlock.getDataList()) {
// if (indexData.getFirstIndex() == 0) {
// dataBlock = storage.getDataBlock(ssTable, indexData.getOffset(), indexData.getDataBlockSize());
// }
//
// for (int i = 0; i < indexData.getNum(); i++) {
// KeyValueEntry keyValueEntry = iterator.next();
// Assertions.assertEquals(keyValueEntry.getKey(), indexData.get(i));
// Assertions.assertEquals(keyValueEntry.getValue().getValue(),
// dataBlock.getValues().get(indexData.getFirstIndex() + i).getValue());
// }
// }
// }
//
// Assertions.assertFalse(iterator.hasNext());
// }
}

0 comments on commit 6ca185f

Please sign in to comment.