http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/itests/src/test/java/org/oasis_open/contextserver/itests/ConditionESQueryBuilderTest.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/oasis_open/contextserver/itests/ConditionESQueryBuilderTest.java b/itests/src/test/java/org/oasis_open/contextserver/itests/ConditionESQueryBuilderTest.java deleted file mode 100644 index 15ef9ad..0000000 --- a/itests/src/test/java/org/oasis_open/contextserver/itests/ConditionESQueryBuilderTest.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package org.oasis_open.contextserver.itests; - -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.runner.RunWith; -import org.oasis_open.contextserver.api.Item; -import org.oasis_open.contextserver.api.conditions.Condition; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; -import org.ops4j.pax.exam.spi.reactors.PerSuite; - -/** - * Integration tests for various condition query builder types (elasticsearch). - * - * @author Sergiy Shyrkov - */ -@RunWith(PaxExam.class) -@ExamReactorStrategy(PerSuite.class) -public class ConditionESQueryBuilderTest extends ConditionEvaluatorTest { - - @Override - protected boolean eval(Condition c) { - @SuppressWarnings("unchecked") - List<Item> list = persistenceService.query(c,null,(Class<Item>) item.getClass()); - return list.contains(item); - } - - @Before - public void setUp() { - super.setUp(); - persistenceService.save(item); - persistenceService.refresh(); - } - - @After - public void tearDown() { - persistenceService.remove(item.getItemId(), item.getClass()); - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/itests/src/test/java/org/oasis_open/contextserver/itests/ConditionEvaluatorTest.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/oasis_open/contextserver/itests/ConditionEvaluatorTest.java b/itests/src/test/java/org/oasis_open/contextserver/itests/ConditionEvaluatorTest.java deleted file mode 100644 index d5e2b73..0000000 --- a/itests/src/test/java/org/oasis_open/contextserver/itests/ConditionEvaluatorTest.java +++ /dev/null @@ -1,184 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package org.oasis_open.contextserver.itests; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.*; - -import javax.inject.Inject; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.oasis_open.contextserver.api.Item; -import org.oasis_open.contextserver.api.Profile; -import org.oasis_open.contextserver.api.conditions.Condition; -import org.oasis_open.contextserver.api.services.DefinitionsService; -import org.oasis_open.contextserver.persistence.spi.PersistenceService; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; -import org.ops4j.pax.exam.spi.reactors.PerSuite; - -/** - * Integration tests for various condition types. - * - * @author Sergiy Shyrkov - */ -@RunWith(PaxExam.class) -@ExamReactorStrategy(PerSuite.class) -public class ConditionEvaluatorTest extends BaseTest { - - protected ConditionBuilder builder; - - @Inject - private DefinitionsService definitionsService; - - @Inject - protected PersistenceService persistenceService; - - protected Item item; - protected Date lastVisit; - - protected boolean eval(Condition c) { - return persistenceService.testMatch(c, item); - } - - @Before - public void setUp() { - assertNotNull("Definition service should be available", definitionsService); - assertNotNull("Persistence service should be available", persistenceService); - - lastVisit = new GregorianCalendar(2015,1,1,20,30,0).getTime(); - - Profile profile = new Profile("profile-" + UUID.randomUUID().toString()); - profile.setProperty("firstVisit", lastVisit); - profile.setProperty("age", Integer.valueOf(30)); - profile.setProperty("gender", "female"); - profile.setProperty("lastVisit", lastVisit); - profile.setSegments(new HashSet<String>(Arrays.asList("s1", "s2", "s3"))); - this.item = profile; - builder = new ConditionBuilder(definitionsService); - } - - @Test - public void testCompound() { - // test AND - assertTrue(eval(builder.and(builder.profileProperty("properties.gender").equalTo("female"), - builder.profileProperty("properties.age").equalTo(Integer.valueOf(30))).build())); - assertFalse(eval(builder.and(builder.profileProperty("properties.gender").equalTo("male"), - builder.profileProperty("properties.age").equalTo(Integer.valueOf(30))).build())); - assertFalse(eval(builder.and(builder.profileProperty("properties.gender").equalTo("female"), - builder.profileProperty("properties.age").equalTo(Integer.valueOf(40))).build())); - - // test OR - assertTrue(eval(builder.or(builder.profileProperty("properties.gender").equalTo("female"), - builder.profileProperty("properties.age").equalTo(Integer.valueOf(40))).build())); - assertTrue(eval(builder.or(builder.profileProperty("properties.gender").equalTo("male"), - builder.profileProperty("properties.age").equalTo(Integer.valueOf(30))).build())); - assertFalse(eval(builder.or(builder.profileProperty("properties.gender").equalTo("male"), - builder.profileProperty("properties.age").equalTo(Integer.valueOf(40))).build())); - - // test NOT - assertTrue(eval(builder.not(builder.profileProperty("properties.gender").equalTo("male")).build())); - assertFalse(eval(builder.not(builder.profileProperty("properties.age").equalTo(Integer.valueOf(30))).build())); - - } - - @Test - public void testDate() { - assertTrue(eval(builder.profileProperty("properties.lastVisit").equalTo(lastVisit).build())); - assertTrue(eval(builder.profileProperty("properties.lastVisit") - .greaterThan(new Date(lastVisit.getTime() - 10000)).build())); - assertTrue(eval(builder.profileProperty("properties.lastVisit").lessThan(new Date(lastVisit.getTime() + 10000)) - .build())); - assertTrue(eval(builder.profileProperty("properties.lastVisit") - .in(new Date(lastVisit.getTime() + 10000), new Date(lastVisit.getTime() - 10000), lastVisit).build())); - assertTrue(eval(builder.profileProperty("properties.lastVisit") - .notIn(new Date(lastVisit.getTime() + 10000), new Date(lastVisit.getTime() - 10000)).build())); - assertFalse(eval(builder.profileProperty("properties.lastVisit") - .notIn(new Date(lastVisit.getTime() + 10000), new Date(lastVisit.getTime() - 10000), lastVisit).build())); - assertTrue(eval(builder.profileProperty("properties.lastVisit").all(lastVisit).build())); - assertFalse(eval(builder.profileProperty("properties.lastVisit") - .all(new Date(lastVisit.getTime() + 10000), lastVisit).build())); - } - - @Test - public void testExistence() { - assertTrue("Gender property does not exist", - eval(builder.profileProperty("properties.gender").exists().build())); - assertFalse("Gender property missing", eval(builder.profileProperty("properties.gender").missing().build())); - assertTrue("Strange property exists", eval(builder.profileProperty("properties.unknown").missing().build())); - assertFalse("Strange property exists", eval(builder.profileProperty("properties.unknown").exists().build())); - } - - @Test - public void testInteger() { - assertTrue(eval(builder.profileProperty("properties.age").equalTo(Integer.valueOf(30)).build())); - assertTrue(eval(builder.not(builder.profileProperty("properties.age").equalTo(Integer.valueOf(40))).build())); - assertTrue(eval(builder.profileProperty("properties.age").notEqualTo(Integer.valueOf(40)).build())); - assertTrue(eval(builder.profileProperty("properties.age").lessThan(Integer.valueOf(40)).build())); - assertTrue(eval(builder.profileProperty("properties.age").greaterThan(Integer.valueOf(20)).build())); - assertTrue(eval(builder.profileProperty("properties.age").greaterThanOrEqualTo(Integer.valueOf(30)).build())); - assertFalse(eval(builder.profileProperty("properties.age").greaterThanOrEqualTo(Integer.valueOf(31)).build())); - - assertTrue(eval(builder.profileProperty("properties.age").in(Integer.valueOf(30)).build())); - assertTrue(eval(builder.profileProperty("properties.age").in(Integer.valueOf(31), Integer.valueOf(30)).build())); - assertTrue(eval(builder.profileProperty("properties.age").notIn(Integer.valueOf(25), Integer.valueOf(26)) - .build())); - assertFalse(eval(builder.profileProperty("properties.age").notIn(Integer.valueOf(25), Integer.valueOf(30)) - .build())); - } - - @Test - public void testMultiValue() { - assertTrue(eval(builder.property("profileSegmentCondition", "segments").parameter("matchType", "in") - .parameter("segments", "s10", "s20", "s2").build())); - assertFalse(eval(builder.property("profileSegmentCondition", "segments").parameter("matchType", "in") - .parameter("segments", "s10", "s20", "s30").build())); - assertTrue(eval(builder.property("profileSegmentCondition", "segments").parameter("matchType", "notIn") - .parameter("segments", "s10", "s20", "s30").build())); - assertFalse(eval(builder.property("profileSegmentCondition", "segments").parameter("matchType", "notIn") - .parameter("segments", "s10", "s20", "s2").build())); - assertTrue(eval(builder.property("profileSegmentCondition", "segments").parameter("matchType", "all") - .parameter("segments", "s1", "s2").build())); - assertFalse(eval(builder.property("profileSegmentCondition", "segments").parameter("matchType", "all") - .parameter("segments", "s1", "s5").build())); - } - - @Test - public void testString() { - assertTrue(eval(builder.profileProperty("properties.gender").equalTo("female").build())); - assertFalse(eval(builder.not(builder.profileProperty("properties.gender").equalTo("female")).build())); - assertTrue(eval(builder.profileProperty("properties.gender").notEqualTo("male").build())); -// assertFalse(eval(builder.not(builder.profileProperty("properties.gender").notEqualTo("male")).build())); - assertTrue(eval(builder.profileProperty("properties.gender").startsWith("fe").build())); - assertTrue(eval(builder.profileProperty("properties.gender").endsWith("le").build())); - assertTrue(eval(builder.profileProperty("properties.gender").contains("fem").build())); - assertFalse(eval(builder.profileProperty("properties.gender").contains("mu").build())); - assertTrue(eval(builder.profileProperty("properties.gender").matchesRegex(".*ale").build())); - - assertTrue(eval(builder.profileProperty("properties.gender").in("male", "female").build())); - assertTrue(eval(builder.profileProperty("properties.gender").notIn("one", "two").build())); - assertFalse(eval(builder.profileProperty("properties.gender").notIn("one", "two", "female").build())); - assertTrue(eval(builder.profileProperty("properties.gender").all("female").build())); - assertFalse(eval(builder.profileProperty("properties.gender").all("male", "female").build())); - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/itests/src/test/java/org/oasis_open/contextserver/itests/SegmentTest.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/oasis_open/contextserver/itests/SegmentTest.java b/itests/src/test/java/org/oasis_open/contextserver/itests/SegmentTest.java deleted file mode 100644 index 3a430c2..0000000 --- a/itests/src/test/java/org/oasis_open/contextserver/itests/SegmentTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package org.oasis_open.contextserver.itests; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.oasis_open.contextserver.api.Metadata; -import org.oasis_open.contextserver.api.services.SegmentService; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; -import org.ops4j.pax.exam.spi.reactors.PerSuite; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import java.util.List; - -@RunWith(PaxExam.class) -@ExamReactorStrategy(PerSuite.class) -public class SegmentTest extends BaseTest{ - private final static Logger LOGGER = LoggerFactory.getLogger(SegmentTest.class); - @Inject - protected SegmentService segmentService; - - @Test - public void testSegments() { - Assert.assertNotNull("Segment service should be available", segmentService); - List<Metadata> segmentMetadatas = segmentService.getSegmentMetadatas(0, 50, null).getList(); - Assert.assertNotEquals("Segment metadata list should not be empty", 0, segmentMetadatas.size()); - LOGGER.info("Retrieved " + segmentMetadatas.size() + " segment metadata entries"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/itests/src/test/java/org/oasis_open/contextserver/itests/TestUtils.java ---------------------------------------------------------------------- diff --git a/itests/src/test/java/org/oasis_open/contextserver/itests/TestUtils.java b/itests/src/test/java/org/oasis_open/contextserver/itests/TestUtils.java deleted file mode 100644 index 539cae1..0000000 --- a/itests/src/test/java/org/oasis_open/contextserver/itests/TestUtils.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package org.oasis_open.contextserver.itests; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.http.HttpResponse; -import org.apache.http.util.EntityUtils; - -import java.io.IOException; - -public class TestUtils { - public static <T> T retrieveResourceFromResponse(HttpResponse response, Class<T> clazz) - throws IOException { - String jsonFromResponse = EntityUtils.toString(response.getEntity()); - ObjectMapper mapper = new ObjectMapper(). - configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - return mapper.readValue(jsonFromResponse, clazz); - } -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/package/pom.xml ---------------------------------------------------------------------- diff --git a/package/pom.xml b/package/pom.xml index 5533cc5..6e34bb9 100644 --- a/package/pom.xml +++ b/package/pom.xml @@ -15,7 +15,8 @@ ~ limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -145,7 +146,7 @@ <outputDirectory> ${project.build.directory}/assembly/etc </outputDirectory> - <destFileName>org.oasis_open.contextserver.web.cfg</destFileName> + <destFileName>org.apache.unomi.web.cfg</destFileName> </artifactItem> <artifactItem> <groupId>org.apache.unomi</groupId> @@ -156,7 +157,7 @@ <outputDirectory> ${project.build.directory}/assembly/etc </outputDirectory> - <destFileName>org.oasis_open.contextserver.persistence.elasticsearch.cfg</destFileName> + <destFileName>org.apache.unomi.persistence.elasticsearch.cfg</destFileName> </artifactItem> <artifactItem> <groupId>org.apache.unomi</groupId> @@ -178,7 +179,7 @@ <outputDirectory> ${project.build.directory}/assembly/etc </outputDirectory> - <destFileName>org.oasis_open.contextserver.plugins.request.cfg</destFileName> + <destFileName>org.apache.unomi.plugins.request.cfg</destFileName> </artifactItem> </artifactItems> <!-- other configurations here --> http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/performance-tests/src/test/java/org/apache/unomi/performancetests/BasicTest.java ---------------------------------------------------------------------- diff --git a/performance-tests/src/test/java/org/apache/unomi/performancetests/BasicTest.java b/performance-tests/src/test/java/org/apache/unomi/performancetests/BasicTest.java new file mode 100644 index 0000000..82a5b4f --- /dev/null +++ b/performance-tests/src/test/java/org/apache/unomi/performancetests/BasicTest.java @@ -0,0 +1,187 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +package org.apache.unomi.performancetests; + +import com.carrotsearch.junitbenchmarks.BenchmarkOptions; +import com.carrotsearch.junitbenchmarks.BenchmarkRule; +import com.carrotsearch.junitbenchmarks.WriterConsumer; +import org.apache.http.HttpEntity; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.apache.unomi.api.Metadata; +import org.apache.unomi.api.services.SegmentService; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TestRule; +import org.junit.runner.RunWith; +import org.ops4j.pax.exam.Configuration; +import org.ops4j.pax.exam.Option; +import org.ops4j.pax.exam.junit.PaxExam; +import org.ops4j.pax.exam.karaf.options.KarafDistributionOption; +import org.ops4j.pax.exam.options.MavenArtifactUrlReference; +import org.ops4j.pax.exam.options.MavenUrlReference; +import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; +import org.ops4j.pax.exam.spi.reactors.PerClass; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Inject; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.List; + +import static org.ops4j.pax.exam.CoreOptions.*; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; +import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder; + +@RunWith(PaxExam.class) +@ExamReactorStrategy(PerClass.class) +public class BasicTest { + + private final static Logger LOGGER = LoggerFactory.getLogger(BasicTest.class); + @Inject + protected SegmentService segmentService; + + /** + * Enables the benchmark rule. + */ + @Rule + public TestRule getBenchmarkRun() { + try { + File benchmarks = new File("../../benchmarks"); + benchmarks.mkdirs(); + return new BenchmarkRule(new WriterConsumer(new FileWriter(new File(benchmarks,"benchmark.txt"),true))); + } catch (IOException e) { + LOGGER.error("Cannot get benchamrks",e); + } + return null; + } + + @Configuration + public Option[] config() { + MavenArtifactUrlReference karafUrl = maven() + .groupId("org.apache.karaf") + .artifactId("apache-karaf") + .version("3.0.1") + .type("tar.gz"); + + MavenUrlReference karafStandardRepo = maven() + .groupId("org.apache.karaf.features") + .artifactId("standard") + .classifier("features") + .type("xml") + .versionAsInProject(); + MavenUrlReference karafPaxWebRepo = maven() + .groupId("org.ops4j.pax.web") + .artifactId("pax-web-features") + .classifier("features") + .type("xml") + .versionAsInProject(); + MavenUrlReference karafSpringRepo = maven() + .groupId("org.apache.karaf.features") + .artifactId("spring") + .classifier("features") + .type("xml") + .versionAsInProject(); + MavenUrlReference karafCxfRepo = maven() + .groupId("org.apache.cxf.karaf") + .artifactId("apache-cxf") + .classifier("features") + .type("xml") + .versionAsInProject(); + MavenUrlReference karafEnterpriseRepo = maven() + .groupId("org.apache.karaf.features") + .artifactId("enterprise") + .classifier("features") + .type("xml") + .versionAsInProject(); + MavenUrlReference contextServerRepo = maven() + .groupId("org.apache.unomi") + .artifactId("unomi-kar") + .classifier("features") + .type("xml") + .versionAsInProject(); + + return new Option[]{ + KarafDistributionOption.debugConfiguration("5005", false), + karafDistributionConfiguration() + .frameworkUrl(karafUrl) + .unpackDirectory(new File("target/exam")) + .useDeployFolder(false), + keepRuntimeFolder(), + KarafDistributionOption.features(karafPaxWebRepo, "war"), + KarafDistributionOption.features(karafCxfRepo, "cxf"), + KarafDistributionOption.features(karafStandardRepo, "openwebbeans"), + KarafDistributionOption.features(karafStandardRepo, "pax-cdi-web-openwebbeans"), + KarafDistributionOption.features(contextServerRepo, "unomi-kar"), + // we need to wrap the HttpComponents libraries ourselves since the OSGi bundles provided by the project are incorrect + wrappedBundle(mavenBundle("org.apache.httpcomponents", + "httpcore").versionAsInProject()), + wrappedBundle(mavenBundle("org.apache.httpcomponents", + "httpmime").versionAsInProject()), + wrappedBundle(mavenBundle("org.apache.httpcomponents", + "httpclient").versionAsInProject()), + wrappedBundle(mavenBundle("com.carrotsearch", + "junit-benchmarks", "0.7.2")), +// wrappedBundle(mavenBundle("com.h2database", +// "h2", "1.4.181")) + }; + } + + @BenchmarkOptions(benchmarkRounds = 100, warmupRounds = 0, concurrency = 10) + @Test + public void testContext() throws IOException { + + CloseableHttpClient httpclient = HttpClients.createDefault(); + HttpGet httpGet = new HttpGet("http://localhost:8181/context.js"); + CloseableHttpResponse response = httpclient.execute(httpGet); + // The underlying HTTP connection is still held by the response object + // to allow the response content to be streamed directly from the network socket. + // In order to ensure correct deallocation of system resources + // the user MUST call CloseableHttpResponse#close() from a finally clause. + // Please note that if response content is not fully consumed the underlying + // connection cannot be safely re-used and will be shut down and discarded + // by the connection manager. + String responseContent = null; + try { + HttpEntity entity = response.getEntity(); + // do something useful with the response body + // and ensure it is fully consumed + responseContent = EntityUtils.toString(entity); + } finally { + response.close(); + } + } + + @BenchmarkOptions(benchmarkRounds = 100, warmupRounds = 0, concurrency = 10) + @Test + public void testSegments() { + Assert.assertNotNull("Segment service should be available", segmentService); + List<Metadata> segmentMetadatas = segmentService.getSegmentMetadatas(0, 50, null).getList(); + Assert.assertNotEquals("Segment metadata list should not be empty", 0, segmentMetadatas.size()); + LOGGER.info("Retrieved " + segmentMetadatas.size() + " segment metadata entries"); + } + + + +} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/performance-tests/src/test/java/org/oasis_open/contextserver/performancetests/BasicTest.java ---------------------------------------------------------------------- diff --git a/performance-tests/src/test/java/org/oasis_open/contextserver/performancetests/BasicTest.java b/performance-tests/src/test/java/org/oasis_open/contextserver/performancetests/BasicTest.java deleted file mode 100644 index b87ad25..0000000 --- a/performance-tests/src/test/java/org/oasis_open/contextserver/performancetests/BasicTest.java +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -package org.oasis_open.contextserver.performancetests; - -import com.carrotsearch.junitbenchmarks.BenchmarkOptions; -import com.carrotsearch.junitbenchmarks.BenchmarkRule; -import com.carrotsearch.junitbenchmarks.WriterConsumer; -import org.apache.http.HttpEntity; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TestRule; -import org.junit.runner.RunWith; -import org.oasis_open.contextserver.api.Metadata; -import org.oasis_open.contextserver.api.services.SegmentService; -import org.ops4j.pax.exam.Configuration; -import org.ops4j.pax.exam.Option; -import org.ops4j.pax.exam.junit.PaxExam; -import org.ops4j.pax.exam.karaf.options.KarafDistributionOption; -import org.ops4j.pax.exam.options.MavenArtifactUrlReference; -import org.ops4j.pax.exam.options.MavenUrlReference; -import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy; -import org.ops4j.pax.exam.spi.reactors.PerClass; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.inject.Inject; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Set; - -import static org.ops4j.pax.exam.CoreOptions.*; -import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.karafDistributionConfiguration; -import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.keepRuntimeFolder; - -@RunWith(PaxExam.class) -@ExamReactorStrategy(PerClass.class) -public class BasicTest { - - private final static Logger LOGGER = LoggerFactory.getLogger(BasicTest.class); - - /** - * Enables the benchmark rule. - */ - @Rule - public TestRule getBenchmarkRun() { - try { - File benchmarks = new File("../../benchmarks"); - benchmarks.mkdirs(); - return new BenchmarkRule(new WriterConsumer(new FileWriter(new File(benchmarks,"benchmark.txt"),true))); - } catch (IOException e) { - LOGGER.error("Cannot get benchamrks",e); - } - return null; - } - - @Inject - protected SegmentService segmentService; - - @Configuration - public Option[] config() { - MavenArtifactUrlReference karafUrl = maven() - .groupId("org.apache.karaf") - .artifactId("apache-karaf") - .version("3.0.1") - .type("tar.gz"); - - MavenUrlReference karafStandardRepo = maven() - .groupId("org.apache.karaf.features") - .artifactId("standard") - .classifier("features") - .type("xml") - .versionAsInProject(); - MavenUrlReference karafPaxWebRepo = maven() - .groupId("org.ops4j.pax.web") - .artifactId("pax-web-features") - .classifier("features") - .type("xml") - .versionAsInProject(); - MavenUrlReference karafSpringRepo = maven() - .groupId("org.apache.karaf.features") - .artifactId("spring") - .classifier("features") - .type("xml") - .versionAsInProject(); - MavenUrlReference karafCxfRepo = maven() - .groupId("org.apache.cxf.karaf") - .artifactId("apache-cxf") - .classifier("features") - .type("xml") - .versionAsInProject(); - MavenUrlReference karafEnterpriseRepo = maven() - .groupId("org.apache.karaf.features") - .artifactId("enterprise") - .classifier("features") - .type("xml") - .versionAsInProject(); - MavenUrlReference contextServerRepo = maven() - .groupId("org.apache.unomi") - .artifactId("unomi-kar") - .classifier("features") - .type("xml") - .versionAsInProject(); - - return new Option[]{ - KarafDistributionOption.debugConfiguration("5005", false), - karafDistributionConfiguration() - .frameworkUrl(karafUrl) - .unpackDirectory(new File("target/exam")) - .useDeployFolder(false), - keepRuntimeFolder(), - KarafDistributionOption.features(karafPaxWebRepo, "war"), - KarafDistributionOption.features(karafCxfRepo, "cxf"), - KarafDistributionOption.features(karafStandardRepo, "openwebbeans"), - KarafDistributionOption.features(karafStandardRepo, "pax-cdi-web-openwebbeans"), - KarafDistributionOption.features(contextServerRepo, "unomi-kar"), - // we need to wrap the HttpComponents libraries ourselves since the OSGi bundles provided by the project are incorrect - wrappedBundle(mavenBundle("org.apache.httpcomponents", - "httpcore").versionAsInProject()), - wrappedBundle(mavenBundle("org.apache.httpcomponents", - "httpmime").versionAsInProject()), - wrappedBundle(mavenBundle("org.apache.httpcomponents", - "httpclient").versionAsInProject()), - wrappedBundle(mavenBundle("com.carrotsearch", - "junit-benchmarks", "0.7.2")), -// wrappedBundle(mavenBundle("com.h2database", -// "h2", "1.4.181")) - }; - } - - @BenchmarkOptions(benchmarkRounds = 100, warmupRounds = 0, concurrency = 10) - @Test - public void testContext() throws IOException { - - CloseableHttpClient httpclient = HttpClients.createDefault(); - HttpGet httpGet = new HttpGet("http://localhost:8181/context.js"); - CloseableHttpResponse response = httpclient.execute(httpGet); - // The underlying HTTP connection is still held by the response object - // to allow the response content to be streamed directly from the network socket. - // In order to ensure correct deallocation of system resources - // the user MUST call CloseableHttpResponse#close() from a finally clause. - // Please note that if response content is not fully consumed the underlying - // connection cannot be safely re-used and will be shut down and discarded - // by the connection manager. - String responseContent = null; - try { - HttpEntity entity = response.getEntity(); - // do something useful with the response body - // and ensure it is fully consumed - responseContent = EntityUtils.toString(entity); - } finally { - response.close(); - } - } - - @BenchmarkOptions(benchmarkRounds = 100, warmupRounds = 0, concurrency = 10) - @Test - public void testSegments() { - Assert.assertNotNull("Segment service should be available", segmentService); - Set<Metadata> segmentMetadatas = segmentService.getSegmentMetadatas(); - Assert.assertNotEquals("Segment metadata list should not be empty", 0, segmentMetadatas.size()); - LOGGER.info("Retrieved " + segmentMetadatas.size() + " segment metadata entries"); - } - - - -} http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/dc1d1520/persistence-elasticsearch/core/pom.xml ---------------------------------------------------------------------- diff --git a/persistence-elasticsearch/core/pom.xml b/persistence-elasticsearch/core/pom.xml index 7a0856e..383fb89 100644 --- a/persistence-elasticsearch/core/pom.xml +++ b/persistence-elasticsearch/core/pom.xml @@ -15,7 +15,8 @@ ~ limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -282,7 +283,7 @@ <Export-Package> org.elasticsearch.*;version="${elasticsearch.version}", org.elasticsearch.index.query.*;version="${elasticsearch.version}", - org.oasis_open.contextserver.persistence.elasticsearch.conditions;version="${project.version}" + org.apache.unomi.persistence.elasticsearch.conditions;version="${project.version}" </Export-Package> <Embed-Dependency>*;scope=compile|runtime;artifactId=!log4j</Embed-Dependency> <Embed-Transitive>true</Embed-Transitive>
