Search in sources :

Example 1 with DistributionException

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");
    }
}
Also used : LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) InternalLogWriter(org.apache.geode.internal.logging.InternalLogWriter) LogWriter(org.apache.geode.LogWriter) GemFireConfigException(org.apache.geode.GemFireConfigException) Host(org.apache.geode.test.dunit.Host) DistributionException(org.apache.geode.distributed.internal.DistributionException) Properties(java.util.Properties) LocalLogWriter(org.apache.geode.internal.logging.LocalLogWriter) DistributionException(org.apache.geode.distributed.internal.DistributionException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) 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 2 with DistributionException

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();
    }
}
Also used : GemFireConfigException(org.apache.geode.GemFireConfigException) NetView(org.apache.geode.distributed.internal.membership.NetView) DistributionException(org.apache.geode.distributed.internal.DistributionException) MemberShunnedException(org.apache.geode.internal.tcp.MemberShunnedException) TimeoutException(java.util.concurrent.TimeoutException) ShunnedMemberException(org.apache.geode.distributed.internal.direct.ShunnedMemberException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CancelException(org.apache.geode.CancelException) DistributionException(org.apache.geode.distributed.internal.DistributionException) ForcedDisconnectException(org.apache.geode.ForcedDisconnectException) SystemConnectException(org.apache.geode.SystemConnectException) GemFireConfigException(org.apache.geode.GemFireConfigException) IOException(java.io.IOException) NotSerializableException(java.io.NotSerializableException) ToDataException(org.apache.geode.ToDataException) SystemConnectException(org.apache.geode.SystemConnectException)

Example 3 with DistributionException

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();
}
Also used : MemberServices(org.apache.geode.distributed.internal.membership.MemberServices) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireConfigException(org.apache.geode.GemFireConfigException) MembershipManager(org.apache.geode.distributed.internal.membership.MembershipManager) DistributionException(org.apache.geode.distributed.internal.DistributionException) ConnectionException(org.apache.geode.internal.tcp.ConnectionException) SystemConnectException(org.apache.geode.SystemConnectException)

Aggregations

GemFireConfigException (org.apache.geode.GemFireConfigException)3 SystemConnectException (org.apache.geode.SystemConnectException)3 DistributionException (org.apache.geode.distributed.internal.DistributionException)3 IOException (java.io.IOException)2 ForcedDisconnectException (org.apache.geode.ForcedDisconnectException)2 NotSerializableException (java.io.NotSerializableException)1 Properties (java.util.Properties)1 TimeoutException (java.util.concurrent.TimeoutException)1 CancelException (org.apache.geode.CancelException)1 LogWriter (org.apache.geode.LogWriter)1 ToDataException (org.apache.geode.ToDataException)1 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)1 ShunnedMemberException (org.apache.geode.distributed.internal.direct.ShunnedMemberException)1 MemberServices (org.apache.geode.distributed.internal.membership.MemberServices)1 MembershipManager (org.apache.geode.distributed.internal.membership.MembershipManager)1 NetView (org.apache.geode.distributed.internal.membership.NetView)1 InternalLogWriter (org.apache.geode.internal.logging.InternalLogWriter)1 LocalLogWriter (org.apache.geode.internal.logging.LocalLogWriter)1 ConnectionException (org.apache.geode.internal.tcp.ConnectionException)1 MemberShunnedException (org.apache.geode.internal.tcp.MemberShunnedException)1