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);
}
});
}
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());
}
}
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();
}
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);
}
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);
}
}
Aggregations