Repository: geode-examples Updated Branches: refs/heads/develop 47008179e -> 5ebbc817e
http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/main/java/org/apache/geode/examples/replicated/Example.java ---------------------------------------------------------------------- diff --git a/replicated/src/main/java/org/apache/geode/examples/replicated/Example.java b/replicated/src/main/java/org/apache/geode/examples/replicated/Example.java new file mode 100644 index 0000000..53e8e0e --- /dev/null +++ b/replicated/src/main/java/org/apache/geode/examples/replicated/Example.java @@ -0,0 +1,56 @@ +/* + * 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.geode.examples.replicated; + +import java.util.function.Consumer; +import java.util.stream.IntStream; + +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; + +public class Example implements Consumer<Region<Integer, String>> { + public static void main(String[] args) { + // connect to the locator using default port 10334 + ClientCache cache = new ClientCacheFactory().addPoolLocator("127.0.0.1", 10334) + .set("log-level", "WARN").create(); + + // create a local region that matches the server region + Region<Integer, String> region = + cache.<Integer, String>createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY) + .create("example-region"); + + new Example().accept(region); + cache.close(); + } + + @Override + public void accept(Region<Integer, String> region) { + // insert values into the region + int count = 10; + IntStream.range(0, count).forEach(i -> region.put(i, "value" + i)); + System.out + .println(String.format("Inserted %d entries into region %s", count, region.getName())); + + // count the values in the region + int inserted = region.keySetOnServer().size(); + System.out.println(String.format("Counted %d keys in region %s", inserted, region.getName())); + + // fetch the values in the region + region.keySetOnServer() + .forEach(key -> System.out.println(String.format("%d:%s", key, region.get(key)))); + } +} http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java ---------------------------------------------------------------------- diff --git a/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java b/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java deleted file mode 100644 index 7503a25..0000000 --- a/replicated/src/main/java/org/apache/geode/examples/replicated/Producer.java +++ /dev/null @@ -1,37 +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.apache.geode.examples.replicated; - -import org.apache.geode.cache.client.ClientCache; - -public class Producer extends BaseClient { - - public static void main(String[] args) { - new Producer().populateRegion(); - } - - public Producer() {} - - public Producer(ClientCache clientCache) { - this.clientCache = clientCache; - } - - public void populateRegion() { - for (int i = 0; i < NUM_ENTRIES; i++) { - getRegion().put(i, "value" + i); - } - logger.info("Done. Inserted " + NUM_ENTRIES + " entries."); - } -} http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/main/main2.iml ---------------------------------------------------------------------- diff --git a/replicated/src/main/main2.iml b/replicated/src/main/main2.iml deleted file mode 100644 index 19dbd15..0000000 --- a/replicated/src/main/main2.iml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="false"> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java ---------------------------------------------------------------------- diff --git a/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java b/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java deleted file mode 100644 index 4bbf051..0000000 --- a/replicated/src/test/java/org/apache/geode/examples/replicated/ConsumerTest.java +++ /dev/null @@ -1,70 +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.apache.geode.examples.replicated; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; - -import java.util.Set; - -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import org.apache.geode.cache.Region; -import org.apache.geode.cache.client.ClientCache; -import org.apache.geode.cache.client.NoAvailableLocatorsException; - -public class ConsumerTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private Consumer consumer; - private ClientCache clientCache = mock(ClientCache.class); - private Region region = mock(Region.class); - private Set keys = mock(Set.class); - - @Before - public void setup() { - when(region.getName()).thenReturn(Consumer.REGION_NAME); - when(keys.size()).thenReturn(Consumer.NUM_ENTRIES); - when(region.keySetOnServer()).thenReturn(keys); - when(clientCache.getRegion(any())).thenReturn(region); - consumer = new Consumer(clientCache); - consumer.setRegion(region); - } - - @Test - public void numberOfEntriesOnServerShouldMatchConsumerEntries() throws Exception { - assertEquals(consumer.NUM_ENTRIES, consumer.countEntriesOnServer()); - } - - @Test - public void numberOfEntriesShouldBeGreaterThanZero() throws Exception { - assertTrue(consumer.NUM_ENTRIES > 0); - } - - @Test - public void countingEntriesWithoutConnectionShouldThrowNoAvailableLocatorsException() - throws Exception { - consumer = new Consumer(); - expectedException.expect(NoAvailableLocatorsException.class); - assertEquals(consumer.NUM_ENTRIES, consumer.countEntriesOnServer()); - } - -} http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/test/java/org/apache/geode/examples/replicated/ExampleTest.java ---------------------------------------------------------------------- diff --git a/replicated/src/test/java/org/apache/geode/examples/replicated/ExampleTest.java b/replicated/src/test/java/org/apache/geode/examples/replicated/ExampleTest.java new file mode 100644 index 0000000..3bab1f0 --- /dev/null +++ b/replicated/src/test/java/org/apache/geode/examples/replicated/ExampleTest.java @@ -0,0 +1,38 @@ +/* + * 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.geode.examples.replicated; + +import static org.assertj.core.api.Assertions.assertThat; + +import org.apache.geode.cache.Region; +import org.geode.examples.util.Mocks; +import org.junit.Rule; +import org.junit.Test; +import org.junit.contrib.java.lang.system.SystemOutRule; + +public class ExampleTest { + + @Rule + public SystemOutRule systemOutRule = new SystemOutRule().enableLog(); + + @Test + public void testExample() throws Exception { + Region<Integer, String> region = Mocks.region("example-region"); + new Example().accept(region); + + assertThat(systemOutRule.getLog()).contains("Inserted 10 entries into region"); + assertThat(systemOutRule.getLog()).contains("value9"); + } +} http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java ---------------------------------------------------------------------- diff --git a/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java b/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java deleted file mode 100644 index 88ce2b1..0000000 --- a/replicated/src/test/java/org/apache/geode/examples/replicated/ProducerTest.java +++ /dev/null @@ -1,68 +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.apache.geode.examples.replicated; - -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.*; - -import java.util.Set; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import org.apache.geode.cache.Region; -import org.apache.geode.cache.client.ClientCache; - -public class ProducerTest { - - @Rule - public ExpectedException expectedException = ExpectedException.none(); - - private Producer producer; - private ClientCache clientCache = mock(ClientCache.class); - private Region region = mock(Region.class); - private Set keys = mock(Set.class); - - @Before - public void setup() throws Exception { - when(region.getName()).thenReturn(Producer.REGION_NAME); - when(region.keySetOnServer()).thenReturn(keys); - when(clientCache.getRegion(any())).thenReturn(region); - } - - @Test - public void populateRegionShouldReturnCorrectNumberOfEntries() throws Exception { - producer = new Producer(clientCache); - producer.setRegion(region); - - producer.populateRegion(); - verify(region, times(producer.NUM_ENTRIES)).put(any(), any()); - } - - @Test - public void populateWhenRegionDoesNotExistShouldThrowNullPointer() throws Exception { - producer = new Producer(clientCache); - expectedException.expect(NullPointerException.class); - producer.populateRegion(); - } - - @After - public void tearDown() { - - } -} http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java ---------------------------------------------------------------------- diff --git a/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java b/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java deleted file mode 100644 index 927af49..0000000 --- a/replicated/src/test/java/org/apache/geode/examples/replicated/ReplicatedTest.java +++ /dev/null @@ -1,165 +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.apache.geode.examples.replicated; - -import static org.hamcrest.core.Is.*; -import static org.junit.Assert.*; -import static org.junit.Assume.*; - -import java.io.IOException; -import java.net.ServerSocket; -import java.util.Map; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.DefaultExecuteResultHandler; -import org.apache.commons.exec.ExecuteException; -import org.apache.commons.exec.environment.EnvironmentUtils; -import org.apache.geode.examples.utils.ShellUtil; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; - -/** - * Tests for the shell scripts of the replicated example - */ -public class ReplicatedTest { - - // TODO: parameterize - public static final String GEODE_LOCATOR_PORT = "GEODE_LOCATOR_PORT="; - private static final String startScriptFileName = "startAll.sh"; - private static final String stopScriptFileName = "stopAll.sh"; - private static final String pidkillerScriptFileName = "pidkiller.sh"; - private boolean processRunning = false; - private ShellUtil shell = new ShellUtil(); - private final long scriptTimeout = TimeUnit.SECONDS.toMillis(120); - private static final Logger logger = Logger.getAnonymousLogger(); - - @Rule - public TemporaryFolder testFolder = new TemporaryFolder(); - - private int locatorPort; - private Map environment; - - @Before - public void setup() throws IOException { - // ignores test if running on windows - assumeThat(System.getProperty("os.name").startsWith("Windows"), is(false)); - - locatorPort = getAvailablePort(); - environment = EnvironmentUtils.getProcEnvironment(); - EnvironmentUtils.addVariableToEnvironment(environment, GEODE_LOCATOR_PORT + locatorPort); - logger.fine("Locator port: " + locatorPort); - } - - @Test - public void checkIfScriptsExistsAndAreExecutable() throws IOException { - assertTrue( - shell.getFileFromClassLoader(startScriptFileName).map(x -> x.isFile()).orElse(false)); - assertTrue(shell.getFileFromClassLoader(stopScriptFileName).map(x -> x.isFile()).orElse(false)); - } - - @Test - public void executeStartThenStopScript() throws InterruptedException, IOException { - final int exitCodeStart = executeScript(startScriptFileName); - assertEquals(0, exitCodeStart); - - final int exitCodeStop = executeScript(stopScriptFileName); - assertEquals(0, exitCodeStop); - } - - @Test - public void failToStopWhenNoServersAreRunning() throws InterruptedException, IOException { - final int exitCode; - - exitCode = executeScript(stopScriptFileName); - assertEquals(1, exitCode); - } - - /** - * Execute the kill script that looks for pid files - * - * @throws IOException - * @throws InterruptedException - */ - private void runKillScript() throws IOException, InterruptedException { - CommandLine cmdLine = CommandLine.parse(shell.getFileFromClassLoader(pidkillerScriptFileName) - .map(x -> x.getAbsolutePath()).orElseThrow(IllegalArgumentException::new)); - cmdLine.addArgument(testFolder.getRoot().getAbsolutePath()); - - DefaultExecuteResultHandler resultHandler = - shell.execute(cmdLine, scriptTimeout, environment, testFolder.getRoot()); - resultHandler.waitFor(scriptTimeout); - } - - /** - * Given a script file name, runs the script and return the exit code. If exitCode != 0 extract - * and prints exception. - * - * @param scriptName - * @return <code>int</code> with exitCode - * @throws IOException - * @throws InterruptedException - */ - private int executeScript(String scriptName) throws IOException, InterruptedException { - final int exitCode; - DefaultExecuteResultHandler resultHandler = - shell.execute(scriptName, scriptTimeout, environment, testFolder.getRoot()); - processRunning = true; - resultHandler.waitFor(); - - logger.finest(String.format("Executing %s...", scriptName)); - exitCode = resultHandler.getExitValue(); - - // extract and log exception if any happened - if (exitCode != 0) { - ExecuteException executeException = resultHandler.getException(); - logger.log(Level.SEVERE, executeException.getMessage(), executeException); - } - return exitCode; - } - - @After - public void tearDown() { - if (processRunning) { - try { - runKillScript(); - } catch (IOException | InterruptedException e) { - e.printStackTrace(); - } - } - } - - /** - * Get a random available port - * - * @return <code>int</code> port number - */ - private static int getAvailablePort() { - try (ServerSocket socket = new ServerSocket(0)) { - int port = socket.getLocalPort(); - socket.close(); - return port; - } catch (IOException ioex) { - logger.log(Level.SEVERE, ioex.getMessage(), ioex); - } - throw new IllegalStateException("No TCP/IP ports available."); - } - -} http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/replicated/src/test/test5.iml ---------------------------------------------------------------------- diff --git a/replicated/src/test/test5.iml b/replicated/src/test/test5.iml deleted file mode 100644 index 19dbd15..0000000 --- a/replicated/src/test/test5.iml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="false"> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/settings.gradle ---------------------------------------------------------------------- diff --git a/settings.gradle b/settings.gradle index 9af877b..28a63f8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -18,5 +18,3 @@ rootProject.name = 'geode-examples' include 'replicated' include 'partitioned' -include 'utils' - http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/src/test/java/org/geode/examples/util/Mocks.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/geode/examples/util/Mocks.java b/src/test/java/org/geode/examples/util/Mocks.java new file mode 100644 index 0000000..ec36681 --- /dev/null +++ b/src/test/java/org/geode/examples/util/Mocks.java @@ -0,0 +1,55 @@ +/* + * 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.geode.examples.util; + +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.geode.cache.Region; +import org.mockito.invocation.InvocationOnMock; + +public class Mocks { + private Mocks() { } + + @SuppressWarnings("unchecked") + public static <K, V> Region<K, V> region(String name) throws Exception { + Map<K, V> data = new HashMap<>(); + Region<K, V> region = mock(Region.class); + + when(region.getName()).thenReturn(name); + when(region.put(any(), any())).then(inv -> data.put(getKey(inv), getValue(inv))); + when(region.get(any())).then(inv -> data.get(getKey(inv))); + when(region.keySet()).thenReturn(data.keySet()); + when(region.values()).thenReturn(data.values()); + when(region.size()).thenReturn(data.size()); + when(region.keySetOnServer()).thenReturn(data.keySet()); + + return region; + } + + @SuppressWarnings("unchecked") + private static <K> K getKey(InvocationOnMock inv) { + return (K) inv.getArguments()[0]; + } + + @SuppressWarnings("unchecked") + private static <V> V getValue(InvocationOnMock inv) { + return (V) inv.getArguments()[1]; + } +} http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/utils/src/main/java/org/apache/geode/examples/utils/ShellUtil.java ---------------------------------------------------------------------- diff --git a/utils/src/main/java/org/apache/geode/examples/utils/ShellUtil.java b/utils/src/main/java/org/apache/geode/examples/utils/ShellUtil.java deleted file mode 100644 index f02b961..0000000 --- a/utils/src/main/java/org/apache/geode/examples/utils/ShellUtil.java +++ /dev/null @@ -1,106 +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.apache.geode.examples.utils; - -import java.io.File; -import java.io.IOException; -import java.net.URL; -import java.util.Map; -import java.util.Optional; - -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.DefaultExecuteResultHandler; -import org.apache.commons.exec.DefaultExecutor; -import org.apache.commons.exec.ExecuteWatchdog; -import org.apache.commons.exec.PumpStreamHandler; -import org.apache.commons.exec.ShutdownHookProcessDestroyer; - -/** - * Utility class for executing shell commands using Apache commons-exec - */ -public class ShellUtil { - - private final ClassLoader classLoader = getClass().getClassLoader(); - - public Optional<File> getFileFromClassLoader(String fileName) { - URL resourceURL = classLoader.getResource(fileName); - return (resourceURL == null) ? Optional.empty() : Optional.of(new File(resourceURL.getFile())); - } - - public CommandLine parseCommandLine(String fileName) { - return getFileFromClassLoader(fileName).map(file -> CommandLine.parse(file.getAbsolutePath())) - .orElseThrow(IllegalArgumentException::new); - } - - public DefaultExecuteResultHandler execute(CommandLine cmdLine, long timeout, Map environment, - File dir) throws IOException { - ExecutorTemplate exampleTestExecutor = new ExecutorTemplate(timeout, dir).invoke(); - DefaultExecutor executor = exampleTestExecutor.getExecutor(); - DefaultExecuteResultHandler resultHandler = exampleTestExecutor.getResultHandler(); - executor.execute(cmdLine, environment, resultHandler); - - return resultHandler; - - } - - public DefaultExecuteResultHandler execute(String fileName, long timeout, Map environment, - File dir) throws IOException { - ExecutorTemplate exampleTestExecutor = new ExecutorTemplate(timeout, dir).invoke(); - DefaultExecutor executor = exampleTestExecutor.getExecutor(); - DefaultExecuteResultHandler resultHandler = exampleTestExecutor.getResultHandler(); - executor.execute(parseCommandLine(fileName), environment, resultHandler); - - return resultHandler; - } - - /** - * Executor template for common scenarios - */ - private static class ExecutorTemplate { - - private final long timeout; - private final File dir; - private DefaultExecutor executor; - private DefaultExecuteResultHandler resultHandler; - - public ExecutorTemplate(final long timeout, final File dir) { - this.timeout = timeout; - this.dir = dir; - } - - public DefaultExecutor getExecutor() { - return executor; - } - - public DefaultExecuteResultHandler getResultHandler() { - return resultHandler; - } - - public ExecutorTemplate invoke() { - executor = new DefaultExecutor(); - ExecuteWatchdog watchdog = new ExecuteWatchdog(timeout); - executor.setWatchdog(watchdog); - - PumpStreamHandler psh = new PumpStreamHandler(System.out, System.err); - executor.setProcessDestroyer(new ShutdownHookProcessDestroyer()); - executor.setStreamHandler(psh); - executor.setWorkingDirectory(dir); - - resultHandler = new DefaultExecuteResultHandler(); - return this; - } - } -} http://git-wip-us.apache.org/repos/asf/geode-examples/blob/c21e76b2/utils/src/main/main5.iml ---------------------------------------------------------------------- diff --git a/utils/src/main/main5.iml b/utils/src/main/main5.iml deleted file mode 100644 index 19dbd15..0000000 --- a/utils/src/main/main5.iml +++ /dev/null @@ -1,6 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<module version="4"> - <component name="NewModuleRootManager" inherit-compiler-output="false"> - <orderEntry type="sourceFolder" forTests="false" /> - </component> -</module> \ No newline at end of file
