Repository: incubator-geode Updated Branches: refs/heads/feature/e2e-testing 6d097230a -> aa9b675fb
Function deployment test Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/aa9b675f Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/aa9b675f Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/aa9b675f Branch: refs/heads/feature/e2e-testing Commit: aa9b675fb312e2e515586c62dd277c1d206c01d3 Parents: 6d09723 Author: Jens Deppe <jde...@pivotal.io> Authored: Tue Oct 11 13:50:49 2016 -0700 Committer: Jens Deppe <jde...@pivotal.io> Committed: Tue Oct 11 13:50:49 2016 -0700 ---------------------------------------------------------------------- .../java/org/apache/geode/e2e/GetPutSteps.java | 30 +++++++++++- .../geode/e2e/container/DockerCluster.java | 48 +++++++++++++++++--- .../org/apache/geode/e2e/get_put.story | 3 ++ 3 files changed, 73 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aa9b675f/geode-core/src/test/java/org/apache/geode/e2e/GetPutSteps.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/e2e/GetPutSteps.java b/geode-core/src/test/java/org/apache/geode/e2e/GetPutSteps.java index 115dd69..e07ee34 100644 --- a/geode-core/src/test/java/org/apache/geode/e2e/GetPutSteps.java +++ b/geode-core/src/test/java/org/apache/geode/e2e/GetPutSteps.java @@ -1,13 +1,23 @@ package org.apache.geode.e2e; +import static junit.framework.TestCase.assertNotNull; import static org.junit.Assert.assertEquals; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; + import com.spotify.docker.client.exceptions.DockerException; import org.apache.geode.cache.CacheClosedException; import org.apache.geode.cache.Region; import org.apache.geode.cache.client.ClientCache; import org.apache.geode.cache.client.ClientCacheFactory; import org.apache.geode.cache.client.ClientRegionShortcut; +import org.apache.geode.cache.execute.Execution; +import org.apache.geode.cache.execute.FunctionService; +import org.apache.geode.cache.execute.ResultCollector; import org.apache.geode.e2e.container.DockerCluster; import org.jbehave.core.annotations.AfterScenario; import org.jbehave.core.annotations.BeforeScenario; @@ -27,7 +37,7 @@ public class GetPutSteps { } @BeforeScenario - public void beforeScenario() { + public void beforeScenario() throws IOException { cluster = new DockerCluster("test-cluster"); } @@ -94,5 +104,23 @@ public class GetPutSteps { return cache; } + + @Given("function $fnName is deployed") + public void deployFunction(String fnClass) throws Exception { + String jar = cluster.injectScratchFile(Utils.getJarForClassName(fnClass)); + cluster.gfshCommand("deploy --jar=" + jar); + } + + @When("I call function with id $fnId on region $regionName with argument $arg it returns $returns") + public void foo(String fnId, String regionName, String arg, int returns) { + ClientCache cache = getClientCache(); + Region region = cache.getRegion(regionName); + Execution exe = FunctionService.onServers(region.getRegionService()); + ResultCollector rs = exe.withArgs(regionName).execute(fnId); + List<Integer> results = (List<Integer>) rs.getResult(); + + assertEquals(returns, results.stream().mapToInt(i -> i.intValue()).sum()); + } + } http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aa9b675f/geode-core/src/test/java/org/apache/geode/e2e/container/DockerCluster.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/e2e/container/DockerCluster.java b/geode-core/src/test/java/org/apache/geode/e2e/container/DockerCluster.java index 96dae81..f1cd4e9 100644 --- a/geode-core/src/test/java/org/apache/geode/e2e/container/DockerCluster.java +++ b/geode-core/src/test/java/org/apache/geode/e2e/container/DockerCluster.java @@ -2,6 +2,11 @@ package org.apache.geode.e2e.container; import static com.google.common.base.Charsets.*; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -29,8 +34,21 @@ public class DockerCluster { private List<String> nodeIds; private String locatorHost; private int locatorPort; + private final String geodeHome; + private final String scratchDir; + + private static final String SCRATCH_DIR_BASENAME = "scratch"; + + public DockerCluster(String name) throws IOException { + geodeHome = System.getenv("GEODE_HOME"); + if (geodeHome == null) { + throw new IllegalStateException("GEODE_HOME environment variable is not set"); + } + + Path scratch = Files.createDirectory(Paths.get(geodeHome, SCRATCH_DIR_BASENAME)); + scratch.toFile().deleteOnExit(); + scratchDir = scratch.toString(); - public DockerCluster(String name) { docker = DefaultDockerClient.builder(). uri("unix:///var/run/docker.sock").build(); @@ -46,6 +64,25 @@ public class DockerCluster { this.locatorCount = count; } + public String getScratchDir() { + return scratchDir; + } + + /** + * Given a file on the local host's filesystem, copy that file into the cluster's + * global scratch area. The scratch file is deleted on exit. + * @param hostFile + * @return the cluster relative file name - for example /tmp/work/scratch/foo.zip + */ + public String injectScratchFile(String hostFile) throws IOException { + Path localPath = Paths.get(hostFile); + Path scratchFile = Paths.get(getScratchDir(), localPath.getFileName().toString()); + Files.copy(localPath, scratchFile); + scratchFile.toFile().deleteOnExit(); + + return Paths.get("/", "tmp", "work", SCRATCH_DIR_BASENAME, scratchFile.getFileName().toString()).toString(); + } + public void start() throws Exception { startLocators(); startServers(); @@ -56,12 +93,8 @@ public class DockerCluster { } public String startContainer(int index, Map<String, List<PortBinding>> portBindings) throws DockerException, InterruptedException { - String geodeHome = System.getenv("GEODE_HOME"); - if (geodeHome == null) { - throw new IllegalStateException("GEODE_HOME environment variable is not set"); - } - String vol = String.format("%s:/tmp/work", geodeHome); + String hostname = String.format("%s-%d", name, index); HostConfig hostConfig = HostConfig. builder(). @@ -73,13 +106,14 @@ public class DockerCluster { image("gemfire/ubuntu-gradle"). openStdin(true). exposedPorts(portBindings.keySet()). - hostname(String.format("%s-%d", name, index)). + hostname(hostname). hostConfig(hostConfig). workingDir("/tmp"). build(); ContainerCreation creation = docker.createContainer(config); String id = creation.id(); +// docker.renameContainer(id, hostname); docker.startContainer(id); docker.inspectContainer(id); http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/aa9b675f/geode-core/src/test/resources/org/apache/geode/e2e/get_put.story ---------------------------------------------------------------------- diff --git a/geode-core/src/test/resources/org/apache/geode/e2e/get_put.story b/geode-core/src/test/resources/org/apache/geode/e2e/get_put.story index 9a451fc..b6651de 100644 --- a/geode-core/src/test/resources/org/apache/geode/e2e/get_put.story +++ b/geode-core/src/test/resources/org/apache/geode/e2e/get_put.story @@ -9,6 +9,9 @@ Given region BAR is created as PARTITION_REDUNDANT with redundancy 1 When I put 100 entries into region BAR Then I can get 100 entries from region BAR +Given function org.apache.geode.e2e.FnGetPrimaryBucketSize is deployed +When I call function with id org.apache.geode.e2e.FnGetPrimaryBucketSize on region BAR with argument BAZ it returns 100 + Given server 0 is killed Then I can get 100 entries from region FOO Then I can get 100 entries from region BAR