DATAGEODE-40 - Fix PoolsConfiguredWithLocatorsAndServersExpressionsIntegrationTests CI failures.
This commit is contained in:
@@ -16,81 +16,81 @@
|
||||
|
||||
package org.springframework.data.gemfire.client;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.springframework.data.gemfire.util.RuntimeExceptionFactory.newIllegalArgumentException;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.geode.cache.client.Pool;
|
||||
import org.apache.geode.cache.client.PoolFactory;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpoint;
|
||||
import org.springframework.data.gemfire.support.ConnectionEndpointList;
|
||||
import org.springframework.data.gemfire.util.CollectionUtils;
|
||||
import org.springframework.data.gemfire.test.mock.MockGemFireObjectsSupport;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
/**
|
||||
* The PoolsConfiguredWithLocatorsAndServersExpressionsIntegrationTests class is a test suite of test cases testing the use of
|
||||
* property placeholder values in the nested <gfe:locator> and <gfe:server> sub-elements
|
||||
* of the <gfe:pool> element as well as the <code>locators</code> and <code>servers</code> attributes.
|
||||
* Integration tests that test the use of property placeholders in nested <gfe:locator> and <gfe:server>
|
||||
* elements of the SDG XML namespace <gfe:pool> element along with testing property placeholders in
|
||||
* the <gfe:pool> element <code>locators</code> and <code>servers</code> attributes.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.junit.Test
|
||||
* @see org.junit.runner.RunWith
|
||||
* @see org.apache.geode.cache.client.Pool
|
||||
* @see org.apache.geode.cache.client.PoolFactory
|
||||
* @see org.springframework.test.context.ContextConfiguration
|
||||
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
|
||||
* @see org.springframework.test.context.junit4.SpringRunner
|
||||
* @see org.springframework.data.gemfire.client.PoolFactoryBean
|
||||
* @see org.springframework.data.gemfire.config.PoolParser
|
||||
* @see org.springframework.data.gemfire.config.xml.PoolParser
|
||||
* @see <a href="https://jira.spring.io/browse/SGF-433">SGF-433</a>
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration
|
||||
public class PoolsConfiguredWithLocatorsAndServersExpressionsIntegrationTests {
|
||||
@SuppressWarnings("unused")
|
||||
public class SpELExpressionConfiguredPoolsIntegrationTests {
|
||||
|
||||
private static ConnectionEndpointList anotherLocators = new ConnectionEndpointList();
|
||||
private static ConnectionEndpointList anotherServers = new ConnectionEndpointList();
|
||||
private static ConnectionEndpointList locators = new ConnectionEndpointList();
|
||||
private static ConnectionEndpointList servers = new ConnectionEndpointList();
|
||||
private static final ConnectionEndpointList anotherLocators = new ConnectionEndpointList();
|
||||
private static final ConnectionEndpointList anotherServers = new ConnectionEndpointList();
|
||||
private static final ConnectionEndpointList locators = new ConnectionEndpointList();
|
||||
private static final ConnectionEndpointList servers = new ConnectionEndpointList();
|
||||
|
||||
@Autowired
|
||||
@Qualifier("locatorPool")
|
||||
@SuppressWarnings("unused")
|
||||
private Pool locatorPool;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("serverPool")
|
||||
@SuppressWarnings("unused")
|
||||
private Pool serverPool;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("anotherLocatorPool")
|
||||
@SuppressWarnings("unused")
|
||||
private Pool anotherLocatorPool;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("anotherServerPool")
|
||||
@SuppressWarnings("unused")
|
||||
private Pool anotherServerPool;
|
||||
|
||||
protected static ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
}
|
||||
private static void assertConnectionEndpoints(ConnectionEndpointList connectionEndpoints,
|
||||
String... expected) {
|
||||
|
||||
protected void assertConnectionEndpoints(Iterable<ConnectionEndpoint> connectionEndpoints, String... expected) {
|
||||
assertThat(connectionEndpoints).isNotNull();
|
||||
assertThat(connectionEndpoints.size()).isEqualTo(expected.length);
|
||||
|
||||
Collections.sort(connectionEndpoints);
|
||||
|
||||
int index = 0;
|
||||
|
||||
@@ -101,50 +101,82 @@ public class PoolsConfiguredWithLocatorsAndServersExpressionsIntegrationTests {
|
||||
assertThat(index).isEqualTo(expected.length);
|
||||
}
|
||||
|
||||
private static ConnectionEndpoint newConnectionEndpoint(String host, int port) {
|
||||
return new ConnectionEndpoint(host, port);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anotherLocatorPoolFactoryConfiguration() {
|
||||
String[] expected = { "localhost[10335]", "cardboardbox[10334]", "safetydepositbox[10336]", "pobox[10334]" };
|
||||
|
||||
assertThat(anotherLocators.size()).isEqualTo(expected.length);
|
||||
String[] expected = { "cardboardbox[10334]", "localhost[10335]", "pobox[10334]", "safetydepositbox[10336]" };
|
||||
|
||||
assertConnectionEndpoints(anotherLocators, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void anotherServerPoolFactoryConfiguration() {
|
||||
|
||||
String[] expected = { "boombox[1234]", "jambox[40404]", "toolbox[8181]" };
|
||||
|
||||
assertThat(anotherServers.size()).isEqualTo(expected.length);
|
||||
assertConnectionEndpoints(CollectionUtils.sort(anotherServers), expected);
|
||||
assertConnectionEndpoints(anotherServers, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void locatorPoolFactoryConfiguration() {
|
||||
|
||||
String[] expected = { "backspace[10334]", "jambox[11235]", "mars[30303]", "pluto[20668]", "skullbox[12480]" };
|
||||
|
||||
assertThat(locators.size()).isEqualTo(expected.length);
|
||||
assertConnectionEndpoints(CollectionUtils.sort(locators), expected);
|
||||
assertConnectionEndpoints(locators, expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serverPoolFactoryConfiguration() {
|
||||
String[] expected = { "earth[4554]", "jupiter[40404]", "mars[5112]", "mercury[1234]", "neptune[42424]", "saturn[41414]",
|
||||
"uranis[0]", "venus[9876]" };
|
||||
|
||||
assertThat(servers.size()).isEqualTo(expected.length);
|
||||
assertConnectionEndpoints(CollectionUtils.sort(servers), expected);
|
||||
String[] expected = {
|
||||
"earth[4554]", "jupiter[40404]", "mars[5112]", "mercury[1234]",
|
||||
"neptune[42424]", "saturn[41414]", "uranis[0]", "venus[9876]"
|
||||
};
|
||||
|
||||
assertConnectionEndpoints(servers, expected);
|
||||
}
|
||||
|
||||
public static class SpELBoundBean {
|
||||
|
||||
private final Properties clientProperties;
|
||||
|
||||
public SpELBoundBean(Properties clientProperties) {
|
||||
this.clientProperties = Optional.ofNullable(clientProperties)
|
||||
.orElseThrow(() -> newIllegalArgumentException("clientProperties are required"));
|
||||
}
|
||||
|
||||
public String locatorsHostsPorts() {
|
||||
return "safetydepositbox[10336], pobox";
|
||||
}
|
||||
|
||||
public String serverTwoHost() {
|
||||
return this.clientProperties.getProperty("gemfire.cache.client.server.2.host");
|
||||
}
|
||||
|
||||
public String serverTwoPort() {
|
||||
return this.clientProperties.getProperty("gemfire.cache.client.server.2.port");
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
|
||||
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
BeanDefinition anotherLocatorPoolBeanDefinition = beanFactory.getBeanDefinition("anotherLocatorPool");
|
||||
anotherLocatorPoolBeanDefinition.setBeanClassName(AnotherLocatorPoolFactoryBean.class.getName());
|
||||
BeanDefinition anotherServerPoolBeanDefinition = beanFactory.getBeanDefinition("anotherServerPool");
|
||||
anotherServerPoolBeanDefinition.setBeanClassName(AnotherServerPoolFactoryBean.class.getName());
|
||||
BeanDefinition locatorPoolBeanDefinition = beanFactory.getBeanDefinition("locatorPool");
|
||||
locatorPoolBeanDefinition.setBeanClassName(LocatorPoolFactoryBean.class.getName());
|
||||
BeanDefinition serverPoolBeanDefinition = beanFactory.getBeanDefinition("serverPool");
|
||||
serverPoolBeanDefinition.setBeanClassName(ServerPoolFactoryBean.class.getName());
|
||||
|
||||
postProcessBeanDefinition(beanFactory, "anotherLocatorPool", AnotherLocatorPoolFactoryBean.class);
|
||||
postProcessBeanDefinition(beanFactory, "anotherServerPool", AnotherServerPoolFactoryBean.class);
|
||||
postProcessBeanDefinition(beanFactory, "locatorPool", LocatorPoolFactoryBean.class);
|
||||
postProcessBeanDefinition(beanFactory, "serverPool", ServerPoolFactoryBean.class);
|
||||
}
|
||||
|
||||
private void postProcessBeanDefinition(ConfigurableListableBeanFactory beanFactory,
|
||||
String beanName, Class<?> beanType) {
|
||||
|
||||
beanFactory.getBeanDefinition(beanName).setBeanClassName(beanType.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,30 +204,7 @@ public class PoolsConfiguredWithLocatorsAndServersExpressionsIntegrationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public static class SpELBoundBean {
|
||||
|
||||
private final Properties clientProperties;
|
||||
|
||||
public SpELBoundBean(Properties clientProperties) {
|
||||
Assert.notNull(clientProperties, "clientProperties must not be null");
|
||||
this.clientProperties = clientProperties;
|
||||
}
|
||||
|
||||
public String locatorsHostsPorts() {
|
||||
return "safetydepositbox[10336], pobox";
|
||||
}
|
||||
|
||||
public String serverTwoHost() {
|
||||
return clientProperties.getProperty("gemfire.cache.client.server.2.host");
|
||||
}
|
||||
|
||||
public String serverTwoPort() {
|
||||
return clientProperties.getProperty("gemfire.cache.client.server.2.port");
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestPoolFactoryBean extends PoolFactoryBean {
|
||||
static class TestPoolFactoryBean extends PoolFactoryBean {
|
||||
|
||||
ConnectionEndpointList getLocatorList() {
|
||||
throw new UnsupportedOperationException("Not Implemented");
|
||||
@@ -207,26 +216,21 @@ public class PoolsConfiguredWithLocatorsAndServersExpressionsIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected PoolFactory createPoolFactory() {
|
||||
final PoolFactory mockPoolFactory = mock(PoolFactory.class);
|
||||
|
||||
when(mockPoolFactory.addLocator(anyString(), anyInt())).thenAnswer(new Answer<PoolFactory>() {
|
||||
@Override
|
||||
public PoolFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
String host = invocation.getArgument(0);
|
||||
int port = invocation.getArgument(1);
|
||||
getLocatorList().add(newConnectionEndpoint(host, port));
|
||||
return mockPoolFactory;
|
||||
}
|
||||
PoolFactory mockPoolFactory = MockGemFireObjectsSupport.mockPoolFactory();
|
||||
|
||||
when(mockPoolFactory.addLocator(anyString(), anyInt())).thenAnswer(invocation -> {
|
||||
String host = invocation.getArgument(0);
|
||||
int port = invocation.getArgument(1);
|
||||
getLocatorList().add(newConnectionEndpoint(host, port));
|
||||
return mockPoolFactory;
|
||||
});
|
||||
|
||||
when(mockPoolFactory.addServer(anyString(), anyInt())).thenAnswer(new Answer<PoolFactory>() {
|
||||
@Override
|
||||
public PoolFactory answer(InvocationOnMock invocation) throws Throwable {
|
||||
String host = invocation.getArgument(0);
|
||||
int port = invocation.getArgument(1);
|
||||
getServerList().add(newConnectionEndpoint(host, port));
|
||||
return mockPoolFactory;
|
||||
}
|
||||
when(mockPoolFactory.addServer(anyString(), anyInt())).thenAnswer(invocation -> {
|
||||
String host = invocation.getArgument(0);
|
||||
int port = invocation.getArgument(1);
|
||||
getServerList().add(newConnectionEndpoint(host, port));
|
||||
return mockPoolFactory;
|
||||
});
|
||||
|
||||
return mockPoolFactory;
|
||||
Reference in New Issue
Block a user