Search in sources :

Example 66 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class QueueCommandsDUnitTest method testCreateUpdatesSharedConfig.

/**
   * Asserts that creating async event queues correctly updates the shared configuration.
   */
// GEODE-1976
@Category(FlakyTest.class)
@Test
public void testCreateUpdatesSharedConfig() throws IOException {
    disconnectAllFromDS();
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    jmxPort = ports[0];
    httpPort = ports[1];
    try {
        jmxHost = InetAddress.getLocalHost().getHostName();
    } catch (UnknownHostException ignore) {
        jmxHost = "localhost";
    }
    final String queueName = "testAsyncEventQueueQueue";
    final String groupName = "testAsyncEventQueueSharedConfigGroup";
    final Properties locatorProps = new Properties();
    locatorProps.setProperty(NAME, "Locator");
    locatorProps.setProperty(MCAST_PORT, "0");
    locatorProps.setProperty(LOG_LEVEL, "fine");
    locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
    locatorProps.setProperty(JMX_MANAGER, "true");
    locatorProps.setProperty(JMX_MANAGER_START, "true");
    locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
    locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
    locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
    // Start the Locator and wait for shared configuration to be available
    final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        @Override
        public void run() {
            final File locatorLogFile = new File("locator-" + locatorPort + ".log");
            try {
                final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
                WaitCriterion wc = new WaitCriterion() {

                    @Override
                    public boolean done() {
                        return locator.isSharedConfigurationRunning();
                    }

                    @Override
                    public String description() {
                        return "Waiting for shared configuration to be started";
                    }
                };
                waitForCriterion(wc, 5000, 500, true);
            } catch (IOException ioex) {
                fail("Unable to create a locator with a shared configuration");
            }
        }
    });
    connect(jmxHost, jmxPort, httpPort, getDefaultShell());
    // Create a cache in VM 1
    VM vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
            localProps.setProperty(GROUPS, groupName);
            getSystem(localProps);
            assertNotNull(getCache());
        }
    });
    // Deploy a JAR file with an AsyncEventListener that can be instantiated on each server
    final File jarFile = new File(new File(".").getAbsolutePath(), "QueueCommandsDUnit.jar");
    QueueCommandsDUnitTest.this.filesToBeDeleted.add(jarFile.getAbsolutePath());
    ClassBuilder classBuilder = new ClassBuilder();
    byte[] jarBytes = classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener", "package com.qcdunit;" + "import java.util.List; import java.util.Properties;" + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;" + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;" + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {" + "Properties props;" + "public boolean processEvents(List<AsyncEvent> events) { return true; }" + "public void close() {}" + "public void init(final Properties props) {this.props = props;}" + "public Properties getConfig() {return this.props;}}");
    writeJarBytesToFile(jarFile, jarBytes);
    CommandResult cmdResult = executeCommand("deploy --jar=QueueCommandsDUnit.jar");
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Test creating the queue
    CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
    commandStringBuilder.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, queueName);
    commandStringBuilder.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP, groupName);
    commandStringBuilder.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER, "com.qcdunit.QueueCommandsDUnitTestListener");
    cmdResult = executeCommand(commandStringBuilder.toString());
    assertEquals(Result.Status.OK, cmdResult.getStatus());
    // Make sure the queue exists in the shared config
    Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {

        @Override
        public void run() {
            ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
            String xmlFromConfig;
            try {
                xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
                assertTrue(xmlFromConfig.contains(queueName));
            } catch (Exception e) {
                fail("Error occurred in cluster configuration service", e);
            }
        }
    });
    // Close cache in the vm1 and restart it to get the shared configuration
    vm = Host.getHost(0).getVM(1);
    vm.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            Cache cache = getCache();
            assertNotNull(cache);
            cache.close();
            assertTrue(cache.isClosed());
            Properties localProps = new Properties();
            localProps.setProperty(MCAST_PORT, "0");
            localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
            localProps.setProperty(GROUPS, groupName);
            localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
            getSystem(localProps);
            cache = getCache();
            assertNotNull(cache);
            AsyncEventQueue aeq = cache.getAsyncEventQueue(queueName);
            assertNotNull(aeq);
        }
    });
}
Also used : UnknownHostException(java.net.UnknownHostException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IOException(java.io.IOException) Properties(java.util.Properties) ClassBuilder(org.apache.geode.internal.ClassBuilder) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) InternalLocator(org.apache.geode.distributed.internal.InternalLocator) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) ClusterConfigurationService(org.apache.geode.distributed.internal.ClusterConfigurationService) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) File(java.io.File) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 67 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class ShellCommandsDUnitTest method testConnectToLocatorBecomesManager.

// GEODE-989: random ports, suspect string: DiskAccessException, disk
@Category(FlakyTest.class)
// pollution, HeadlessGfsh, time sensitive
@Test
public void testConnectToLocatorBecomesManager() {
    final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    final int jmxManagerPort = ports[0];
    final int locatorPort = ports[1];
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port", String.valueOf(jmxManagerPort));
    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-http-port", "0");
    assertEquals(String.valueOf(jmxManagerPort), System.getProperty(DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-port"));
    assertEquals("0", System.getProperty(DistributionConfig.GEMFIRE_PREFIX + "jmx-manager-http-port"));
    final String pathname = (getClass().getSimpleName() + "_" + getTestMethodName());
    final File workingDirectory = new File(pathname);
    workingDirectory.mkdir();
    assertTrue(workingDirectory.isDirectory());
    final LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setBindAddress(null).setForce(true).setMemberName(pathname).setPort(locatorPort).setWorkingDirectory(IOUtils.tryGetCanonicalPathElseGetAbsolutePath(workingDirectory)).build();
    assertNotNull(locatorLauncher);
    assertEquals(locatorPort, locatorLauncher.getPort().intValue());
    try {
        // fix for bug 46729
        locatorLauncher.start();
        final LocatorState locatorState = locatorLauncher.waitOnStatusResponse(60, 10, TimeUnit.SECONDS);
        assertNotNull(locatorState);
        assertEquals(Status.ONLINE, locatorState.getStatus());
        final Result result = connectToLocator(locatorPort);
        assertNotNull(result);
        assertEquals(Result.Status.OK, result.getStatus());
    } finally {
        assertEquals(Status.STOPPED, locatorLauncher.stop().getStatus());
        assertEquals(Status.NOT_RESPONDING, locatorLauncher.status().getStatus());
    }
}
Also used : LocatorLauncher(org.apache.geode.distributed.LocatorLauncher) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Result(org.apache.geode.management.cli.Result) Category(org.junit.experimental.categories.Category) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 68 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class ShowMetricsDUnitTest method testShowMetricsMember.

// GEODE-1764
@Category(FlakyTest.class)
@Test
public void testShowMetricsMember() throws ClassNotFoundException, IOException, InterruptedException {
    systemSetUp();
    Cache cache = getCache();
    final DistributedMember distributedMember = cache.getDistributedSystem().getDistributedMember();
    final String exportFileName = "memberMetricReport.csv";
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(1);
    CacheServer cs = getCache().addCacheServer();
    cs.setPort(ports[0]);
    cs.start();
    final int cacheServerPort = cs.getPort();
    SerializableCallable showMetricCmd = new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            WaitCriterion wc = createMBeanWaitCriterion(3, "", distributedMember, 0);
            waitForCriterion(wc, 5000, 500, true);
            wc = createMBeanWaitCriterion(5, "", distributedMember, cacheServerPort);
            waitForCriterion(wc, 10000, 500, true);
            final String command = CliStrings.SHOW_METRICS + " --" + CliStrings.SHOW_METRICS__MEMBER + "=" + distributedMember.getId() + " --" + CliStrings.SHOW_METRICS__CACHESERVER__PORT + "=" + cacheServerPort + " --" + CliStrings.SHOW_METRICS__FILE + "=" + exportFileName;
            CommandProcessor commandProcessor = new CommandProcessor();
            Result result = commandProcessor.createCommandStatement(command, Collections.EMPTY_MAP).process();
            String resultAsString = commandResultToString((CommandResult) result);
            assertEquals(resultAsString, true, result.getStatus().equals(Status.OK));
            assertTrue(result.hasIncomingFiles());
            result.saveIncomingFiles(null);
            File file = new File(exportFileName);
            file.deleteOnExit();
            assertTrue(file.exists());
            file.delete();
            return resultAsString;
        }
    };
    // Invoke the command in the Manager VM
    final VM managerVm = Host.getHost(0).getVM(0);
    Object managerResultObj = managerVm.invoke(showMetricCmd);
    String managerResult = (String) managerResultObj;
    getLogWriter().info("#SB Manager");
    getLogWriter().info(managerResult);
    cs.stop();
}
Also used : Result(org.apache.geode.management.cli.Result) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheServer(org.apache.geode.cache.server.CacheServer) CommandProcessor(org.apache.geode.management.internal.cli.remote.CommandProcessor) File(java.io.File) Cache(org.apache.geode.cache.Cache) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 69 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class LocatorDUnitTest method testStartTwoLocators.

/**
   * Bug 30341 concerns race conditions in JGroups that allow two locators to start up in a
   * split-brain configuration. To work around this we have always told customers that they need to
   * stagger the starting of locators. This test configures two locators to start up simultaneously
   * and shows that they find each other and form a single system.
   */
// GEODE-1931
@Category(FlakyTest.class)
@Test
public void testStartTwoLocators() throws Exception {
    disconnectAllFromDS();
    Host host = Host.getHost(0);
    VM loc1 = host.getVM(1);
    VM loc2 = host.getVM(2);
    int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
    final int port1 = ports[0];
    this.port1 = port1;
    final int port2 = ports[1];
    // for cleanup in tearDown2
    this.port2 = port2;
    DistributedTestUtils.deleteLocatorStateFile(port1);
    DistributedTestUtils.deleteLocatorStateFile(port2);
    final String host0 = NetworkUtils.getServerHostName(host);
    final String locators = host0 + "[" + port1 + "]," + host0 + "[" + port2 + "]";
    final Properties properties = new Properties();
    properties.put(MCAST_PORT, "0");
    properties.put(LOCATORS, locators);
    properties.put(ENABLE_NETWORK_PARTITION_DETECTION, "false");
    properties.put(DISABLE_AUTO_RECONNECT, "true");
    properties.put(MEMBER_TIMEOUT, "2000");
    properties.put(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
    properties.put(ENABLE_CLUSTER_CONFIGURATION, "false");
    addDSProps(properties);
    startVerifyAndStopLocator(loc1, loc2, port1, port2, properties);
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) Properties(java.util.Properties) Category(org.junit.experimental.categories.Category) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest)

Example 70 with Category

use of org.junit.experimental.categories.Category in project geode by apache.

the class LocatorLauncherRemoteIntegrationTest method testStartCreatesPidFile.

/*
                          * // TODO: fix up this test
                          * 
                          * this.temporaryFolder.getRoot() = new File(getUniqueName());
                          * this.temporaryFolder.getRoot().mkdir();
                          * assertTrue(this.temporaryFolder.getRoot().isDirectory() &&
                          * this.temporaryFolder.getRoot().canWrite());
                          * 
                          * // launch LocatorLauncherForkingProcess which then launches the GemFire
                          * Locator final List<String> jvmArguments = getJvmArguments();
                          * 
                          * 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(LocatorLauncherRemoteDUnitTest.class.getName().concat("$").
                          * concat(LocatorLauncherForkingProcess.class.getSimpleName()));
                          * command.add(String.valueOf(this.locatorPort));
                          * 
                          * this.process = new
                          * ProcessBuilder(command).directory(this.temporaryFolder.getRoot()).start(
                          * ); this.processOutReader = new
                          * ProcessStreamReader.Builder(this.process).inputStream(this.process.
                          * getInputStream()).build().start(); this.processErrReader = new
                          * ProcessStreamReader.Builder(this.process).inputStream(this.process.
                          * getErrorStream()).build().start();
                          * 
                          * Thread waiting = new Thread(new Runnable() { public void run() { try {
                          * assertIndexDetailsEquals(0, process.waitFor()); } catch
                          * (InterruptedException ignore) {
                          * logger.error("Interrupted while waiting for process!", ignore); } } });
                          * 
                          * try { waiting.start(); waiting.join(TIMEOUT_MILLISECONDS);
                          * assertFalse("Process took too long and timed out!", waiting.isAlive());
                          * } finally { if (waiting.isAlive()) { waiting.interrupt(); } }
                          * 
                          * LocatorLauncher locatorLauncher = new
                          * Builder().setWorkingDirectory(this.temporaryFolder.getRoot().
                          * getCanonicalPath()).build();
                          * 
                          * assertIndexDetailsEquals(Status.ONLINE,
                          * locatorLauncher.status().getStatus());
                          * assertIndexDetailsEquals(Status.STOPPED,
                          * locatorLauncher.stop().getStatus()); }
                          */
// GEODE-473: random ports, BindException, forks JVM, uses
@Category(FlakyTest.class)
// ErrorCollector
@Test
public void testStartCreatesPidFile() throws Throwable {
    // build and start the locator
    final List<String> jvmArguments = getJvmArguments();
    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(LocatorLauncher.class.getName());
    command.add(LocatorLauncher.Command.START.getName());
    command.add(getUniqueName());
    command.add("--port=" + this.locatorPort);
    command.add("--redirect-output");
    this.process = new ProcessBuilder(command).directory(this.temporaryFolder.getRoot()).start();
    this.processOutReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getInputStream()).build().start();
    this.processErrReader = new ProcessStreamReader.Builder(this.process).inputStream(this.process.getErrorStream()).build().start();
    int pid = 0;
    this.launcher = new LocatorLauncher.Builder().setWorkingDirectory(this.temporaryFolder.getRoot().getCanonicalPath()).build();
    try {
        waitForLocatorToStart(this.launcher);
        // validate the pid file and its contents
        this.pidFile = new File(this.temporaryFolder.getRoot(), ProcessType.LOCATOR.getPidFileName());
        assertTrue(this.pidFile.exists());
        pid = readPid(this.pidFile);
        assertTrue(pid > 0);
        assertTrue(ProcessUtils.isProcessAlive(pid));
        final String logFileName = getUniqueName() + ".log";
        assertTrue("Log file should exist: " + logFileName, new File(this.temporaryFolder.getRoot(), logFileName).exists());
        // check the status
        final LocatorState locatorState = this.launcher.status();
        assertNotNull(locatorState);
        assertEquals(Status.ONLINE, locatorState.getStatus());
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
    // stop the locator
    try {
        assertEquals(Status.STOPPED, this.launcher.stop().getStatus());
        waitForPidToStop(pid);
    } catch (Throwable e) {
        this.errorCollector.addError(e);
    }
}
Also used : Builder(org.apache.geode.distributed.LocatorLauncher.Builder) Builder(org.apache.geode.distributed.LocatorLauncher.Builder) ArrayList(java.util.ArrayList) LocatorState(org.apache.geode.distributed.LocatorLauncher.LocatorState) File(java.io.File) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Category (org.junit.experimental.categories.Category)900 Test (org.junit.Test)856 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)148 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)121 File (java.io.File)102 Instant (org.joda.time.Instant)92 KV (org.apache.beam.sdk.values.KV)86 ArrayList (java.util.ArrayList)84 Row (org.apache.beam.sdk.values.Row)71 Schema (org.apache.beam.sdk.schemas.Schema)65 VM (org.apache.geode.test.dunit.VM)65 QuickTest (com.hazelcast.test.annotation.QuickTest)57 List (java.util.List)57 Matchers.containsString (org.hamcrest.Matchers.containsString)55 InputStream (java.io.InputStream)49 NightlyTest (com.hazelcast.test.annotation.NightlyTest)47 FileListView (com.owncloud.android.test.ui.models.FileListView)46 UsesSchema (org.apache.beam.sdk.testing.UsesSchema)43 StringUtils.byteArrayToJsonString (org.apache.beam.sdk.util.StringUtils.byteArrayToJsonString)41 IOException (java.io.IOException)40