SGF-717 - Upgrade to Pivotal GemFire 9.3.0.

This commit is contained in:
John Blum
2018-02-05 12:26:04 -08:00
parent 09cde34c05
commit 598832af7f
6 changed files with 54 additions and 41 deletions

View File

@@ -16,11 +16,17 @@
package org.springframework.data.gemfire;
import static org.assertj.core.api.Assertions.*;
import static org.hamcrest.Matchers.*;
import static org.mockito.ArgumentMatchers.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.Collections;
@@ -37,9 +43,7 @@ import org.apache.geode.cache.query.Query;
import org.apache.geode.cache.query.QueryService;
import org.apache.geode.cache.query.SelectResults;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
@@ -55,19 +59,16 @@ import org.springframework.data.gemfire.test.support.AbstractUnitAndIntegrationT
* @see org.junit.Test
* @see org.mockito.Mock
* @see org.mockito.Mockito
* @see org.mockito.runners.MockitoJUnitRunner
* @see org.mockito.junit.MockitoJUnitRunner
* @see org.springframework.data.gemfire.GemfireTemplate
* @see AbstractUnitAndIntegrationTestsWithMockSupport
* @see org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer
* @see org.springframework.test.context.ContextConfiguration
*/
@RunWith(MockitoJUnitRunner.class)
@SuppressWarnings("unused")
@RunWith(MockitoJUnitRunner.class)
public class GemfireTemplateUnitTests extends AbstractUnitAndIntegrationTestsWithMockSupport {
@Rule
public ExpectedException exception = ExpectedException.none();
private GemfireTemplate template;
@Mock
@@ -100,13 +101,19 @@ public class GemfireTemplateUnitTests extends AbstractUnitAndIntegrationTestsWit
assertThat(localTemplate.isExposeNativeRegion()).isFalse();
}
@Test
@Test(expected = IllegalArgumentException.class)
public void constructWithNullRegionThrowsIllegalArgumentException() {
exception.expect(IllegalArgumentException.class);
exception.expectCause(is(nullValue(Throwable.class)));
exception.expectMessage("Region is required");
new GemfireTemplate(null);
try {
new GemfireTemplate(null);
}
catch (IllegalArgumentException expected) {
assertThat(expected).hasMessage("Region is required");
assertThat(expected).hasNoCause();
throw expected;
}
}
@Test
@@ -159,28 +166,32 @@ public class GemfireTemplateUnitTests extends AbstractUnitAndIntegrationTestsWit
@Test
public void findIsSuccessful() throws Exception {
Object[] expectedParams = { "arg" };
String expectedQuery = "SELECT * FROM /Example";
SelectResults mockSelectResults = mock(SelectResults.class);
when(mockQuery.execute(any(Object[].class))).thenReturn(mockSelectResults);
when(mockQuery.execute(any(Object.class))).thenReturn(mockSelectResults);
assertThat(template.find(expectedQuery, expectedParams)).isEqualTo(mockSelectResults);
verify(mockRegion, atLeastOnce()).getRegionService();
verify(mockRegionService, times(1)).getQueryService();
verify(mockQueryService, times(1)).newQuery(eq(expectedQuery));
verify(mockQuery, times(1)).execute(eq(expectedParams));
verify(mockQuery, times(1)).execute(eq("arg"));
verifyZeroInteractions(mockSelectResults);
}
@Test(expected = InvalidDataAccessApiUsageException.class)
public void findWithSingleResultQueryThrowsInvalidDataAccessApiUsageException() throws Exception {
Object[] expectedParams = { "arg" };
String expectedQuery = "SELECT 1 FROM /Example";
when(mockQuery.execute(any(Object[].class))).thenReturn(1);
when(mockQuery.execute(any(Object.class))).thenReturn(1);
try {
template.find(expectedQuery, expectedParams);
@@ -189,62 +200,68 @@ public class GemfireTemplateUnitTests extends AbstractUnitAndIntegrationTestsWit
verify(mockRegion, atLeastOnce()).getRegionService();
verify(mockRegionService, times(1)).getQueryService();
verify(mockQueryService, times(1)).newQuery(eq(expectedQuery));
verify(mockQuery, times(1)).execute(eq(expectedParams));
verify(mockQuery, times(1)).execute(eq("arg"));
}
}
@Test
public void findUniqueReturnsSelectResultsIsSuccessful() throws Exception {
Object[] expectedParams = { "arg" };
String expectedQuery = "SELECT 1 FROM /Example";
SelectResults mockSelectResults = mock(SelectResults.class);
when(mockQuery.execute(eq(expectedParams))).thenReturn(mockSelectResults);
when(mockQuery.execute(any(Object.class))).thenReturn(mockSelectResults);
when(mockSelectResults.asList()).thenReturn(Collections.singletonList(1));
assertThat(template.<Integer>findUnique(expectedQuery, expectedParams)).isEqualTo(1);
assertThat((Object) template.findUnique(expectedQuery, expectedParams)).isEqualTo(1);
verify(mockRegion, atLeastOnce()).getRegionService();
verify(mockRegionService, times(1)).getQueryService();
verify(mockQueryService, times(1)).newQuery(eq(expectedQuery));
verify(mockQuery, times(1)).execute(eq(expectedParams));
verify(mockQuery, times(1)).execute(eq("arg"));
verify(mockSelectResults, times(1)).asList();
}
@Test
public void findUniqueReturnsObjectIsSuccessful() throws Exception {
Object[] expectedParams = { "arg" };
String expectedQuery = "SELECT 1 FROM /Example";
when(mockQuery.execute(eq(expectedParams))).thenReturn("test");
when(mockQuery.execute(any(Object.class))).thenReturn("test");
assertThat(template.<String>findUnique(expectedQuery, expectedParams)).isEqualTo("test");
assertThat((Object) template.findUnique(expectedQuery, expectedParams)).isEqualTo("test");
verify(mockRegion, atLeastOnce()).getRegionService();
verify(mockRegionService, times(1)).getQueryService();
verify(mockQueryService, times(1)).newQuery(eq(expectedQuery));
verify(mockQuery, times(1)).execute(eq(expectedParams));
verify(mockQuery, times(1)).execute(eq("arg"));
}
@Test(expected = InvalidDataAccessApiUsageException.class)
public void findUniqueWithMultiResultQueryThrowsInvalidDataAccessApiUsageException() throws Exception {
Object[] expectedParams = { "arg" };
String expectedQuery = "SELECT 1 FROM /Example";
SelectResults mockSelectResults = mock(SelectResults.class);
when(mockQuery.execute(eq(expectedParams))).thenReturn(mockSelectResults);
when(mockQuery.execute(any(Object.class))).thenReturn(mockSelectResults);
when(mockSelectResults.asList()).thenReturn(Arrays.asList(1, 2));
try {
assertThat(template.<Integer>findUnique(expectedQuery, expectedParams)).isEqualTo(1);
assertThat((Object) template.findUnique(expectedQuery, expectedParams)).isEqualTo(1);
}
finally {
verify(mockRegion, atLeastOnce()).getRegionService();
verify(mockRegionService, times(1)).getQueryService();
verify(mockQueryService, times(1)).newQuery(eq(expectedQuery));
verify(mockQuery, times(1)).execute(eq(expectedParams));
verify(mockQuery, times(1)).execute(eq("arg"));
verify(mockSelectResults, times(1)).asList();
}
}

View File

@@ -24,8 +24,8 @@ import javax.annotation.Resource;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.EvictionAction;
import org.apache.geode.cache.EvictionAlgorithm;
import org.apache.geode.cache.EvictionAttributes;
import org.apache.geode.cache.Region;
import org.apache.geode.internal.cache.lru.LRUCapacityController;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
@@ -84,7 +84,7 @@ public class RegionEvictionAttributesNamespaceTest {
assertEquals(EvictionAction.LOCAL_DESTROY, two.getAttributes().getEvictionAttributes().getAction());
assertEquals(EvictionAlgorithm.LRU_ENTRY, two.getAttributes().getEvictionAttributes().getAlgorithm());
assertEquals(LRUCapacityController.DEFAULT_MAXIMUM_ENTRIES,
assertEquals(EvictionAttributes.DEFAULT_ENTRIES_MAXIMUM,
two.getAttributes().getEvictionAttributes().getMaximum());
}
@@ -135,5 +135,4 @@ public class RegionEvictionAttributesNamespaceTest {
assertEquals(expectedMaximum, six.getAttributes().getEvictionAttributes().getMaximum());
}
}

View File

@@ -90,8 +90,8 @@ public class LocatorProcess {
distributedSystemProperties.setProperty(DistributionConfig.LOG_LEVEL_NAME,
System.getProperty("spring.data.gemfire.log-level", GEMFIRE_LOG_LEVEL));
return InternalLocator.startLocator(locatorPort, null, null, null, null, null, distributedSystemProperties,
true, true, hostnameForClients, loadClusterConfigurationFromDirectory);
return InternalLocator.startLocator(locatorPort, null, null, null, null,
true, distributedSystemProperties, hostnameForClients);
}
@SuppressWarnings("unused")