Skip to content

Commit

Permalink
Terracotta-OSS#191 : Galvan testing for single server cases
Browse files Browse the repository at this point in the history
* basically move tests from sample entity (passthrough) to galvan
  • Loading branch information
anthonydahanne committed Dec 19, 2016
1 parent 5ba381f commit 3246a02
Show file tree
Hide file tree
Showing 8 changed files with 329 additions and 69 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Terracotta, Inc.
*
* Licensed 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.terracotta.management.integration.tests;

import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.terracotta.testing.rules.BasicExternalCluster;

import java.io.File;

import static java.util.Collections.emptyList;

/**
* @author Mathieu Carbou
*/
public abstract class AbstractSingleTest extends AbstractTest {

private final String offheapResource = "primary-server-resource";
private final String resourceConfig =
"<config xmlns:ohr='http://www.terracotta.org/config/offheap-resource'>"
+ "<ohr:offheap-resources>"
+ "<ohr:resource name=\"" + offheapResource + "\" unit=\"MB\">64</ohr:resource>"
+ "</ohr:offheap-resources>" +
"</config>\n";

@Rule
public org.terracotta.testing.rules.Cluster voltron =
new BasicExternalCluster(new File("target/galvan"), 1, emptyList(), "", resourceConfig, "");

@Before
public void setUp() throws Exception {
voltron.getClusterControl().waitForActive();
commonSetUp(voltron);
}

@After
public void tearDown() throws Exception {
commonTearDown();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terracotta.management.entity.sample;
package org.terracotta.management.integration.tests;

import org.junit.Test;
import org.terracotta.management.model.call.Parameter;
Expand All @@ -37,7 +37,7 @@
/**
* @author Mathieu Carbou
*/
public class ClientCacheRemoteManagementTest extends AbstractTest {
public class ClientCacheRemoteManagementIT extends AbstractSingleTest {

@Test
public void can_access_remote_management_registry_of_client() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terracotta.management.entity.sample;
package org.terracotta.management.integration.tests;

import org.junit.Test;
import org.terracotta.management.entity.tms.TmsAgentConfig;
Expand All @@ -40,7 +40,7 @@
/**
* @author Mathieu Carbou
*/
public class ServerCacheManagementTest extends AbstractTest {
public class ServerCacheManagementIT extends AbstractSingleTest {

@Test
public void can_access_remote_management_registry_on_server() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.terracotta.management.entity.sample;
package org.terracotta.management.integration.tests;

import org.junit.Before;
import org.junit.Test;
import org.terracotta.management.model.capabilities.descriptors.Settings;
import org.terracotta.management.model.cluster.Cluster;
Expand All @@ -34,7 +35,7 @@
/**
* @author Mathieu Carbou
*/
public class TopologyTest extends AbstractTest {
public class TopologyIT extends AbstractSingleTest {

@Test
public void can_read_topology() throws Exception {
Expand Down Expand Up @@ -70,9 +71,27 @@ public void can_read_topology() throws Exception {
.replace(client.getHostName(), "<hostname>")
.replace(client.getHostAddress(), "127.0.0.1"));

String actual = replaceHostname(zeroPorts(currentTopo[0]));
String expected = replaceVersion(readJson("topology.json").toString());
// and compare
assertEquals(expected, actual);
}

private String zeroPorts(String s) {
return s.replaceAll("(\"bindPort\":[0-9]+)", "\"bindPort\":0").replaceAll("(\"groupPort\":[0-9]+)", "\"groupPort\":0");
}

private String replaceHostname(String s) {
return s.replaceAll("\"hostname\":(.*),", "\"hostname\":\"<hostname>\",").replaceAll("(\"groupPort\":[0-9]+)", "\"groupPort\":0");
}

assertEquals(readJson("topology.json").toString(), currentTopo[0]);
/**
*
* @param topology, probably from topology.json
* @return the same topology, but replacing VERSION_TO_REPLACE with the tc core version from the pom
*/
private String replaceVersion(String topology) {
return topology.replace("VERSION_TO_REPLACE", System.getProperty("kitInstallationPath").substring(System.getProperty("kitInstallationPath").lastIndexOf("terracotta-") + 11, System.getProperty("kitInstallationPath").length()-1));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
[
{
"name": "CacheCalls",
"descriptors": [
{
"name": "clear",
"returnType": "void",
"parameters": []
},
{
"name": "get",
"returnType": "java.lang.String",
"parameters": [
{
"name": "key",
"type": "java.lang.String"
}
]
},
{
"name": "put",
"returnType": "void",
"parameters": [
{
"name": "key",
"type": "java.lang.String"
},
{
"name": "value",
"type": "java.lang.String"
}
]
},
{
"name": "size",
"returnType": "int",
"parameters": []
}
],
"capabilityContext": {
"attributes": [
{
"name": "appName",
"required": true
},
{
"name": "cacheName",
"required": true
}
]
}
},
{
"name": "CacheSettings",
"descriptors": [
{
"appName": "pet-clinic",
"cacheName": "pets",
"size": 0
},
{
"appName": "pet-clinic",
"cacheName": "clients",
"size": 0
}
],
"capabilityContext": {
"attributes": [
{
"name": "appName",
"required": true
},
{
"name": "cacheName",
"required": true
}
]
}
},
{
"name": "CacheStatistics",
"properties": {
"averageWindowDuration": 1,
"averageWindowUnit": "MINUTES",
"historySize": 100,
"historyInterval": 1,
"historyIntervalUnit": "SECONDS",
"timeToDisable": 5,
"timeToDisableUnit": "SECONDS"
},
"descriptors": [
{
"name": "Cache:ClearCount",
"type": "COUNTER_HISTORY"
},
{
"name": "Cache:ClearRate",
"type": "RATE_HISTORY"
},
{
"name": "Cache:HitCount",
"type": "COUNTER_HISTORY"
},
{
"name": "Cache:HitRate",
"type": "RATE_HISTORY"
},
{
"name": "Cache:HitRatio",
"type": "RATIO_HISTORY"
},
{
"name": "Cache:MissCount",
"type": "COUNTER_HISTORY"
},
{
"name": "Cache:MissRate",
"type": "RATE_HISTORY"
},
{
"name": "Cache:MissRatio",
"type": "RATIO_HISTORY"
},
{
"name": "ClientCache:Size",
"type": "SIZE_HISTORY"
}
],
"capabilityContext": {
"attributes": [
{
"name": "appName",
"required": true
},
{
"name": "cacheName",
"required": true
}
]
}
},
{
"name": "ManagementAgentService",
"descriptors": [],
"capabilityContext": {
"attributes": []
}
},
{
"name": "StatisticCollectorCapability",
"descriptors": [
{
"name": "startStatisticCollector",
"returnType": "void",
"parameters": []
},
{
"name": "stopStatisticCollector",
"returnType": "void",
"parameters": []
},
{
"name": "updateCollectedStatistics",
"returnType": "void",
"parameters": [
{
"name": "capabilityName",
"type": "java.lang.String"
},
{
"name": "statisticNames",
"type": "java.util.Collection"
}
]
}
],
"capabilityContext": {
"attributes": [
{
"name": "appName",
"required": true
}
]
}
}
]
Loading

0 comments on commit 3246a02

Please sign in to comment.