use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testDiskWriteAttributes.
/**
* Tests {@code DiskWriteAttributes}
*/
@Test
public void testDiskWriteAttributes() throws Exception {
CacheCreation cache = new CacheCreation();
// Set properties for Asynch writes
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
RegionCreation root = (RegionCreation) cache.createRegion("root", attrs);
{
attrs = new RegionAttributesCreation(cache);
DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
dwaf.setSynchronous(true);
attrs.setDiskWriteAttributes(dwaf.create());
root.createSubregion("sync", attrs);
}
{
attrs = new RegionAttributesCreation(cache);
DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
dwaf.setTimeInterval(123L);
dwaf.setBytesThreshold(456L);
attrs.setDiskWriteAttributes(dwaf.create());
root.createSubregion("async", attrs);
}
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testAddEntriesViaCacheXml.
/**
* Tests that loading cache XML can add/update entries to a region.
*/
@Test
public void testAddEntriesViaCacheXml() throws Exception {
String key1 = "KEY1";
String value1 = "VALUE1";
CacheCreation creation = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
attrs.setScope(Scope.LOCAL);
Region root = creation.createRegion("root", attrs);
root.put(key1, value1);
testXml(creation);
Cache cache = getCache();
root = cache.getRegion("root");
assertEquals(1, root.entrySet(false).size());
assertEquals(value1, root.get(key1));
creation = new CacheCreation();
attrs = new RegionAttributesCreation(creation);
attrs.setScope(Scope.LOCAL);
String value2 = "VALUE2";
String key2 = "KEY2";
String value3 = "VALUE3";
root = creation.createRegion("root", attrs);
root.put(key1, value2);
root.put(key2, value3);
cache.loadCacheXml(generate(creation));
root = cache.getRegion("root");
assertEquals(2, root.entrySet(false).size());
assertEquals(value2, root.get(key1));
assertEquals(value3, root.get(key2));
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class ServerLauncherRemoteIntegrationTest method testStartUsingServerPortUsedInsteadOfDefaultCacheXml.
/**
* Confirms part of fix for #47664
*/
@Test
public void testStartUsingServerPortUsedInsteadOfDefaultCacheXml() throws Throwable {
// write out cache.xml with one port
final CacheCreation creation = new CacheCreation();
final RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
attrs.setScope(Scope.DISTRIBUTED_ACK);
attrs.setDataPolicy(DataPolicy.REPLICATE);
creation.createRegion(getUniqueName(), attrs);
creation.addCacheServer();
File cacheXmlFile = new File(this.temporaryFolder.getRoot(), getUniqueName() + ".xml");
final PrintWriter pw = new PrintWriter(new FileWriter(cacheXmlFile), true);
CacheXmlGenerator.generate(creation, pw);
pw.close();
// launch server and specify a different port
final List<String> jvmArguments = getJvmArguments();
jvmArguments.add("-D" + DistributionConfig.GEMFIRE_PREFIX + "" + CACHE_XML_FILE + "=" + cacheXmlFile.getCanonicalPath());
final List<String> command = new ArrayList<String>();
command.add(new File(new File(System.getProperty("java.home"), "bin"), "java").getCanonicalPath());
for (String jvmArgument : jvmArguments) {
command.add(jvmArgument);
}
command.add("-cp");
command.add(System.getProperty("java.class.path"));
command.add(ServerLauncher.class.getName());
command.add(ServerLauncher.Command.START.getName());
command.add(getUniqueName());
command.add("--redirect-output");
command.add("--server-port=" + this.serverPort);
final String expectedString = "java.net.BindException";
final AtomicBoolean outputContainedExpectedString = new AtomicBoolean();
this.process = new ProcessBuilder(command).directory(this.temporaryFolder.getRoot()).start();
this.processOutReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getInputStream()).inputListener(createExpectedListener("sysout", getUniqueName() + "#sysout", expectedString, outputContainedExpectedString)).build().start();
this.processErrReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()).inputListener(createExpectedListener("syserr", getUniqueName() + "#syserr", expectedString, outputContainedExpectedString)).build().start();
// wait for server to start up
int pid = 0;
this.launcher = new ServerLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
try {
waitForServerToStart();
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertTrue(this.pidFile.exists());
pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
// validate log file was created
final String logFileName = getUniqueName() + ".log";
assertTrue("Log file should exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
// verify server used --server-port instead of default or port in cache.xml
assertFalse(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
final ServerState status = this.launcher.status();
final String portString = status.getPort();
int port = Integer.valueOf(portString);
assertEquals("Port should be " + this.serverPort + " instead of " + port, this.serverPort, port);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the server
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForPidToStop(pid);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testOverflowAndBackup.
/**
* Tests the {@code overflowThreshold} and {@code persistBackup} related attributes
*/
@Test
public void testOverflowAndBackup() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setMirrorType(MirrorType.KEYS_VALUES);
attrs.setPersistBackup(true);
cache.createRegion("root", attrs);
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testEvictionLRUHeapAttributes.
@Test
public void testEvictionLRUHeapAttributes() throws Exception {
final String rName = getUniqueName();
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setEvictionAttributes(EvictionAttributes.createLRUHeapAttributes(new EvictionObjectSizer(), EvictionAction.LOCAL_DESTROY));
cache.createRegion(rName, attrs);
testXml(cache);
}
Aggregations