create Tags in StringCompressor instead of use StringCompressor in Tags
This commit is contained in:
@@ -23,6 +23,7 @@ import javax.swing.JTextArea;
|
||||
import javax.swing.JTextField;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -36,7 +37,6 @@ import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.blockstorage.BSFile;
|
||||
import org.lucares.pdb.datastore.Doc;
|
||||
import org.lucares.pdb.datastore.Proposal;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.lucares.utils.CollectionUtils;
|
||||
import org.lucares.utils.DateUtils;
|
||||
import org.lucares.utils.file.FileUtils;
|
||||
@@ -66,11 +66,13 @@ public class DataStoreTest {
|
||||
final DateTimeRange dateRange = DateTimeRange.relativeHours(1);
|
||||
final ParititionId partitionId = DateIndexExtension.toPartitionIds(dateRange).get(0);
|
||||
|
||||
final Tags eagleTim = Tags.createAndAddToDictionary("bird", "eagle", "name", "Tim");
|
||||
final Tags pigeonJennifer = Tags.createAndAddToDictionary("bird", "pigeon", "name", "Jennifer");
|
||||
final Tags flamingoJennifer = Tags.createAndAddToDictionary("bird", "flamingo", "name", "Jennifer");
|
||||
final Tags labradorJenny = Tags.createAndAddToDictionary("dog", "labrador", "name", "Jenny");
|
||||
final Tags labradorTim = Tags.createAndAddToDictionary("dog", "labrador", "name", "Tim");
|
||||
final Tags eagleTim = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "eagle", "name", "Tim");
|
||||
final Tags pigeonJennifer = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "pigeon", "name",
|
||||
"Jennifer");
|
||||
final Tags flamingoJennifer = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "flamingo", "name",
|
||||
"Jennifer");
|
||||
final Tags labradorJenny = Tags.STRING_COMPRESSOR.createAndAddToDictionary("dog", "labrador", "name", "Jenny");
|
||||
final Tags labradorTim = Tags.STRING_COMPRESSOR.createAndAddToDictionary("dog", "labrador", "name", "Tim");
|
||||
|
||||
tagsToBlockStorageRootBlockNumber = new HashMap<>();
|
||||
tagsToBlockStorageRootBlockNumber.put(eagleTim, dataStore.createNewFile(partitionId, eagleTim));
|
||||
@@ -115,8 +117,10 @@ public class DataStoreTest {
|
||||
|
||||
dataStore = new DataStore(dataDirectory);
|
||||
tagsToBlockStorageRootBlockNumber = new LinkedHashMap<>();
|
||||
final Tags pigeonJennifer = Tags.createAndAddToDictionary("bird", "pigeon", "name", "Jennifer");
|
||||
final Tags flamingoJennifer = Tags.createAndAddToDictionary("bird", "flamingo", "name", "Jennifer");
|
||||
final Tags pigeonJennifer = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "pigeon", "name",
|
||||
"Jennifer");
|
||||
final Tags flamingoJennifer = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "flamingo", "name",
|
||||
"Jennifer");
|
||||
|
||||
final ParititionId partitionId = new ParititionId("partitionA");
|
||||
tagsToBlockStorageRootBlockNumber.put(pigeonJennifer, dataStore.createNewFile(partitionId, pigeonJennifer));
|
||||
@@ -130,7 +134,7 @@ public class DataStoreTest {
|
||||
public void testBlockAlignment() throws IOException {
|
||||
|
||||
dataStore = new DataStore(dataDirectory);
|
||||
final Tags eagleTim = Tags.createAndAddToDictionary("bird", "eagle", "name", "Tim");
|
||||
final Tags eagleTim = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "eagle", "name", "Tim");
|
||||
final long eagleTimBlockOffset = dataStore.createNewFile(new ParititionId("partitionA"), eagleTim);
|
||||
Assertions.assertEquals(0, eagleTimBlockOffset % BSFile.BLOCK_SIZE);
|
||||
}
|
||||
@@ -183,18 +187,28 @@ public class DataStoreTest {
|
||||
final DateTimeRange dateRange = DateTimeRange.relativeHours(1);
|
||||
|
||||
final List<Tags> tags = Arrays.asList(
|
||||
Tags.createAndAddToDictionary("type", "bird", "subtype", "eagle", "age", "three", "name", "Tim"),
|
||||
Tags.createAndAddToDictionary("type", "bird", "subtype", "pigeon", "age", "two", "name", "Jennifer"),
|
||||
Tags.createAndAddToDictionary("type", "bird", "subtype", "flamingo", "age", "one", "name", "Jennifer"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "bird", "subtype", "eagle", "age", "three",
|
||||
"name", "Tim"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "bird", "subtype", "pigeon", "age", "two",
|
||||
"name", "Jennifer"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "bird", "subtype", "flamingo", "age", "one",
|
||||
"name", "Jennifer"),
|
||||
|
||||
Tags.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three", "name", "Jenny"),
|
||||
Tags.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three", "name", "Tim"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three",
|
||||
"name", "Jenny"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three",
|
||||
"name", "Tim"),
|
||||
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "one", "name", "Timothy"),
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "two", "name", "Paul"),
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "three", "name", "Jane"),
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name", "Sam"),
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name", "John"));
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "one", "name",
|
||||
"Timothy"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "two", "name",
|
||||
"Paul"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "three",
|
||||
"name", "Jane"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name",
|
||||
"Sam"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name",
|
||||
"John"));
|
||||
|
||||
tags.forEach(t -> dataStore.createNewFile(partitionId, t));
|
||||
|
||||
@@ -208,7 +222,7 @@ public class DataStoreTest {
|
||||
|
||||
final long timestamp = DateUtils.getDate(2016, 1, 1, 13, 1, 1).toInstant().toEpochMilli();
|
||||
|
||||
final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
|
||||
final Tags tags = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "myValue");
|
||||
|
||||
dataStore.write(timestamp, tags, 1);
|
||||
dataStore.write(timestamp, tags, 2);
|
||||
@@ -222,21 +236,28 @@ public class DataStoreTest {
|
||||
try (final DataStore dataStore = new DataStore(dir)) {
|
||||
|
||||
final List<Tags> tags = Arrays.asList(
|
||||
Tags.createAndAddToDictionary("type", "bird", "subtype", "eagle", "age", "three", "name", "Tim"),
|
||||
Tags.createAndAddToDictionary("type", "bird", "subtype", "pigeon", "age", "two", "name",
|
||||
"Jennifer"),
|
||||
Tags.createAndAddToDictionary("type", "bird", "subtype", "flamingo", "age", "one", "name",
|
||||
"Jennifer"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "bird", "subtype", "eagle", "age", "three",
|
||||
"name", "Tim"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "bird", "subtype", "pigeon", "age", "two",
|
||||
"name", "Jennifer"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "bird", "subtype", "flamingo", "age", "one",
|
||||
"name", "Jennifer"),
|
||||
|
||||
Tags.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three", "name",
|
||||
"Jenny"),
|
||||
Tags.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age", "three", "name", "Tim"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age",
|
||||
"three", "name", "Jenny"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "dog", "subtype", "labrador", "age",
|
||||
"three", "name", "Tim"),
|
||||
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "one", "name", "Timothy"),
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "two", "name", "Paul"),
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "three", "name", "Jane"),
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name", "Sam"),
|
||||
Tags.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four", "name", "John"));
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "one",
|
||||
"name", "Timothy"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "tiger", "age", "two",
|
||||
"name", "Paul"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "three",
|
||||
"name", "Jane"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four",
|
||||
"name", "Sam"),
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("type", "cat", "subtype", "lion", "age", "four",
|
||||
"name", "John"));
|
||||
|
||||
final DateTimeRange dateRange = DateTimeRange.relativeMillis(0);
|
||||
final ParititionId partitionId = DateIndexExtension.toPartitionIds(dateRange).get(0);
|
||||
|
||||
@@ -8,6 +8,7 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.lucares.pdb.api.DateTimeRange;
|
||||
@@ -15,7 +16,6 @@ import org.lucares.pdb.api.QueryWithCaretMarker;
|
||||
import org.lucares.pdb.api.QueryWithCaretMarker.ResultMode;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.datastore.Proposal;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.lucares.utils.CollectionUtils;
|
||||
import org.lucares.utils.file.FileUtils;
|
||||
|
||||
@@ -44,18 +44,23 @@ public class ProposerTest {
|
||||
dateRange = DateTimeRange.now();
|
||||
final ParititionId now = DateIndexExtension.toPartitionIds(dateRange).get(0);
|
||||
|
||||
final Tags eagleTim = Tags.createAndAddToDictionary("bird", "eagle", "name", "Tim");
|
||||
final Tags eagleTimothy = Tags.createAndAddToDictionary("bird", "eagle", "name", "Timothy");
|
||||
final Tags pigeonJennifer = Tags.createAndAddToDictionary("bird", "pigeon", "name", "Jennifer");
|
||||
final Tags flamingoJennifer = Tags.createAndAddToDictionary("bird", "flamingo", "name", "Jennifer");
|
||||
final Tags labradorJenny = Tags.createAndAddToDictionary("dog", "labrador", "name", "Jenny");
|
||||
final Tags labradorTim = Tags.createAndAddToDictionary("dog", "labrador", "name", "Tim");
|
||||
final Tags eagleTim = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "eagle", "name", "Tim");
|
||||
final Tags eagleTimothy = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "eagle", "name", "Timothy");
|
||||
final Tags pigeonJennifer = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "pigeon", "name",
|
||||
"Jennifer");
|
||||
final Tags flamingoJennifer = Tags.STRING_COMPRESSOR.createAndAddToDictionary("bird", "flamingo", "name",
|
||||
"Jennifer");
|
||||
final Tags labradorJenny = Tags.STRING_COMPRESSOR.createAndAddToDictionary("dog", "labrador", "name", "Jenny");
|
||||
final Tags labradorTim = Tags.STRING_COMPRESSOR.createAndAddToDictionary("dog", "labrador", "name", "Tim");
|
||||
|
||||
final Tags methodA = Tags.createAndAddToDictionary("method", "FooController.doImportantStuff", "source", "web");
|
||||
final Tags methodB = Tags.createAndAddToDictionary("method", "FooService.doImportantStuff", "source",
|
||||
"service");
|
||||
final Tags methodC = Tags.createAndAddToDictionary("method", "BarController.doBoringStuff", "source", "web");
|
||||
final Tags methodD = Tags.createAndAddToDictionary("method", "FooBarService.doOtherStuff", "source", "service");
|
||||
final Tags methodA = Tags.STRING_COMPRESSOR.createAndAddToDictionary("method", "FooController.doImportantStuff",
|
||||
"source", "web");
|
||||
final Tags methodB = Tags.STRING_COMPRESSOR.createAndAddToDictionary("method", "FooService.doImportantStuff",
|
||||
"source", "service");
|
||||
final Tags methodC = Tags.STRING_COMPRESSOR.createAndAddToDictionary("method", "BarController.doBoringStuff",
|
||||
"source", "web");
|
||||
final Tags methodD = Tags.STRING_COMPRESSOR.createAndAddToDictionary("method", "FooBarService.doOtherStuff",
|
||||
"source", "service");
|
||||
|
||||
dataStore.createNewFile(now, eagleTim);
|
||||
dataStore.createNewFile(now, eagleTimothy);
|
||||
|
||||
@@ -38,9 +38,12 @@ public class QueryCompletionIndexTest {
|
||||
Tags.STRING_COMPRESSOR = new StringCompressor(new UniqueStringIntegerPairs());
|
||||
|
||||
final List<Tags> tags = Arrays.asList(//
|
||||
Tags.createAndAddToDictionary("firstname", "John", "lastname", "Doe", "country", "Atlantis"), // A
|
||||
Tags.createAndAddToDictionary("firstname", "Jane", "lastname", "Doe", "country", "ElDorado"), // B
|
||||
Tags.createAndAddToDictionary("firstname", "John", "lastname", "Miller", "country", "Atlantis")// C
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("firstname", "John", "lastname", "Doe", "country",
|
||||
"Atlantis"), // A
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("firstname", "Jane", "lastname", "Doe", "country",
|
||||
"ElDorado"), // B
|
||||
Tags.STRING_COMPRESSOR.createAndAddToDictionary("firstname", "John", "lastname", "Miller", "country",
|
||||
"Atlantis")// C
|
||||
);
|
||||
|
||||
final DateTimeRange dateRange = DateTimeRange.relativeMillis(1);
|
||||
|
||||
@@ -64,4 +64,59 @@ public class StringCompressor {
|
||||
return get(tag.getValue());
|
||||
}
|
||||
|
||||
public Tags createAndAddToDictionary(final String key, final String value) {
|
||||
final int keyAsInt = put(key);
|
||||
final int valueAsInt = put(value);
|
||||
return TagsBuilder.create().add(keyAsInt, valueAsInt).build();
|
||||
}
|
||||
|
||||
public Tags createAndAddToDictionary(final String key1, final String value1, final String key2,
|
||||
final String value2) {
|
||||
final int key1AsInt = put(key1);
|
||||
final int value1AsInt = put(value1);
|
||||
|
||||
final int key2AsInt = put(key2);
|
||||
final int value2AsInt = put(value2);
|
||||
|
||||
final Tags result = TagsBuilder.create().add(key1AsInt, value1AsInt).add(key2AsInt, value2AsInt).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Tags createAndAddToDictionary(final String key1, final String value1, final String key2, final String value2,
|
||||
final String key3, final String value3) {
|
||||
|
||||
final int key1AsInt = put(key1);
|
||||
final int value1AsInt = put(value1);
|
||||
|
||||
final int key2AsInt = put(key2);
|
||||
final int value2AsInt = put(value2);
|
||||
|
||||
final int key3AsInt = put(key3);
|
||||
final int value3AsInt = put(value3);
|
||||
|
||||
final Tags result = TagsBuilder.create().add(key1AsInt, value1AsInt).add(key2AsInt, value2AsInt)
|
||||
.add(key3AsInt, value3AsInt).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
public Tags createAndAddToDictionary(final String key1, final String value1, final String key2, final String value2,
|
||||
final String key3, final String value3, final String key4, final String value4) {
|
||||
|
||||
final int key1AsInt = put(key1);
|
||||
final int value1AsInt = put(value1);
|
||||
|
||||
final int key2AsInt = put(key2);
|
||||
final int value2AsInt = put(value2);
|
||||
|
||||
final int key3AsInt = put(key3);
|
||||
final int value3AsInt = put(value3);
|
||||
|
||||
final int key4AsInt = put(key4);
|
||||
final int value4AsInt = put(value4);
|
||||
|
||||
final Tags result = TagsBuilder.create().add(key1AsInt, value1AsInt).add(key2AsInt, value2AsInt)
|
||||
.add(key3AsInt, value3AsInt).add(key4AsInt, value4AsInt).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,33 +60,6 @@ public class Tags implements Comparable<Tags> {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Tags createAndAddToDictionary(final String key, final String value) {
|
||||
|
||||
return TagsBuilder.create().addAndAddToDictionary(key, value).build();
|
||||
}
|
||||
|
||||
public static Tags createAndAddToDictionary(final String key1, final String value1, final String key2,
|
||||
final String value2) {
|
||||
|
||||
final Tags result = TagsBuilder.create().addAndAddToDictionary(key1, value1).addAndAddToDictionary(key2, value2)
|
||||
.build();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Tags createAndAddToDictionary(final String key1, final String value1, final String key2,
|
||||
final String value2, final String key3, final String value3) {
|
||||
final Tags result = TagsBuilder.create().addAndAddToDictionary(key1, value1).addAndAddToDictionary(key2, value2)
|
||||
.addAndAddToDictionary(key3, value3).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Tags createAndAddToDictionary(final String key1, final String value1, final String key2,
|
||||
final String value2, final String key3, final String value3, final String key4, final String value4) {
|
||||
final Tags result = TagsBuilder.create().addAndAddToDictionary(key1, value1).addAndAddToDictionary(key2, value2)
|
||||
.addAndAddToDictionary(key3, value3).addAndAddToDictionary(key4, value4).build();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static Tags fromBytes(final byte[] bytes) {
|
||||
final List<Tag> result = new ArrayList<>();
|
||||
|
||||
|
||||
@@ -30,12 +30,6 @@ public class TagsBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TagsBuilder addAndAddToDictionary(final String key, final String value) {
|
||||
final int keyAsInt = Tags.STRING_COMPRESSOR.put(key);
|
||||
final int valueAsInt = Tags.STRING_COMPRESSOR.put(value);
|
||||
return add(keyAsInt, valueAsInt);
|
||||
}
|
||||
|
||||
public Tags build() {
|
||||
return Tags.create(tags);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.lucares.pdb.api.StringCompressor;
|
||||
import org.lucares.pdb.api.Tag;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.api.TagsBuilder;
|
||||
import org.lucares.pdb.api.UniqueStringIntegerPairs;
|
||||
@@ -72,23 +73,23 @@ public class MemoryScale {
|
||||
}
|
||||
}
|
||||
|
||||
private static Object createTag() {
|
||||
private static Tag createTag() {
|
||||
return Tags.STRING_COMPRESSOR.createTag("", "");
|
||||
}
|
||||
|
||||
private static Object createTags0() {
|
||||
private static Tags createTags0() {
|
||||
return new Tags();
|
||||
}
|
||||
|
||||
private static Object createTags1() {
|
||||
return Tags.createAndAddToDictionary("k1", "v1");
|
||||
private static Tags createTags1() {
|
||||
return Tags.STRING_COMPRESSOR.createAndAddToDictionary("k1", "v1");
|
||||
}
|
||||
|
||||
private static Object createTags2() {
|
||||
return Tags.createAndAddToDictionary("k1", "v1", "k2", "v2");
|
||||
private static Tags createTags2() {
|
||||
return Tags.STRING_COMPRESSOR.createAndAddToDictionary("k1", "v1", "k2", "v2");
|
||||
}
|
||||
|
||||
private static Object createTags6() {
|
||||
private static Tags createTags6() {
|
||||
final TagsBuilder result = TagsBuilder.create();
|
||||
|
||||
result.add(Tags.STRING_COMPRESSOR.createTag("k1", "v1"));
|
||||
|
||||
@@ -13,6 +13,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
@@ -24,7 +25,6 @@ import org.lucares.pdb.api.Query;
|
||||
import org.lucares.pdb.api.Result;
|
||||
import org.lucares.pdb.api.Tags;
|
||||
import org.lucares.pdb.datastore.Entry;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.lucares.utils.DateUtils;
|
||||
|
||||
public class PerformanceDbTest {
|
||||
@@ -48,7 +48,7 @@ public class PerformanceDbTest {
|
||||
final OffsetDateTime nowInUtc = DateUtils.nowInUtc();
|
||||
final long date = nowInUtc.toInstant().toEpochMilli();
|
||||
final long value = 1;
|
||||
final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
|
||||
final Tags tags = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "myValue");
|
||||
db.putEntry(new Entry(date, value, tags));
|
||||
|
||||
final Result result = db.get(Query.createQuery(tags, DateTimeRange.ofDay(nowInUtc)));
|
||||
@@ -71,7 +71,7 @@ public class PerformanceDbTest {
|
||||
final long dayTwo = dateRange.getEndEpochMilli();
|
||||
final long valueOne = 1;
|
||||
final long valueTwo = 2;
|
||||
final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
|
||||
final Tags tags = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "myValue");
|
||||
|
||||
db.putEntry(new Entry(dayOne, valueOne, tags));
|
||||
db.putEntry(new Entry(dayTwo, valueTwo, tags));
|
||||
@@ -116,7 +116,7 @@ public class PerformanceDbTest {
|
||||
|
||||
final DateTimeRange timeRange = DateTimeRange.ofDay(DateUtils.getDate(year, month, day, 1, 1, 1));
|
||||
|
||||
final Tags tags = Tags.createAndAddToDictionary("myKey", "one");
|
||||
final Tags tags = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "one");
|
||||
final List<Entry> entries = generateEntries(timeRange, numberOfEntries, 0, tags);
|
||||
|
||||
printEntries(entries, "");
|
||||
@@ -149,7 +149,7 @@ public class PerformanceDbTest {
|
||||
final int month = 1;
|
||||
final int day = 2;
|
||||
|
||||
tags = Tags.createAndAddToDictionary("myKey", "one");
|
||||
tags = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "one");
|
||||
final DateTimeRange timeRange = DateTimeRange.ofDay(DateUtils.getDate(year, month, day, 1, 1, 1));
|
||||
|
||||
final List<Entry> entries = generateEntries(timeRange, numberOfEntries, 0, tags);
|
||||
@@ -185,18 +185,21 @@ public class PerformanceDbTest {
|
||||
final DateTimeRange dateRange = new DateTimeRange(from, to);
|
||||
final long numberOfEntries = timeRange.duration().toHours();
|
||||
|
||||
final Tags tagsCommon = Tags.createAndAddToDictionary("commonKey", "commonValue");
|
||||
final Tags tagsOne = Tags.createAndAddToDictionary("myKey", "one", "commonKey", "commonValue");
|
||||
final Tags tagsCommon = Tags.STRING_COMPRESSOR.createAndAddToDictionary("commonKey", "commonValue");
|
||||
final Tags tagsOne = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "one", "commonKey",
|
||||
"commonValue");
|
||||
final List<Entry> entriesOne = generateEntries(timeRange, numberOfEntries, 1, tagsOne);
|
||||
db.putEntries(entriesOne);
|
||||
printEntries(entriesOne, "one");
|
||||
|
||||
final Tags tagsTwo = Tags.createAndAddToDictionary("myKey", "two", "commonKey", "commonValue");
|
||||
final Tags tagsTwo = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "two", "commonKey",
|
||||
"commonValue");
|
||||
final List<Entry> entriesTwo = generateEntries(timeRange, numberOfEntries, 2, tagsTwo);
|
||||
printEntries(entriesTwo, "two");
|
||||
db.putEntries(entriesTwo);
|
||||
|
||||
final Tags tagsThree = Tags.createAndAddToDictionary("myKey", "three", "commonKey", "commonValue");
|
||||
final Tags tagsThree = Tags.STRING_COMPRESSOR.createAndAddToDictionary("myKey", "three", "commonKey",
|
||||
"commonValue");
|
||||
final List<Entry> entriesThree = generateEntries(timeRange, numberOfEntries, 3, tagsThree);
|
||||
printEntries(entriesThree, "three");
|
||||
db.putEntries(entriesThree);
|
||||
@@ -233,9 +236,11 @@ public class PerformanceDbTest {
|
||||
final long numberOfEntries = timeRange.duration().toHours();
|
||||
|
||||
final String key = "myKey";
|
||||
final Tags tagsOne = Tags.createAndAddToDictionary(key, "one", "commonKey", "commonValue");
|
||||
final Tags tagsTwo = Tags.createAndAddToDictionary(key, "two", "commonKey", "commonValue");
|
||||
final Tags tagsThree = Tags.createAndAddToDictionary("commonKey", "commonValue");
|
||||
final Tags tagsOne = Tags.STRING_COMPRESSOR.createAndAddToDictionary(key, "one", "commonKey",
|
||||
"commonValue");
|
||||
final Tags tagsTwo = Tags.STRING_COMPRESSOR.createAndAddToDictionary(key, "two", "commonKey",
|
||||
"commonValue");
|
||||
final Tags tagsThree = Tags.STRING_COMPRESSOR.createAndAddToDictionary("commonKey", "commonValue");
|
||||
final LongList entriesOne = storeEntries(db, timeRange, numberOfEntries, tagsOne, 1);
|
||||
final LongList entriesTwo = storeEntries(db, timeRange, numberOfEntries, tagsTwo, 2);
|
||||
final LongList entriesThree = storeEntries(db, timeRange, numberOfEntries, tagsThree, 3);
|
||||
@@ -247,9 +252,9 @@ public class PerformanceDbTest {
|
||||
for (final GroupResult groupResult : groups) {
|
||||
final Tags groupedBy = groupResult.getGroupedBy();
|
||||
|
||||
if (groupedBy.equals(Tags.createAndAddToDictionary(key, "one"))) {
|
||||
if (groupedBy.equals(Tags.STRING_COMPRESSOR.createAndAddToDictionary(key, "one"))) {
|
||||
Assertions.assertEquals(entriesOne, groupResult.flatMap());
|
||||
} else if (groupedBy.equals(Tags.createAndAddToDictionary(key, "two"))) {
|
||||
} else if (groupedBy.equals(Tags.STRING_COMPRESSOR.createAndAddToDictionary(key, "two"))) {
|
||||
|
||||
Assertions.assertEquals(entriesTwo, groupResult.flatMap());
|
||||
} else if (groupedBy.isEmpty()) {
|
||||
@@ -272,10 +277,14 @@ public class PerformanceDbTest {
|
||||
|
||||
final String key1 = "myKey1";
|
||||
final String key2 = "myKey2";
|
||||
final Tags tagsOne = Tags.createAndAddToDictionary(key1, "one", key2, "aaa", "commonKey", "commonValue");
|
||||
final Tags tagsTwoA = Tags.createAndAddToDictionary(key1, "two", key2, "bbb", "commonKey", "commonValue");
|
||||
final Tags tagsTwoB = Tags.createAndAddToDictionary(key1, "two", key2, "bbb", "commonKey", "commonValue");
|
||||
final Tags tagsThree = Tags.createAndAddToDictionary(key1, "three", "commonKey", "commonValue");
|
||||
final Tags tagsOne = Tags.STRING_COMPRESSOR.createAndAddToDictionary(key1, "one", key2, "aaa", "commonKey",
|
||||
"commonValue");
|
||||
final Tags tagsTwoA = Tags.STRING_COMPRESSOR.createAndAddToDictionary(key1, "two", key2, "bbb", "commonKey",
|
||||
"commonValue");
|
||||
final Tags tagsTwoB = Tags.STRING_COMPRESSOR.createAndAddToDictionary(key1, "two", key2, "bbb", "commonKey",
|
||||
"commonValue");
|
||||
final Tags tagsThree = Tags.STRING_COMPRESSOR.createAndAddToDictionary(key1, "three", "commonKey",
|
||||
"commonValue");
|
||||
|
||||
final LongList entriesOne = storeEntries(db, timeRange, numberOfEntries, tagsOne, 1);
|
||||
final LongList entriesTwo = storeEntries(db, timeRange, numberOfEntries, tagsTwoA, 2);
|
||||
@@ -290,9 +299,10 @@ public class PerformanceDbTest {
|
||||
for (final GroupResult groupResult : groups) {
|
||||
final Tags groupedBy = groupResult.getGroupedBy();
|
||||
|
||||
if (groupedBy.equals(Tags.createAndAddToDictionary(key1, "one", key2, "aaa"))) {
|
||||
if (groupedBy.equals(Tags.STRING_COMPRESSOR.createAndAddToDictionary(key1, "one", key2, "aaa"))) {
|
||||
Assertions.assertEquals(entriesOne, groupResult.flatMap());
|
||||
} else if (groupedBy.equals(Tags.createAndAddToDictionary(key1, "two", key2, "bbb"))) {
|
||||
} else if (groupedBy
|
||||
.equals(Tags.STRING_COMPRESSOR.createAndAddToDictionary(key1, "two", key2, "bbb"))) {
|
||||
// there is no defined order of the entries.
|
||||
// eventually we might return them in ascending order, but
|
||||
// that is not yet implemented
|
||||
@@ -302,7 +312,7 @@ public class PerformanceDbTest {
|
||||
actualEntries.sort();
|
||||
|
||||
Assertions.assertEquals(entriesTwo, actualEntries);
|
||||
} else if (groupedBy.equals(Tags.createAndAddToDictionary(key1, "three"))) {
|
||||
} else if (groupedBy.equals(Tags.STRING_COMPRESSOR.createAndAddToDictionary(key1, "three"))) {
|
||||
Assertions.assertEquals(entriesThree, groupResult.flatMap());
|
||||
} else {
|
||||
Assertions.fail("unexpected group: " + groupedBy);
|
||||
|
||||
Reference in New Issue
Block a user