use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testREPLICATE_OVERFLOW.
@Test
public void testREPLICATE_OVERFLOW() throws Exception {
CacheCreation cache = new CacheCreation();
RegionCreation root = (RegionCreation) cache.createRegion("replicateoverflow", "REPLICATE_OVERFLOW");
testXml(cache);
GemFireCacheImpl c = (GemFireCacheImpl) getCache();
Region r = c.getRegion("replicateoverflow");
assertNotNull(r);
RegionAttributes ra = r.getAttributes();
assertEquals(DataPolicy.REPLICATE, ra.getDataPolicy());
assertEquals(Scope.DISTRIBUTED_ACK, ra.getScope());
assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes());
assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, c.getResourceManager().getEvictionHeapPercentage(), 0);
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class ServerLauncherRemoteIntegrationTest method testStartUsingServerPortOverridesCacheXml.
/**
* Confirms part of fix for #47664
*/
@Test
public void testStartUsingServerPortOverridesCacheXml() throws Throwable {
// generate two free ports
final int[] freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
// 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().setPort(freeTCPPorts[0]);
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=" + freeTCPPorts[1]);
String expectedString = "java.net.BindException";
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
assertTrue(AvailablePort.isPortAvailable(freeTCPPorts[0], AvailablePort.SOCKET));
assertFalse(AvailablePort.isPortAvailable(freeTCPPorts[1], AvailablePort.SOCKET));
ServerState status = this.launcher.status();
String portString = status.getPort();
int port = Integer.valueOf(portString);
assertEquals("Port should be " + freeTCPPorts[1] + " instead of " + port, freeTCPPorts[1], port);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the server
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForPidToStop(pid);
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class ServerLauncherLocalIntegrationTest method testStartUsingServerPortOverridesCacheXml.
/*
* assertTrue(getUniqueName() + " is broken if PID == Integer.MAX_VALUE",
* ProcessUtils.identifyPid() != Integer.MAX_VALUE);
*
* // create existing pid file this.pidFile = new
* File(ProcessType.SERVER.getPidFileName()); final int realPid =
* Host.getHost(0).getVM(3).invoke(() -> ProcessUtils.identifyPid());
* assertFalse(realPid == ProcessUtils.identifyPid());
* writePid(this.pidFile, realPid);
*
* // build and start the server final Builder builder = new Builder()
* .setDisableDefaultServer(true) .setForce(true)
* .setMemberName(getUniqueName()) .setRedirectOutput(true)
* .set(DistributionConfig.ConfigurationProperties.MCAST_PORT, "0");
*
* assertTrue(builder.getForce()); this.launcher = builder.build();
* assertTrue(this.launcher.isForcing()); this.launcher.start();
*
* // collect and throw the FIRST failure Throwable failure = null;
*
* try { waitForServerToStart(this.launcher);
*
* // validate the pid file and its contents
* assertTrue(this.pidFile.exists()); final int pid =
* readPid(this.pidFile); assertTrue(pid > 0);
* assertTrue(ProcessUtils.isProcessAlive(pid));
* assertIndexDetailsEquals(getPid(), pid);
*
* // validate log file was created final String logFileName =
* getUniqueName()+".log"; assertTrue("Log file should exist: " +
* logFileName, new File(logFileName).exists());
*
* } catch (Throwable e) { logger.error(e); if (failure == null) { failure
* = e; } }
*
* try { assertIndexDetailsEquals(Status.STOPPED,
* this.launcher.stop().getStatus()); waitForFileToDelete(this.pidFile); }
* catch (Throwable e) { logger.error(e); if (failure == null) { failure =
* e; } }
*
* if (failure != null) { throw failure; } } //
* testStartUsingForceOverwritesExistingPidFile
*/
/**
* Confirms part of fix for #47664
*/
@Test
public void testStartUsingServerPortOverridesCacheXml() throws Throwable {
// verifies part of the fix for #47664
String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
// generate two free ports
final int[] freeTCPPorts = AvailablePortHelper.getRandomAvailableTCPPorts(2);
assertTrue(AvailablePort.isPortAvailable(freeTCPPorts[0], AvailablePort.SOCKET));
assertTrue(AvailablePort.isPortAvailable(freeTCPPorts[1], AvailablePort.SOCKET));
// 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().setPort(freeTCPPorts[0]);
File cacheXmlFile = this.temporaryFolder.newFile(getUniqueName() + ".xml");
final PrintWriter pw = new PrintWriter(new FileWriter(cacheXmlFile), true);
CacheXmlGenerator.generate(creation, pw);
pw.close();
System.setProperty(CACHE_XML_FILE, cacheXmlFile.getCanonicalPath());
// start server
final Builder builder = new Builder().setMemberName(getUniqueName()).setRedirectOutput(true).setServerPort(freeTCPPorts[1]).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(MCAST_PORT, "0");
this.launcher = builder.build();
this.launcher.start();
// wait for server to start up
try {
waitForServerToStart(this.launcher);
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertTrue(this.pidFile.exists());
int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
assertEquals(getPid(), pid);
// verify server used --server-port instead of default or port in cache.xml
assertTrue(AvailablePort.isPortAvailable(freeTCPPorts[0], AvailablePort.SOCKET));
assertFalse(AvailablePort.isPortAvailable(freeTCPPorts[1], AvailablePort.SOCKET));
final ServerState status = this.launcher.status();
final String portString = status.getPort();
final int port = Integer.valueOf(portString);
assertEquals("Port should be " + freeTCPPorts[1] + " instead of " + port, freeTCPPorts[1], port);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
// stop the server
try {
assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
waitForFileToDelete(this.pidFile);
assertFalse("PID file still exists!", pidFile.exists());
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class ServerLauncherLocalIntegrationTest method testStartUsingServerPortUsedInsteadOfDefaultCacheXml.
/**
* Confirms part of fix for #47664
*/
@Test
public void testStartUsingServerPortUsedInsteadOfDefaultCacheXml() throws Throwable {
String rootFolder = this.temporaryFolder.getRoot().getCanonicalPath();
// 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 = this.temporaryFolder.newFile(getUniqueName() + ".xml");
final PrintWriter pw = new PrintWriter(new FileWriter(cacheXmlFile), true);
CacheXmlGenerator.generate(creation, pw);
pw.close();
System.setProperty(CACHE_XML_FILE, cacheXmlFile.getCanonicalPath());
// start server
final Builder builder = new Builder().setMemberName(getUniqueName()).setRedirectOutput(true).setServerPort(this.serverPort).setWorkingDirectory(rootFolder).set(LOG_LEVEL, "config").set(MCAST_PORT, "0");
this.launcher = builder.build();
this.launcher.start();
// wait for server to start up
try {
waitForServerToStart(this.launcher);
// validate the pid file and its contents
this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.SERVER.getPidFileName());
assertTrue(this.pidFile.exists());
int pid = readPid(this.pidFile);
assertTrue(pid > 0);
assertTrue(ProcessUtils.isProcessAlive(pid));
assertEquals(getPid(), pid);
// verify server used --server-port instead of default
assertFalse(AvailablePort.isPortAvailable(this.serverPort, AvailablePort.SOCKET));
final int port = Integer.valueOf(this.launcher.status().getPort());
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());
waitForFileToDelete(this.pidFile);
} catch (Throwable e) {
this.errorCollector.addError(e);
}
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class AsyncEventQueueFactoryImpl method create.
public AsyncEventQueue create(String asyncQueueId, AsyncEventListener listener) {
if (listener == null) {
throw new IllegalArgumentException(LocalizedStrings.AsyncEventQueue_ASYNC_EVENT_LISTENER_CANNOT_BE_NULL.toLocalizedString());
}
AsyncEventQueue asyncEventQueue = null;
if (this.cache instanceof GemFireCacheImpl) {
if (logger.isDebugEnabled()) {
logger.debug("Creating GatewaySender that underlies the AsyncEventQueue");
}
addAsyncEventListener(listener);
GatewaySender sender = create(AsyncEventQueueImpl.getSenderIdFromAsyncEventQueueId(asyncQueueId));
AsyncEventQueueImpl queue = new AsyncEventQueueImpl(sender, listener);
asyncEventQueue = queue;
this.cache.addAsyncEventQueue(queue);
} else if (this.cache instanceof CacheCreation) {
asyncEventQueue = new AsyncEventQueueCreation(asyncQueueId, attrs, listener);
((CacheCreation) cache).addAsyncEventQueue(asyncEventQueue);
}
if (logger.isDebugEnabled()) {
logger.debug("Returning AsyncEventQueue" + asyncEventQueue);
}
return asyncEventQueue;
}
Aggregations