Skip to content

Instantly share code, notes, and snippets.

@jxblum
Created April 10, 2020 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jxblum/8b447b9257dadca4f6f80c2780b1b821 to your computer and use it in GitHub Desktop.
Save jxblum/8b447b9257dadca4f6f80c2780b1b821 to your computer and use it in GitHub Desktop.
Writing Client to Geode Cluster Integrating Tests
/*
* Copyright 2020 the original author or authors.
*
* 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
*
* https://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.springframework.data.gemfire.cluster;
import java.io.IOException;
import java.util.Scanner;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.client.ClientCache;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.config.annotation.CacheServerApplication;
import org.springframework.data.gemfire.config.annotation.ClientCacheApplication;
import org.springframework.data.gemfire.config.annotation.EnableClusterConfiguration;
import org.springframework.data.gemfire.config.annotation.EnableManager;
import org.springframework.data.gemfire.config.annotation.LocatorApplication;
import org.springframework.data.gemfire.process.ProcessWrapper;
import org.springframework.data.gemfire.test.support.ClientServerIntegrationTestsSupport;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* The ClientClusterIntegrationTests class...
*
* @author John Blum
* @since 1.0.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = ClientClusterIntegrationTests.TestGeodeClientApplication.class)
public class ClientClusterIntegrationTests extends ClientServerIntegrationTestsSupport {
private static ProcessWrapper locatorProcess;
private static ProcessWrapper serverProcess;
@BeforeClass
public static void startCluster() throws IOException {
int locatorPort = findAvailablePort();
locatorProcess = run(TestLocatorApplication.class,
String.format("-Dspring.data.gemfire.locator.port=%d", locatorPort));
waitForServerToStart("localhost", locatorPort);
int serverPort = findAvailablePort();
serverProcess = run(TestGeodeServerApplication.class,
String.format("-Dspring.data.gemfire.locators=localhost[%1$d] -Dspring.data.gemfire.cache.server.port=%2$d",
locatorPort, serverPort));
waitForServerToStart("localhost", serverPort);
System.setProperty("spring.data.gemfire.pool.locators",
String.format("localhost[%d]", locatorPort));
}
@AfterClass
public static void stopCluster() {
stop(serverProcess);
stop(locatorProcess);
System.clearProperty("spring.data.gemfire.pool.locators");
}
@Test
public void test() { }
@ClientCacheApplication
@EnableClusterConfiguration
static class TestGeodeClientApplication { }
@LocatorApplication
@EnableManager
static class TestLocatorApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext applicationContext =
new AnnotationConfigApplicationContext(TestLocatorApplication.class);
applicationContext.registerShutdownHook();
new Scanner(System.in).nextLine();
}
}
@CacheServerApplication
static class TestGeodeServerApplication {
public static void main(String[] args) {
AnnotationConfigApplicationContext applicationContext =
new AnnotationConfigApplicationContext(TestGeodeServerApplication.class);
applicationContext.registerShutdownHook();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment