Add Integration Tests for @EnableDiskStore annotation and DiskStoreConfiguration class.

Closes #645
This commit is contained in:
John Blum
2023-04-17 13:28:28 -07:00
parent 487ae967ca
commit b9a11e9dda
4 changed files with 147 additions and 3 deletions

View File

@@ -78,6 +78,7 @@ public class DiskStoreConfiguration extends AbstractAnnotationConfigSupport
protected static final long DEFAULT_MAX_OPLOG_SIZE = 1024L;
protected static final long DEFAULT_TIME_INTERVAL = DiskStoreFactory.DEFAULT_TIME_INTERVAL;
@SuppressWarnings("all")
@Autowired(required = false)
private List<DiskStoreConfigurer> diskStoreConfigurers = Collections.emptyList();

View File

@@ -14,7 +14,6 @@
* limitations under the License.
*
*/
package org.springframework.data.gemfire.config.annotation;
import static org.springframework.data.gemfire.config.annotation.DiskStoreConfiguration.DEFAULT_ALLOW_FORCE_COMPACTION;

View File

@@ -12,11 +12,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.config.xml;
/**
* The GemfireConstants class define constants for Spring GemFire component bean names.
* Spring GemFire component bean names.
*
* @author David Turanski
* @author John Blum
@@ -27,6 +26,7 @@ public interface GemfireConstants {
String DEFAULT_GEMFIRE_CACHE_NAME = "gemfireCache";
String DEFAULT_GEMFIRE_INDEX_DEFINITION_QUERY_SERVICE = "gemfireIndexDefinitionQueryService";
String DEFAULT_GEMFIRE_FUNCTION_SERVICE_NAME = "gemfireFunctionService";
String DEFAULT_GEMFIRE_DISK_STORE_NAME = "DEFAULT";
String DEFAULT_GEMFIRE_POOL_NAME = "gemfirePool";
String DEFAULT_GEMFIRE_TRANSACTION_MANAGER_NAME = "gemfireTransactionManager";

View File

@@ -0,0 +1,144 @@
/*
* Copyright 2022 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.config.annotation;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.File;
import jakarta.annotation.Resource;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.apache.geode.cache.DataPolicy;
import org.apache.geode.cache.DiskStore;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.Region;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.data.gemfire.ReplicatedRegionFactoryBean;
import org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport;
import org.springframework.data.gemfire.tests.util.FileSystemUtils;
import org.springframework.data.gemfire.util.RegionUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration Tests for {@link EnableDiskStore} and {@link EnableDiskStores} annotations
* along with the {@link DiskStoreConfiguration} class.
*
* @author John Blum
* @see java.io.File
* @see org.junit.Test
* @see org.apache.geode.cache.GemFireCache
* @see org.apache.geode.cache.DiskStore
* @see org.apache.geode.cache.Region
* @see org.springframework.data.gemfire.tests.integration.IntegrationTestsSupport
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringRunner
* @since 3.0.0
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class EnableDiskStoresConfigurationIntegrationTests extends IntegrationTestsSupport {
private static final String DISK_STORE_LOCATION_PROPERTY =
"spring.data.gemfire.disk.store.ParkDiskStore.directory.location";
private static final File DISK_STORE_LOCATION = new File(System.getProperty("java.io.tmpdir"),
"/spring/geode/tests/EnableDiskStoresConfigurationIntegrationTests");
@Autowired
private GemFireCache cache;
@Resource(name = "DiskBasedRegion")
private Region<Object, Object> diskBasedRegion;
@BeforeClass
public static void setSpringDataGemFireDiskStoreDirectoryLocationAsSystemProperty() {
System.setProperty(DISK_STORE_LOCATION_PROPERTY, DISK_STORE_LOCATION.getAbsolutePath());
assertThat(DISK_STORE_LOCATION).doesNotExist();
}
@AfterClass
public static void clearSystemProperties() {
System.clearProperty(DISK_STORE_LOCATION_PROPERTY);
FileSystemUtils.deleteRecursive(DISK_STORE_LOCATION);
}
@Before
public void assertCache() {
assertThat(this.cache).isNotNull();
assertThat(this.cache.getName()).isEqualTo(EnableDiskStoresConfigurationIntegrationTests.class.getSimpleName());
}
@Before
public void assertRegion() {
assertThat(this.diskBasedRegion).isNotNull();
assertThat(this.diskBasedRegion.getName()).isEqualTo(RegionUtils.toRegionName("DiskBasedRegion"));
assertThat(this.diskBasedRegion.getFullPath())
.isEqualTo(RegionUtils.toRegionPath("DiskBasedRegion"));
assertThat(this.diskBasedRegion.getAttributes()).isNotNull();
assertThat(this.diskBasedRegion.getAttributes().getDataPolicy()).isEqualTo(DataPolicy.PERSISTENT_REPLICATE);
}
@Test
public void customDiskStoreConfigurationIsCorrect() {
String diskStoreName = this.diskBasedRegion.getAttributes().getDiskStoreName();
assertThat(diskStoreName).isNotBlank();
DiskStore diskStore = this.cache.findDiskStore(diskStoreName);
assertThat(diskStore).isNotNull();
assertThat(diskStore.getName()).isEqualTo("ParkDiskStore");
File[] diskDirectories = diskStore.getDiskDirs();
assertThat(diskDirectories).isNotNull();
assertThat(diskDirectories).hasSize(1);
assertThat(diskDirectories[0]).isEqualTo(DISK_STORE_LOCATION);
assertThat(diskDirectories[0]).isDirectory();
}
@PeerCacheApplication(name = "EnableDiskStoresConfigurationIntegrationTests")
@EnableDiskStore(name = "ParkDiskStore")
static class TestConfiguration {
@Bean("DiskBasedRegion")
@DependsOn("ParkDiskStore")
ReplicatedRegionFactoryBean<Object, Object> diskBasedRegion(GemFireCache cache) {
ReplicatedRegionFactoryBean<Object, Object> regionBean = new ReplicatedRegionFactoryBean<>();
regionBean.setCache(cache);
regionBean.setDiskStoreName("ParkDiskStore");
regionBean.setPersistent(true);
return regionBean;
}
}
}