use of org.apache.geode.distributed.internal.DistributionException 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.distributed.internal.DistributionException in project geode by apache.
the class GMSMembershipManager method join.
/**
* Joins the distributed system
*
* @throws GemFireConfigException - configuration error
* @throws SystemConnectException - problem joining
*/
private void join() {
services.setShutdownCause(null);
services.getCancelCriterion().cancel(null);
latestViewWriteLock.lock();
try {
try {
// added for bug #44373
this.isJoining = true;
// connect
long start = System.currentTimeMillis();
boolean ok = services.getJoinLeave().join();
if (!ok) {
throw new GemFireConfigException("Unable to join the distributed system. " + "Operation either timed out, was stopped or Locator does not exist.");
}
long delta = System.currentTimeMillis() - start;
logger.info(LogMarker.DISTRIBUTION, LocalizedMessage.create(LocalizedStrings.GroupMembershipService_JOINED_TOOK__0__MS, delta));
NetView initialView = services.getJoinLeave().getView();
latestView = new NetView(initialView, initialView.getViewId());
listener.viewInstalled(latestView);
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
if (ex.getCause() != null && ex.getCause().getCause() instanceof SystemConnectException) {
throw (SystemConnectException) (ex.getCause().getCause());
}
throw new DistributionException(LocalizedStrings.GroupMembershipService_AN_EXCEPTION_WAS_THROWN_WHILE_JOINING.toLocalizedString(), ex);
} finally {
this.isJoining = false;
}
} finally {
latestViewWriteLock.unlock();
}
}
use of org.apache.geode.distributed.internal.DistributionException in project geode by apache.
the class GMSMemberFactory method newMembershipManager.
public MembershipManager newMembershipManager(DistributedMembershipListener listener, DistributionConfig config, RemoteTransportConfig transport, DMStats stats) throws DistributionException {
Services services = new Services(listener, config, transport, stats);
try {
services.init();
services.start();
} catch (ConnectionException e) {
throw new DistributionException(LocalizedStrings.MemberFactory_UNABLE_TO_CREATE_MEMBERSHIP_MANAGER.toLocalizedString(), e);
} catch (GemFireConfigException | SystemConnectException | GemFireSecurityException e) {
throw e;
} catch (RuntimeException e) {
Services.getLogger().error("Unexpected problem starting up membership services", e);
throw new SystemConnectException("Problem starting up membership services", e);
}
return (MembershipManager) services.getManager();
}
Aggregations