use of org.apache.geode.internal.logging.LocalLogWriter in project geode by apache.
the class LocatorDUnitTest method testNoLocator.
/**
* Tests that attempting to connect to a distributed system in which no locator is defined throws
* an exception.
*/
@Test
public void testNoLocator() {
disconnectAllFromDS();
Host host = Host.getHost(0);
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
DistributedTestUtils.deleteLocatorStateFile(port1);
String locators = NetworkUtils.getServerHostName(host) + "[" + port + "]";
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, locators);
addDSProps(props);
final String expected = "java.net.ConnectException";
final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
bgexecLogger.info(addExpected);
boolean exceptionOccurred = true;
try {
DistributedSystem.connect(props);
exceptionOccurred = false;
} catch (DistributionException ex) {
// I guess it can throw this too...
} catch (GemFireConfigException ex) {
String s = ex.getMessage();
assertTrue(s.indexOf("Locator does not exist") >= 0);
} catch (Exception ex) {
// if you see this fail, determine if unexpected exception is expected
// if expected then add in a catch block for it above this catch
org.apache.geode.test.dunit.Assert.fail("Failed with unexpected exception", ex);
} finally {
bgexecLogger.info(removeExpected);
}
if (!exceptionOccurred) {
fail("Should have thrown a GemFireConfigException");
}
}
use of org.apache.geode.internal.logging.LocalLogWriter in project geode by apache.
the class QueueManagerJUnitTest method setUp.
@Before
public void setUp() {
this.logger = new LocalLogWriter(InternalLogWriter.FINEST_LEVEL, System.out);
Properties properties = new Properties();
properties.put(MCAST_PORT, "0");
properties.put(LOCATORS, "");
ds = DistributedSystem.connect(properties);
stats = new PoolStats(ds, "QueueManagerJUnitTest");
pool = new DummyPool();
endpoints = new EndpointManagerImpl("pool", ds, ds.getCancelCriterion(), pool.getStats());
source = new DummySource();
factory = new DummyFactory();
background = Executors.newSingleThreadScheduledExecutor();
final String addExpectedPEM = "<ExpectedException action=add>" + expectedPrimaryErrorMsg + "</ExpectedException>";
final String addExpectedREM = "<ExpectedException action=add>" + expectedRedundantErrorMsg + "</ExpectedException>";
ds.getLogWriter().info(addExpectedPEM);
ds.getLogWriter().info(addExpectedREM);
}
use of org.apache.geode.internal.logging.LocalLogWriter in project geode by apache.
the class LocatorLoadBalancingDUnitTest method checkLocatorLoad.
public void checkLocatorLoad(final Map expected) {
List locators = Locator.getLocators();
Assert.assertEquals(1, locators.size());
InternalLocator locator = (InternalLocator) locators.get(0);
final ServerLocator sl = locator.getServerLocatorAdvisee();
InternalLogWriter log = new LocalLogWriter(InternalLogWriter.FINEST_LEVEL, System.out);
sl.getDistributionAdvisor().dumpProfiles("PROFILES= ");
Awaitility.await().pollDelay(100, TimeUnit.MILLISECONDS).pollInterval(100, TimeUnit.MILLISECONDS).timeout(300, TimeUnit.SECONDS).until(() -> expected.equals(sl.getLoadMap()));
}
use of org.apache.geode.internal.logging.LocalLogWriter in project geode by apache.
the class ConnectionManagerJUnitTest method setUp.
@Before
public void setUp() {
this.logger = new LocalLogWriter(InternalLogWriter.FINEST_LEVEL, System.out);
factory = new DummyFactory();
Properties properties = new Properties();
properties.put(MCAST_PORT, "0");
properties.put(LOCATORS, "");
ds = DistributedSystem.connect(properties);
background = Executors.newSingleThreadScheduledExecutor();
poolStats = new PoolStats(ds, "connectionManagerJUnitTest");
endpointManager = new EndpointManagerImpl("pool", ds, ds.getCancelCriterion(), poolStats);
cancelCriterion = new CancelCriterion() {
public String cancelInProgress() {
return null;
}
public RuntimeException generateCancelledException(Throwable e) {
return null;
}
};
}
use of org.apache.geode.internal.logging.LocalLogWriter in project geode by apache.
the class ConnectionPoolDUnitTest method basicTestBridgeServerFailover.
private void basicTestBridgeServerFailover(final int cnxCount) throws CacheException {
final String name = this.getName();
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
// Create two bridge servers
SerializableRunnable createCacheServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = getBridgeServerRegionAttributes(null, null);
createRegion(name, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
};
vm0.invoke(createCacheServer);
vm1.invoke(createCacheServer);
final int port0 = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
final int port1 = vm1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
// final String host1 = getServerHostName(vm1.getHost());
// Create one bridge client in this VM
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(factory, host0, port0, port1, true, -1, cnxCount, null, 100);
Region region = createRegion(name, factory.create());
// force connections to form
region.put("keyInit", new Integer(0));
region.put("keyInit2", new Integer(0));
}
};
vm2.invoke(create);
// Launch async thread that puts objects into cache. This thread will execute until
// the test has ended (which is why the RegionDestroyedException and CacheClosedException
// are caught and ignored. If any other exception occurs, the test will fail. See
// the putAI.exceptionOccurred() assertion below.
AsyncInvocation putAI = vm2.invokeAsync(new CacheSerializableRunnable("Put objects") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
try {
for (int i = 0; i < 100000; i++) {
region.put("keyAI", new Integer(i));
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
fail("interrupted");
}
}
} catch (NoAvailableServersException ignore) {
/* ignore */
} catch (RegionDestroyedException e) {
// will be thrown when the test ends
/* ignore */
} catch (CancelException e) {
// will be thrown when the test ends
/* ignore */
}
}
});
SerializableRunnable verify1Server = new CacheSerializableRunnable("verify1Server") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
PoolImpl pool = getPool(region);
verifyServerCount(pool, 1);
}
};
SerializableRunnable verify2Servers = new CacheSerializableRunnable("verify2Servers") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
PoolImpl pool = getPool(region);
verifyServerCount(pool, 2);
}
};
vm2.invoke(verify2Servers);
SerializableRunnable stopCacheServer = new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
};
final String expected = "java.io.IOException";
final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
vm2.invoke(new SerializableRunnable() {
public void run() {
LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
bgexecLogger.info(addExpected);
}
});
try {
// make sure we removeExpected
// Bounce the non-current server (I know that VM1 contains the non-current server
// because ...
vm1.invoke(stopCacheServer);
vm2.invoke(verify1Server);
final int restartPort = port1;
vm1.invoke(new SerializableRunnable("Restart CacheServer") {
public void run() {
try {
Region region = getRootRegion().getSubregion(name);
assertNotNull(region);
startBridgeServer(restartPort);
} catch (Exception e) {
getSystem().getLogWriter().fine(new Exception(e));
org.apache.geode.test.dunit.Assert.fail("Failed to start CacheServer", e);
}
}
});
// Pause long enough for the monitor to realize the server has been bounced
// and reconnect to it.
vm2.invoke(verify2Servers);
} finally {
vm2.invoke(new SerializableRunnable() {
public void run() {
LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
bgexecLogger.info(removeExpected);
}
});
}
// Stop the other cache server
vm0.invoke(stopCacheServer);
// Run awhile
vm2.invoke(verify1Server);
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info(// FIXME
"FIXME: this thread does not terminate");
// // Verify that no exception has occurred in the putter thread
// join(putAI, 5 * 60 * 1000, getLogWriter());
// //assertTrue("Exception occurred while invoking " + putAI, !putAI.exceptionOccurred());
// if (putAI.exceptionOccurred()) {
// fail("While putting entries: ", putAI.getException());
// }
// Close Pool
vm2.invoke(new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.localDestroyRegion();
}
});
// Stop the last cache server
vm1.invoke(stopCacheServer);
}
Aggregations