brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject [04/10] brooklyn-server git commit: Add catalog performance tests
Date Wed, 16 Nov 2016 18:15:48 GMT
Add catalog performance tests


Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/b15b1ebb
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/b15b1ebb
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/b15b1ebb

Branch: refs/heads/master
Commit: b15b1ebbf83d6b35ba06d7671552e8ffd3d88be3
Parents: 44088b2
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Nov 9 16:18:04 2016 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Nov 16 18:08:08 2016 +0000

----------------------------------------------------------------------
 .../qa/performance/CatalogPerformanceTest.java  | 176 ++++++++++++++++++
 .../BrooklynRestResourcePerformanceTest.java    |  37 ++++
 .../CatalogResourcePerformanceTest.java         | 185 +++++++++++++++++++
 .../rest/testing/BrooklynRestResourceTest.java  |   4 +-
 4 files changed, 400 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b15b1ebb/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/qa/performance/CatalogPerformanceTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/qa/performance/CatalogPerformanceTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/qa/performance/CatalogPerformanceTest.java
new file mode 100644
index 0000000..5382cc5
--- /dev/null
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/qa/performance/CatalogPerformanceTest.java
@@ -0,0 +1,176 @@
+/*
+ * 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.brooklyn.camp.brooklyn.qa.performance;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+import org.apache.brooklyn.api.catalog.CatalogItem;
+import org.apache.brooklyn.camp.brooklyn.AbstractYamlTest;
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.core.test.policy.TestPolicy;
+import org.apache.brooklyn.core.test.qa.performance.AbstractPerformanceTest;
+import org.apache.brooklyn.test.performance.PerformanceMeasurer;
+import org.apache.brooklyn.test.performance.PerformanceTestDescriptor;
+import org.apache.brooklyn.test.performance.PerformanceTestResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+
+public class CatalogPerformanceTest extends AbstractYamlTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(CatalogPerformanceTest.class);
+    
+    private static String TEST_VERSION = "0.1.2";
+
+    protected PerformanceTestResult measure(PerformanceTestDescriptor options) {
+        PerformanceTestResult result = PerformanceMeasurer.run(options);
+        LOG.info("test="+options+"; result="+result);
+        return result;
+    }
+
+    protected int numIterations() {
+        return 100;
+    }
+    
+    private List<CatalogItem<?, ?>> addItems(int idSuffix) {
+        String yaml = Joiner.on("\n").join(
+                "brooklyn.catalog:",
+                "  version: " + TEST_VERSION,
+                "  items:",
+                "  - id: myentity-" + idSuffix,
+                "    itemType: entity",
+                "    name: My Catalog Entity " + idSuffix,
+                "    description: My description",
+                "    icon_url: classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif",
+                "    item:",
+                "      type: " + TestEntity.class.getName(),
+                "  - id: myapp-" + idSuffix,
+                "    itemType: template",
+                "    name: My Catalog App " + idSuffix,
+                "    description: My description",
+                "    icon_url: classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif",
+                "    item:",
+                "      services:",
+                "      - type: " + TestEntity.class.getName(),
+                "  - id: mylocation-" + idSuffix,
+                "    itemType: location",
+                "    name: My Catalog Location " + idSuffix,
+                "    description: My description",
+                "    item:",
+                "      type: localhost",
+                "  - id: mypolicy-" + idSuffix,
+                "    itemType: policy",
+                "    name: My Catalog Policy " + idSuffix,
+                "    description: My description",
+                "    item:",
+                "      type: " + TestPolicy.class.getName());
+        return ImmutableList.copyOf(mgmt().getCatalog().addItems(yaml, false));
+    }
+    
+    @Test(groups={"Integration"})
+    public void testAddItems() {
+        final AtomicInteger counter = new AtomicInteger();
+        final AtomicReference<List<CatalogItem<?,?>>> items = new AtomicReference<>();
+        
+        Runnable preJob = null;
+        
+        Runnable job = new Runnable() {
+            public void run() {
+                int i = counter.getAndIncrement();
+                items.set(addItems(i));
+            }
+        };
+        Runnable postJob = new Runnable() {
+            public void run() {
+                if (items.get() != null) {
+                    for (CatalogItem<?, ?> item : items.get()) {
+                        mgmt().getCatalog().deleteCatalogItem(item.getSymbolicName(),  item.getVersion());
+                    }
+                }
+            }
+        };
+        runPerformanceTest("testAddItems", preJob, job, postJob);
+    }
+    
+    @Test(groups={"Integration"})
+    public void testCreateSpecs() {
+        final AtomicInteger counter = new AtomicInteger();
+        final AtomicReference<List<CatalogItem<?,?>>> items = new AtomicReference<>();
+        
+        Runnable preJob = new Runnable() {
+            public void run() {
+                int i = counter.getAndIncrement();
+                items.set(addItems(i));
+            }
+        };
+        Runnable job = new Runnable() {
+            @SuppressWarnings({"unchecked", "rawtypes"})
+            public void run() {
+                for (CatalogItem<?, ?> item : items.get()) {
+                    CatalogItem castItem = (CatalogItem) item;
+                    mgmt().getCatalog().createSpec(castItem);
+                }
+            }
+        };
+        Runnable postJob = new Runnable() {
+            public void run() {
+                if (items.get() != null) {
+                    for (CatalogItem<?, ?> item : items.get()) {
+                        mgmt().getCatalog().deleteCatalogItem(item.getSymbolicName(),  item.getVersion());
+                    }
+                }
+            }
+        };
+        runPerformanceTest("testCreateSpecs", preJob, job, postJob);
+    }
+    
+    @Test(groups={"Integration"})
+    public void testCreateSameSpecsRepeatedly() {
+        final List<CatalogItem<?, ?>> items = addItems(0);
+        
+        Runnable job = new Runnable() {
+            @SuppressWarnings({"unchecked", "rawtypes"})
+            public void run() {
+                for (CatalogItem<?, ?> item : items) {
+                    CatalogItem castItem = (CatalogItem) item;
+                    mgmt().getCatalog().createSpec(castItem);
+                }
+            }
+        };
+        runPerformanceTest("testCreateSpecs", null, job, null);
+    }
+    
+    protected void runPerformanceTest(String methodName, Runnable preJob, Runnable job, Runnable
postJob) {
+        int numIterations = numIterations();
+        double minRatePerSec = 10 * AbstractPerformanceTest.PERFORMANCE_EXPECTATION;
+        
+        measure(PerformanceTestDescriptor.create()
+                .summary("CatalogPerformanceTest." + methodName)
+                .iterations(numIterations)
+                .minAcceptablePerSecond(minRatePerSec)
+                .preJob(preJob)
+                .job(job)
+                .postJob(postJob));
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b15b1ebb/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BrooklynRestResourcePerformanceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BrooklynRestResourcePerformanceTest.java
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BrooklynRestResourcePerformanceTest.java
new file mode 100644
index 0000000..e38cc7e
--- /dev/null
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/BrooklynRestResourcePerformanceTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.brooklyn.rest.resources;
+
+import org.apache.brooklyn.rest.testing.BrooklynRestResourceTest;
+import org.apache.brooklyn.test.performance.PerformanceMeasurer;
+import org.apache.brooklyn.test.performance.PerformanceTestDescriptor;
+import org.apache.brooklyn.test.performance.PerformanceTestResult;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class BrooklynRestResourcePerformanceTest extends BrooklynRestResourceTest
{
+
+    private static final Logger log = LoggerFactory.getLogger(BrooklynRestResourcePerformanceTest.class);
+
+    protected PerformanceTestResult measure(PerformanceTestDescriptor options) {
+        PerformanceTestResult result = PerformanceMeasurer.run(options);
+        log.info("test="+options+"; result="+result);
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b15b1ebb/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourcePerformanceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourcePerformanceTest.java
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourcePerformanceTest.java
new file mode 100644
index 0000000..e97666f
--- /dev/null
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/CatalogResourcePerformanceTest.java
@@ -0,0 +1,185 @@
+/*
+ * 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.brooklyn.rest.resources;
+
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
+
+import javax.ws.rs.core.GenericType;
+
+import org.apache.brooklyn.core.test.entity.TestEntity;
+import org.apache.brooklyn.core.test.qa.performance.AbstractPerformanceTest;
+import org.apache.brooklyn.policy.autoscaling.AutoScalerPolicy;
+import org.apache.brooklyn.rest.domain.CatalogEntitySummary;
+import org.apache.brooklyn.rest.domain.CatalogItemSummary;
+import org.apache.brooklyn.rest.domain.CatalogLocationSummary;
+import org.apache.brooklyn.rest.domain.CatalogPolicySummary;
+import org.apache.brooklyn.test.performance.PerformanceTestDescriptor;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
+
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+
+//by using a different suite name we disallow interleaving other tests between the methods
of this test class, which wrecks the test fixtures
+@Test(suiteName = "CatalogResourcePerformanceTest")
+public class CatalogResourcePerformanceTest extends BrooklynRestResourcePerformanceTest {
+
+    @SuppressWarnings("unused")
+    private static final Logger log = LoggerFactory.getLogger(CatalogResourcePerformanceTest.class);
+    
+    private static String TEST_VERSION = "0.1.2";
+
+    @Override
+    protected boolean useLocalScannedCatalog() {
+        return true;
+    }
+    
+    protected int numIterations() {
+        return 100;
+    }
+    
+    @Override
+    protected void initClass() throws Exception {
+        super.initClass();
+        
+        // pre-populate the catalog with YAML blueprints
+        for (int i = 0; i < 10; i++) {
+            String yaml = Joiner.on("\n").join(
+                    "brooklyn.catalog:",
+                    "  version: " + TEST_VERSION,
+                    "  items:",
+                    "  - id: myentity-" + i,
+                    "    itemType: entity",
+                    "    name: My Catalog Entity " + i,
+                    "    description: My description",
+                    "    icon_url: classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif",
+                    "    item:",
+                    "      type: " + TestEntity.class.getName(),
+                    "  - id: myapp-" + i,
+                    "    itemType: template",
+                    "    name: My Catalog App " + i,
+                    "    description: My description",
+                    "    icon_url: classpath:/org/apache/brooklyn/test/osgi/entities/icon.gif",
+                    "    item:",
+                    "      services:",
+                    "      - type: " + TestEntity.class.getName(),
+                    "  - id: mylocation-" + i,
+                    "    itemType: location",
+                    "    name: My Catalog Location " + i,
+                    "    description: My description",
+                    "    item:",
+                    "      type: localhost",
+                    "  - id: mypolicy-" + i,
+                    "    itemType: policy",
+                    "    name: My Catalog Policy " + i,
+                    "    description: My description",
+                    "    item:",
+                    "      type: " + AutoScalerPolicy.class.getName());
+            getManagementContext().getCatalog().addItems(yaml, false);
+        }
+    }
+
+    @Test(groups={"Integration"})
+    public void testListAllEntities() {
+        runListAllPerformanceTest("testListAllEntities", "/catalog/entities", new GenericType<List<CatalogEntitySummary>>()
{});
+    }
+    
+    @Test(groups={"Integration"})
+    public void testListAllApplications() {
+        runListAllPerformanceTest("testListAllApplications", "/catalog/applications", new
GenericType<List<CatalogItemSummary>>() {});
+    }
+    
+    @Test(groups={"Integration"})
+    public void testListAllPolicies() {
+        runListAllPerformanceTest("testListAllPolicicies", "/catalog/policies", new GenericType<List<CatalogPolicySummary>>()
{});
+    }
+    
+    @Test(groups={"Integration"})
+    public void testListAllLocations() {
+        runListAllPerformanceTest("testListAllLocations", "/catalog/locations", new GenericType<List<CatalogLocationSummary>>()
{});
+    }
+    
+    @Test(groups={"Integration"})
+    public void testGetEntity() {
+        runGetOnePerformanceTest("testGetEntity", "/catalog/entities/myentity-0/"+TEST_VERSION,
CatalogEntitySummary.class);
+    }
+    
+    @Test(groups={"Integration"})
+    public void testGetApplication() {
+        runGetOnePerformanceTest("testGetApplication", "/catalog/applications/myapp-0/"+TEST_VERSION,
CatalogItemSummary.class);
+    }
+    
+    @Test(groups={"Integration"})
+    public void testGetPolicy() {
+        runGetOnePerformanceTest("testGetPolicy", "/catalog/policies/mypolicy-0/"+TEST_VERSION,
CatalogPolicySummary.class);
+    }
+    
+    @Test(groups={"Integration"})
+    public void testGetLocation() {
+        runGetOnePerformanceTest("testGetLocation", "/catalog/locations/mylocation-0/"+TEST_VERSION,
CatalogLocationSummary.class);
+    }
+    
+    protected void runListAllPerformanceTest(String methodName, final String urlPath, final
GenericType<? extends List<?>> returnType) {
+        runPerformanceTest(
+                "CatalogResourcePerformanceTest."+methodName, 
+                new Function<WebClient, Void>() {
+                    public Void apply(WebClient client) {
+                        List<?> result = client.path(urlPath).get(returnType);
+                        assertTrue(result.size() > 0, "size="+result.size());
+                        return null;
+                    }});
+    }
+    
+    protected void runGetOnePerformanceTest(String methodName, final String urlPath, final
Class<?> returnType) {
+        runPerformanceTest(
+                "CatalogResourcePerformanceTest."+methodName, 
+                new Function<WebClient, Void>() {
+                    public Void apply(WebClient client) {
+                        Object result = client.path(urlPath).get(returnType);
+                        assertNotNull(result);
+                        return null;
+                    }});
+    }
+    
+    protected void runPerformanceTest(String summary, final Function<WebClient, Void>
job) {
+        int numIterations = numIterations();
+        double minRatePerSec = 10 * AbstractPerformanceTest.PERFORMANCE_EXPECTATION;
+        
+        final AtomicReference<WebClient> client = new AtomicReference<>();
+        
+        measure(PerformanceTestDescriptor.create()
+                .summary(summary)
+                .iterations(numIterations)
+                .minAcceptablePerSecond(minRatePerSec)
+                .preJob(new Runnable() {
+                    public void run() {
+                        client.set(client());
+                    }})
+                .job(new Runnable() {
+                    public void run() {
+                        job.apply(client.get());
+                    }}));
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/b15b1ebb/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/BrooklynRestResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/BrooklynRestResourceTest.java
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/BrooklynRestResourceTest.java
index 505bb58..5108e72 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/BrooklynRestResourceTest.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/BrooklynRestResourceTest.java
@@ -73,13 +73,13 @@ public abstract class BrooklynRestResourceTest extends BrooklynRestApiTest
{
     };
 
     @Override
-    public void initClass() throws Exception {
+    protected void initClass() throws Exception {
         super.initClass();
         startServer();
     }
 
     @Override
-    public void destroyClass() throws Exception {
+    protected void destroyClass() throws Exception {
         stopServer();
         super.destroyClass();
     }


Mime
View raw message