diff --git a/build.gradle b/build.gradle index da5d8bbd..5e7dfbe1 100644 --- a/build.gradle +++ b/build.gradle @@ -6,6 +6,7 @@ project.group = 'com.codingchili' subprojects { apply plugin: 'java' + apply plugin: 'maven' apply plugin: 'idea' version = rootProject.version diff --git a/core/build.gradle b/core/build.gradle index 245c1ce6..b39d82b6 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -1,41 +1,43 @@ -task sourcesJar(type: Jar) { - classifier 'sources' - from sourceSets.main.allSource -} - -jar { - from { - (configurations.runtime).collect { - it.isDirectory() ? it : zipTree(it) - } - } - manifest { - attributes 'Implementation-Title': 'chili-core', - 'Implementation-Version': version, - 'Main-Class': 'com.codingchili.core.Launcher' - } -} - -test { - maxHeapSize = "512m" -} - -dependencies { - compile group: 'junit', name: 'junit', version: '4.12' - compile group: 'io.vertx', name: 'vertx-core', version: '3.4.1' - compile group: 'io.vertx', name: 'vertx-unit', version: '3.4.1' - compile group: 'io.vertx', name: 'vertx-web', version: '3.4.1' - compile group: 'io.vertx', name: 'vertx-hazelcast', version: '3.4.1' - compile group: 'io.vertx', name: 'vertx-mongo-client', version: '3.4.1' - compile group: 'io.vertx', name: 'vertx-dropwizard-metrics', version: '3.4.1' - compile group: 'de.neuland-bfi', name: 'jade4j', version: '1.2.5' - compile group: 'de.mkammerer', name: 'argon2-jvm', version: '2.2' - compile group: 'org.fusesource.jansi', name: 'jansi', version: '1.14' - - // the following dependencies are about 25MB in size.. - compile group: 'org.elasticsearch.client', name: 'transport', version: '5.3.0' - compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.6.2' - compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.6.2' - - compile group: 'com.googlecode.cqengine', name: 'cqengine', version: '2.9.3' -} +task sourcesJar(type: Jar) { + classifier 'sources' + from sourceSets.main.allSource +} + +install.dependsOn jar + +jar { + from { + (configurations.runtime).collect { + it.isDirectory() ? it : zipTree(it) + } + } + manifest { + attributes 'Implementation-Title': 'chili-core', + 'Implementation-Version': version, + 'Main-Class': 'com.codingchili.core.Launcher' + } +} + +test { + maxHeapSize = "512m" +} + +dependencies { + compile group: 'junit', name: 'junit', version: '4.12' + compile group: 'io.vertx', name: 'vertx-core', version: '3.4.2' + compile group: 'io.vertx', name: 'vertx-unit', version: '3.4.2' + compile group: 'io.vertx', name: 'vertx-web', version: '3.4.2' + compile group: 'io.vertx', name: 'vertx-hazelcast', version: '3.4.2' + compile group: 'io.vertx', name: 'vertx-mongo-client', version: '3.4.2' + compile group: 'io.vertx', name: 'vertx-dropwizard-metrics', version: '3.4.2' + compile group: 'de.neuland-bfi', name: 'jade4j', version: '1.2.5' + compile group: 'de.mkammerer', name: 'argon2-jvm', version: '2.2' + compile group: 'org.fusesource.jansi', name: 'jansi', version: '1.14' + + // the following dependencies are about 25MB in size.. + compile group: 'org.elasticsearch.client', name: 'transport', version: '5.3.0' + compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.6.2' + compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.6.2' + + compile group: 'com.googlecode.cqengine', name: 'cqengine', version: '2.12.1' +} diff --git a/core/main/java/com/codingchili/core/storage/IndexedMap.java b/core/main/java/com/codingchili/core/storage/IndexedMap.java index 404e2c05..6613ac08 100644 --- a/core/main/java/com/codingchili/core/storage/IndexedMap.java +++ b/core/main/java/com/codingchili/core/storage/IndexedMap.java @@ -2,7 +2,6 @@ import com.codingchili.core.context.StorageContext; import com.codingchili.core.protocol.Serializer; -import com.codingchili.core.security.Account; import com.codingchili.core.storage.exception.NothingToRemoveException; import com.codingchili.core.storage.exception.NothingToReplaceException; import com.codingchili.core.storage.exception.ValueAlreadyPresentException; @@ -46,7 +45,7 @@ public abstract class IndexedMap implements AsyncStorage private SharedIndexCollection db; @SuppressWarnings("unchecked") - protected IndexedMap(Future> future, StorageContext context) { + public IndexedMap(Future> future, StorageContext context) { this.context = context; FIELD_ID = attribute(context.clazz(), String.class, Storable.idField, Storable::id); fields.put(Storable.idField, FIELD_ID); diff --git a/core/main/java/com/codingchili/core/storage/IndexedMapVolatile.java b/core/main/java/com/codingchili/core/storage/IndexedMapVolatile.java index f69a0a3e..f94175d9 100644 --- a/core/main/java/com/codingchili/core/storage/IndexedMapVolatile.java +++ b/core/main/java/com/codingchili/core/storage/IndexedMapVolatile.java @@ -11,7 +11,7 @@ */ public class IndexedMapVolatile extends IndexedMap { - protected IndexedMapVolatile(Future> future, StorageContext context) { + public IndexedMapVolatile(Future> future, StorageContext context) { super(future, context); } diff --git a/core/main/java/com/codingchili/core/testing/MapTestCases.java b/core/main/java/com/codingchili/core/testing/MapTestCases.java index ffde3266..ca3469a7 100644 --- a/core/main/java/com/codingchili/core/testing/MapTestCases.java +++ b/core/main/java/com/codingchili/core/testing/MapTestCases.java @@ -162,10 +162,13 @@ public void testPut(TestContext test) { store.put(OBJECT_ONE, put -> { test.assertTrue(put.succeeded()); - store.get(ONE, get -> { - test.assertEquals(OBJECT_ONE, get.result()); - test.assertTrue(get.succeeded()); - async.complete(); + store.size(size -> { + test.assertEquals(TEST_ITEM_COUNT.intValue(), size.result()); + store.get(ONE, get -> { + test.assertEquals(OBJECT_ONE, get.result()); + test.assertTrue(get.succeeded()); + async.complete(); + }); }); }); } diff --git a/core/main/java/com/codingchili/core/testing/StorageObject.java b/core/main/java/com/codingchili/core/testing/StorageObject.java index f451a949..49dea812 100644 --- a/core/main/java/com/codingchili/core/testing/StorageObject.java +++ b/core/main/java/com/codingchili/core/testing/StorageObject.java @@ -1,97 +1,98 @@ -package com.codingchili.core.testing; - -import java.util.ArrayList; -import java.util.List; - -import com.codingchili.core.storage.Storable; - -/** - * @author Robin Duda - *

- * Test class to simulate a stored object. - */ -public class StorageObject implements Storable { - public static final String NESTED_PREFIX = "nested."; - public static String levelField = "level"; - private String name; - private Integer level; - private NestedObject nested; - private List keywords = new ArrayList<>(); - - public StorageObject() { - keywords.add("Z"); - } - - public StorageObject(String name, Integer level) { - this(); - this.name = name; - this.level = level; - this.nested = new NestedObject(NESTED_PREFIX + name); - } - - public Integer getLevel() { - return level; - } - - public StorageObject setLevel(Integer level) { - this.level = level; - return this; - } - - public String id() { - return name; - } - - public String getName() { - return name; - } - - public StorageObject setName(String name) { - this.name = name; - return this; - } - - public NestedObject getNested() { - return nested; - } - - public void setNested(NestedObject nested) { - this.nested = nested; - } - - public List getKeywords() { - return keywords; - } - - public void setKeywords(List keywords) { - this.keywords = keywords; - } - - public String toString() { - return "name=" + name + " " + "level=" + level; - } - - @Override - public int hashCode() { - return name.hashCode(); - } - - @Override - public boolean equals(Object other) { - return compareTo(other) == 0; - } - - @Override - public int compareToAttribute(Storable other, String attribute) { - StorageObject item = (StorageObject) other; - - switch (attribute) { - case "level": - return level.compareTo(item.getLevel()); - case "nested.name": - return nested.getName().compareTo(item.getNested().getName()); - default: - return 0; - } - } -} +package com.codingchili.core.testing; + +import java.util.ArrayList; +import java.util.List; + +import com.codingchili.core.storage.Storable; + +/** + * @author Robin Duda + *

+ * Test class to simulate a stored object. + */ +public class StorageObject implements Storable { + public static final String NESTED_PREFIX = "nested."; + public static String levelField = "level"; + private String name; + private Integer level; + private NestedObject nested; + private List keywords = new ArrayList<>(); + + public StorageObject() { + keywords.add("Z"); + } + + public StorageObject(String name, Integer level) { + this(); + this.name = name; + this.level = level; + this.nested = new NestedObject(NESTED_PREFIX + name); + } + + public Integer getLevel() { + return level; + } + + public StorageObject setLevel(Integer level) { + this.level = level; + return this; + } + + @Override + public String id() { + return name; + } + + public String getName() { + return name; + } + + public StorageObject setName(String name) { + this.name = name; + return this; + } + + public NestedObject getNested() { + return nested; + } + + public void setNested(NestedObject nested) { + this.nested = nested; + } + + public List getKeywords() { + return keywords; + } + + public void setKeywords(List keywords) { + this.keywords = keywords; + } + + public String toString() { + return "name=" + name + " " + "level=" + level; + } + + @Override + public int hashCode() { + return name.hashCode(); + } + + @Override + public boolean equals(Object other) { + return compareTo(other) == 0; + } + + @Override + public int compareToAttribute(Storable other, String attribute) { + StorageObject item = (StorageObject) other; + + switch (attribute) { + case "level": + return level.compareTo(item.getLevel()); + case "nested.name": + return nested.getName().compareTo(item.getNested().getName()); + default: + return 0; + } + } +} diff --git a/core/test/java/com/codingchili/core/storage/ElasticMapIT.java b/core/test/java/com/codingchili/core/storage/ElasticMapIT.java index d0f383ae..4b48d6b0 100644 --- a/core/test/java/com/codingchili/core/storage/ElasticMapIT.java +++ b/core/test/java/com/codingchili/core/storage/ElasticMapIT.java @@ -1,71 +1,71 @@ -package com.codingchili.core.storage; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.runner.RunWith; - -import com.codingchili.core.testing.MapTestCases; - -import io.vertx.ext.unit.Async; -import io.vertx.ext.unit.TestContext; -import io.vertx.ext.unit.junit.VertxUnitRunner; - -/** - * @author Robin Duda - *

- * Tests for the storage providers in core. Reuse these tests when new - * storage subsystems are implemented using the StorageLoader. - */ -@Ignore("Requires running elasticsearch 5.2.2, travis runs an older version.") -@RunWith(VertxUnitRunner.class) -public class ElasticMapIT extends MapTestCases { - private static final int ELASTIC_REFRESH = 1200; - - public ElasticMapIT() { - /** - * sets a STARTUP_DELAY between initializing the database and starting the tests. - * This is required as elasticsearch is near-real-time only. - */ - STARTUP_DELAY = ELASTIC_REFRESH; - } - - @Before - public void setUp(TestContext test) { - super.setUp(test, ElasticMap.class); - } - - @After - public void tearDown(TestContext test) { - super.tearDown(test); - } - - /** - * elasticsearch is near-realtime which means that clear does not return realtime results. - */ - @Override - @Test - public void testClear(TestContext test) { - Async async = test.async(); - - store.clear(clear -> { - test.assertTrue(clear.succeeded()); - - context.timer(ELASTIC_REFRESH, event -> store.size(size -> { - test.assertFalse(size.succeeded(), "should fail to count on missing index."); - async.complete(); - })); - }); - } - - @Ignore("Searching with case sensitivity is not supported for ElasticSearch.") - @Override - public void testCaseSensitivityEqualsNotIgnored(TestContext test) { - } - - @Ignore("Querying nested fields cannot be combined with sorting, without loading field-data into memory.") - @Override - public void testSortByNestedField(TestContext test) { - } -} +package com.codingchili.core.storage; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +import com.codingchili.core.testing.MapTestCases; + +import io.vertx.ext.unit.Async; +import io.vertx.ext.unit.TestContext; +import io.vertx.ext.unit.junit.VertxUnitRunner; + +/** + * @author Robin Duda + *

+ * Tests for the storage providers in core. Reuse these tests when new + * storage subsystems are implemented using the StorageLoader. + */ +@Ignore("Requires running elasticsearch 5.3, travis runs an older version.") +@RunWith(VertxUnitRunner.class) +public class ElasticMapIT extends MapTestCases { + private static final int ELASTIC_REFRESH = 1200; + + public ElasticMapIT() { + /** + * sets a STARTUP_DELAY between initializing the database and starting the tests. + * This is required as elasticsearch is near-real-time only. + */ + STARTUP_DELAY = ELASTIC_REFRESH; + } + + @Before + public void setUp(TestContext test) { + super.setUp(test, ElasticMap.class); + } + + @After + public void tearDown(TestContext test) { + super.tearDown(test); + } + + /** + * elasticsearch is near-realtime which means that clear does not return realtime results. + */ + @Override + @Test + public void testClear(TestContext test) { + Async async = test.async(); + + store.clear(clear -> { + test.assertTrue(clear.succeeded()); + + context.timer(ELASTIC_REFRESH, event -> store.size(size -> { + test.assertFalse(size.succeeded(), "should fail to count on missing index."); + async.complete(); + })); + }); + } + + @Ignore("Searching with case sensitivity is not supported for ElasticSearch.") + @Override + public void testCaseSensitivityEqualsNotIgnored(TestContext test) { + } + + @Ignore("Querying nested fields cannot be combined with sorting, without loading field-data into memory.") + @Override + public void testSortByNestedField(TestContext test) { + } +} diff --git a/core/test/java/com/codingchili/core/storage/IndexedMapPersistedTest.java b/core/test/java/com/codingchili/core/storage/IndexedMapPersistedTest.java new file mode 100644 index 00000000..36ee8650 --- /dev/null +++ b/core/test/java/com/codingchili/core/storage/IndexedMapPersistedTest.java @@ -0,0 +1,34 @@ +package com.codingchili.core.storage; + +import com.codingchili.core.testing.MapTestCases; +import io.vertx.ext.unit.TestContext; +import io.vertx.ext.unit.junit.VertxUnitRunner; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * @author Robin Duda + *

+ * Tests for the CQEngine indexed storage. + */ +@RunWith(VertxUnitRunner.class) +public class IndexedMapPersistedTest extends MapTestCases { + + @Before + public void setUp(TestContext test) { + super.setUp(test, IndexedMapVolatile.class); + } + + @After + public void tearDown(TestContext test) { + super.tearDown(test); + } + + @Ignore("Does not support mixing multiple modes of restricted character cases.") + @Test + public void testCaseSensitivityEqualsNotIgnored(TestContext test) { + } +} diff --git a/core/test/java/com/codingchili/core/storage/IndexedMapTest.java b/core/test/java/com/codingchili/core/storage/IndexedMapVolatileTest.java similarity index 93% rename from core/test/java/com/codingchili/core/storage/IndexedMapTest.java rename to core/test/java/com/codingchili/core/storage/IndexedMapVolatileTest.java index ca9b1f53..bf162fe0 100644 --- a/core/test/java/com/codingchili/core/storage/IndexedMapTest.java +++ b/core/test/java/com/codingchili/core/storage/IndexedMapVolatileTest.java @@ -21,7 +21,7 @@ * Tests for the CQEngine indexed storage. */ @RunWith(VertxUnitRunner.class) -public class IndexedMapTest extends MapTestCases { +public class IndexedMapVolatileTest extends MapTestCases { private static final String TEST_UPPER = "testUPPER"; @Before