SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.

Removed the XSD enumeration restriction on the 'eviction-type' attribute of the 'subscription-config' sub-element of the 'cache-server' element inside the SDG XML namespace (XSD) allowing the use of property placeholders to specify the Eviction Policy for Client Subscription to GemFire Cache Servers.
This commit is contained in:
John Blum
2015-02-02 10:44:51 -08:00
parent 4fc92494ae
commit b8bd3c69f0
10 changed files with 614 additions and 104 deletions

View File

@@ -0,0 +1,233 @@
/*
* Copyright 2010-2013 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
*
* 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.springframework.data.gemfire.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.mockito.Matchers.same;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.InterestRegistrationListener;
import com.gemstone.gemfire.cache.server.CacheServer;
import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig;
import com.gemstone.gemfire.cache.server.ServerLoadProbe;
/**
* The CacheServerFactoryBeanTest class is a test suite of test cases testing the contract and functionality
* of the CacheServerFactoryBean class.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.server.CacheServerFactoryBean
* @since 1.6.0
*/
public class CacheServerFactoryBeanTest {
@Test
public void testGetObjectUninitialized() {
assertNull(new CacheServerFactoryBean().getObject());
}
@Test
public void testGetObjectType() {
assertEquals(CacheServer.class, new CacheServerFactoryBean().getObjectType());
}
@Test
public void testIsSingleton() {
assertTrue(new CacheServerFactoryBean().isSingleton());
}
@Test
@SuppressWarnings("deprecation")
public void testAfterPropertiesSet() throws IOException {
Cache mockCache = mock(Cache.class, "testAfterPropertiesSet.MockCache");
CacheServer mockCacheServer = mock(CacheServer.class, "testAfterPropertiesSet.MockCacheServer");
ClientSubscriptionConfig mockClientSubscriptionConfig = mock(ClientSubscriptionConfig.class,
"testAfterPropertiesSet.MockClientSubscriptionConfig");
InterestRegistrationListener mockInterestRegistrationListenerOne = mock(InterestRegistrationListener.class,
"testAfterPropertiesSet.MockInterestRegistrationListener.One");
InterestRegistrationListener mockInterestRegistrationListenerTwo = mock(InterestRegistrationListener.class,
"testAfterPropertiesSet.MockInterestRegistrationListener.Two");
ServerLoadProbe mockServerLoadProbe = mock(ServerLoadProbe.class, "testAfterPropertiesSet.MockServerLoadProbe");
when(mockCache.addCacheServer()).thenReturn(mockCacheServer);
when(mockCacheServer.getClientSubscriptionConfig()).thenReturn(mockClientSubscriptionConfig);
CacheServerFactoryBean factoryBean = new CacheServerFactoryBean();
factoryBean.setCache(mockCache);
factoryBean.setBindAddress("10.124.62.5");
factoryBean.setHostNameForClients("skullbox");
factoryBean.setListeners(new HashSet<InterestRegistrationListener>(Arrays.asList(
mockInterestRegistrationListenerOne, mockInterestRegistrationListenerTwo)));
factoryBean.setLoadPollInterval(500l);
factoryBean.setMaxConnections(200);
factoryBean.setMaxMessageCount(1024);
factoryBean.setMaxTimeBetweenPings(2000);
factoryBean.setMaxThreads(50);
factoryBean.setMessageTimeToLive(8192);
factoryBean.setNotifyBySubscription(true);
factoryBean.setPort(54321);
factoryBean.setServerGroups(new String[] { "testGroup" });
factoryBean.setServerLoadProbe(mockServerLoadProbe);
factoryBean.setSocketBufferSize(4096);
factoryBean.setSubscriptionCapacity(8196);
factoryBean.setSubscriptionEvictionPolicy(SubscriptionEvictionPolicy.ENTRY);
factoryBean.setSubscriptionDiskStore("toTheVoid");
factoryBean.afterPropertiesSet();
assertSame(mockCacheServer, factoryBean.getObject());
assertEquals(mockCacheServer.getClass(), factoryBean.getObjectType());
verify(mockCache, times(1)).addCacheServer();
verify(mockCacheServer, times(1)).setBindAddress(eq("10.124.62.5"));
verify(mockCacheServer, times(1)).setGroups(eq(new String[] { "testGroup" }));
verify(mockCacheServer, times(1)).setHostnameForClients(eq("skullbox"));
verify(mockCacheServer, times(1)).setLoadPollInterval(eq(500l));
verify(mockCacheServer, times(1)).setLoadProbe(same(mockServerLoadProbe));
verify(mockCacheServer, times(1)).setMaxConnections(eq(200));
verify(mockCacheServer, times(1)).setMaximumMessageCount(eq(1024));
verify(mockCacheServer, times(1)).setMaximumTimeBetweenPings(eq(2000));
verify(mockCacheServer, times(1)).setMaxThreads(eq(50));
verify(mockCacheServer, times(1)).setMessageTimeToLive(eq(8192));
verify(mockCacheServer, times(1)).setNotifyBySubscription(eq(true));
verify(mockCacheServer, times(1)).setPort(eq(54321));
verify(mockCacheServer, times(1)).setSocketBufferSize(eq(4096));
verify(mockCacheServer, times(1)).registerInterestRegistrationListener(
same(mockInterestRegistrationListenerOne));
verify(mockCacheServer, times(1)).registerInterestRegistrationListener(
same(mockInterestRegistrationListenerTwo));
verify(mockCacheServer, times(1)).getClientSubscriptionConfig();
verify(mockClientSubscriptionConfig, times(1)).setCapacity(eq(8196));
verify(mockClientSubscriptionConfig, times(1)).setDiskStoreName(eq("toTheVoid"));
verify(mockClientSubscriptionConfig, times(1)).setEvictionPolicy("entry");
}
@Test(expected = IllegalArgumentException.class)
public void testAfterPropertiesSetWithNullCache() throws IOException {
try {
new CacheServerFactoryBean().afterPropertiesSet();
}
catch (IllegalArgumentException expected) {
assertEquals("A GemFire Cache is required.", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAndGetAutoStartup() {
CacheServerFactoryBean factoryBean = new CacheServerFactoryBean();
assertTrue(factoryBean.isAutoStartup());
factoryBean.setAutoStartup(false);
assertFalse(factoryBean.isAutoStartup());
}
@Test
public void testSetAndGetSubscriptionEvictionPolicy() {
CacheServerFactoryBean factoryBean = new CacheServerFactoryBean();
assertEquals(SubscriptionEvictionPolicy.DEFAULT, factoryBean.getSubscriptionEvictionPolicy());
factoryBean.setSubscriptionEvictionPolicy(SubscriptionEvictionPolicy.MEM);
assertEquals(SubscriptionEvictionPolicy.MEM, factoryBean.getSubscriptionEvictionPolicy());
factoryBean.setSubscriptionEvictionPolicy(null);
assertEquals(SubscriptionEvictionPolicy.DEFAULT, factoryBean.getSubscriptionEvictionPolicy());
}
@Test
public void testCacheServerLifecycle() throws Exception {
CacheServer mockCacheServer = mock(CacheServer.class, "testCacheServerLifecycle.MockCacheServer");
final AtomicBoolean running = new AtomicBoolean(false);
final AtomicBoolean called = new AtomicBoolean(false);
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
running.compareAndSet(false, true);
return null;
}
}).when(mockCacheServer).start();
doAnswer(new Answer() {
@Override
public Object answer(final InvocationOnMock invocationOnMock) throws Throwable {
running.compareAndSet(true, false);
return null;
}
}).when(mockCacheServer).stop();
when(mockCacheServer.isRunning()).then(new Answer<Boolean>() {
@Override
public Boolean answer(final InvocationOnMock invocationOnMock) throws Throwable {
return running.get();
}
});
CacheServerFactoryBean factoryBean = new CacheServerFactoryBean();
factoryBean.setCacheServer(mockCacheServer);
assertSame(mockCacheServer, factoryBean.getObject());
assertFalse(factoryBean.isRunning());
factoryBean.start();
assertTrue(factoryBean.isRunning());
assertFalse(called.get());
factoryBean.stop(new Runnable() {
@Override public void run() {
called.set(true);
}
});
assertFalse(factoryBean.isRunning());
assertTrue(called.get());
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright 2010-2013 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
*
* 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.springframework.data.gemfire.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.After;
import org.junit.Test;
/**
* The SubscriptionEvictionPolicyConverterTest class is a test suite of test cases testing the contract
* and functionality of the SubscriptionEvictionPolicyConverter class.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter
* @since 1.6.0
*/
public class SubscriptionEvictionPolicyConverterTest {
private final SubscriptionEvictionPolicyConverter converter = new SubscriptionEvictionPolicyConverter();
@After
public void tearDown() {
converter.setValue(null);
}
@Test
public void testConvert() {
assertEquals(SubscriptionEvictionPolicy.ENTRY, converter.convert("EnTry"));
assertEquals(SubscriptionEvictionPolicy.MEM, converter.convert("MEM"));
assertEquals(SubscriptionEvictionPolicy.NONE, converter.convert("nONE"));
assertEquals(SubscriptionEvictionPolicy.NONE, converter.convert("NOne"));
}
@Test(expected = IllegalArgumentException.class)
public void testConvertIllegalValue() {
try {
converter.setAsText("memory");
}
catch (IllegalArgumentException expected) {
assertEquals("(memory) is not a valid SubscriptionEvictionPolicy!", expected.getMessage());
throw expected;
}
}
@Test
public void testSetAsText() {
assertNull(converter.getValue());
converter.setAsText("enTRY");
assertEquals(SubscriptionEvictionPolicy.ENTRY, converter.getValue());
converter.setAsText("MEm");
assertEquals(SubscriptionEvictionPolicy.MEM, converter.getValue());
}
@Test(expected = IllegalArgumentException.class)
public void testSetAsTextWithIllegalValue() {
try {
assertNull(converter.getValue());
converter.setAsText("KEYS");
}
catch (IllegalArgumentException expected) {
assertEquals("(KEYS) is not a valid SubscriptionEvictionPolicy!", expected.getMessage());
throw expected;
}
finally {
assertNull(converter.getValue());
}
}
}

View File

@@ -0,0 +1,87 @@
/*
* Copyright 2010-2013 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
*
* 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.springframework.data.gemfire.server;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.Test;
import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig;
/**
* The SubscriptionEvictionPolicyTest class is a test suite of test cases testing the contract and functionality
* of the SubscriptionEvictionPolicy enum.
*
* @author John Blum
* @see org.junit.Test
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy
* @since 1.6.0
*/
public class SubscriptionEvictionPolicyTest {
@Test
public void testDefault() {
assertEquals(ClientSubscriptionConfig.DEFAULT_EVICTION_POLICY.toLowerCase(),
SubscriptionEvictionPolicy.DEFAULT.name().toLowerCase());
assertSame(SubscriptionEvictionPolicy.NONE, SubscriptionEvictionPolicy.DEFAULT);
}
@Test
public void testValueOfIgnoreCase() {
assertEquals(SubscriptionEvictionPolicy.ENTRY, SubscriptionEvictionPolicy.valueOfIgnoreCase("entry"));
assertEquals(SubscriptionEvictionPolicy.MEM, SubscriptionEvictionPolicy.valueOfIgnoreCase("Mem"));
assertEquals(SubscriptionEvictionPolicy.NONE, SubscriptionEvictionPolicy.valueOfIgnoreCase("NOne"));
assertEquals(SubscriptionEvictionPolicy.NONE, SubscriptionEvictionPolicy.valueOfIgnoreCase("nONE"));
assertEquals(SubscriptionEvictionPolicy.NONE, SubscriptionEvictionPolicy.valueOfIgnoreCase("NONE"));
}
@Test
public void testValueOfIgnoreCaseWithIllegalValue() {
assertNull(SubscriptionEvictionPolicy.valueOfIgnoreCase("KEYS"));
assertNull(SubscriptionEvictionPolicy.valueOfIgnoreCase("Memory"));
assertNull(SubscriptionEvictionPolicy.valueOfIgnoreCase("all"));
assertNull(SubscriptionEvictionPolicy.valueOfIgnoreCase("no"));
assertNull(SubscriptionEvictionPolicy.valueOfIgnoreCase("one"));
assertNull(SubscriptionEvictionPolicy.valueOfIgnoreCase(" "));
assertNull(SubscriptionEvictionPolicy.valueOfIgnoreCase(""));
assertNull(SubscriptionEvictionPolicy.valueOfIgnoreCase(null));
}
@Test
public void testSetEvictionPolicy() {
ClientSubscriptionConfig mockConfig = mock(ClientSubscriptionConfig.class,
"testSetEvictionPolicy.ClientSubscriptionConfig");
ClientSubscriptionConfig returnedConfig = SubscriptionEvictionPolicy.MEM.setEvictionPolicy(mockConfig);
assertSame(mockConfig, returnedConfig);
verify(mockConfig, times(1)).setEvictionPolicy(eq("mem"));
}
@Test
public void testSetEvictionPolicyWithNull() {
assertNull(SubscriptionEvictionPolicy.ENTRY.setEvictionPolicy(null));
}
}