Search in sources :

Example 26 with RegionAttributesCreation

use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.

the class CacheXml80DUnitTest method testCacheServerDisableTcpNoDelay.

@Test
public void testCacheServerDisableTcpNoDelay() throws Exception {
    CacheCreation cache = new CacheCreation();
    CacheServer cs = cache.addCacheServer();
    cs.setPort(0);
    cs.setTcpNoDelay(false);
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    attrs.setDataPolicy(DataPolicy.NORMAL);
    cache.createVMRegion("rootNORMAL", attrs);
    testXml(cache);
}
Also used : CacheServer(org.apache.geode.cache.server.CacheServer) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 27 with RegionAttributesCreation

use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation 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);
    }
}
Also used : FileWriter(java.io.FileWriter) ServerState(org.apache.geode.distributed.ServerLauncher.ServerState) ArrayList(java.util.ArrayList) Builder(org.apache.geode.distributed.ServerLauncher.Builder) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ProcessStreamReader(org.apache.geode.internal.process.ProcessStreamReader) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) File(java.io.File) PrintWriter(java.io.PrintWriter) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 28 with RegionAttributesCreation

use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation 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);
    }
}
Also used : FileWriter(java.io.FileWriter) Builder(org.apache.geode.distributed.ServerLauncher.Builder) ServerState(org.apache.geode.distributed.ServerLauncher.ServerState) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 29 with RegionAttributesCreation

use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation 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);
    }
}
Also used : FileWriter(java.io.FileWriter) Builder(org.apache.geode.distributed.ServerLauncher.Builder) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) File(java.io.File) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 30 with RegionAttributesCreation

use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.

the class RegionHelper method validateRegion.

public static void validateRegion(Cache cache, RegionConfiguration configuration, Region region) {
    // Get the attributes of the existing region
    RegionAttributes existingAttributes = region.getAttributes();
    // Create region attributes creation on existing region attributes.
    // The RAC is created to execute the sameAs method.
    RegionAttributesCreation existingRACreation = new RegionAttributesCreation(existingAttributes, false);
    // Create requested region attributes
    RegionAttributes requestedRegionAttributes = getRegionAttributes(cache, configuration);
    // Compare the two region attributes. This method either returns true or throws a
    // RuntimeException.
    existingRACreation.sameAs(requestedRegionAttributes);
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)

Aggregations

RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)87 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)86 Test (org.junit.Test)85 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)64 Region (org.apache.geode.cache.Region)37 Cache (org.apache.geode.cache.Cache)35 LocalRegion (org.apache.geode.internal.cache.LocalRegion)32 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)28 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)28 ClientCache (org.apache.geode.cache.client.ClientCache)27 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)17 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)14 File (java.io.File)13 RegionAttributes (org.apache.geode.cache.RegionAttributes)11 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)11 DiskWriteAttributesFactory (org.apache.geode.cache.DiskWriteAttributesFactory)10 FixedPartitionAttributes (org.apache.geode.cache.FixedPartitionAttributes)9 CacheServer (org.apache.geode.cache.server.CacheServer)8 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 PartitionAttributes (org.apache.geode.cache.PartitionAttributes)7