You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@curator.apache.org by Randgalt <gi...@git.apache.org> on 2018/02/20 18:37:31 UTC

[GitHub] curator pull request #252: [CURATOR-455] Curator's EnsembleProvider.getConne...

GitHub user Randgalt opened a pull request:

    https://github.com/apache/curator/pull/252

    [CURATOR-455] Curator's EnsembleProvider.getConnectionString() is not re-called once the session expiration has been injected

    When the connection is lost client.getZookeeperClient().getZooKeeper() needs to be called periodically so that the ensemble provider may update the connection string, etc.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/apache/curator CURATOR-455

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/curator/pull/252.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #252
    
----
commit 770a0f948e211ed6f794e318cf7722dff1fa1c0a
Author: randgalt <ra...@...>
Date:   2018-02-07T23:53:32Z

    [maven-release-plugin] prepare release apache-curator-4.0.1

commit 6978b09d800ad5d367a88f5ae7cf8ed099a9ca7c
Author: randgalt <ra...@...>
Date:   2018-02-07T23:53:43Z

    [maven-release-plugin] prepare for next development iteration

commit f57206d6bd1744a71f7416438e010775f2e50adb
Author: randgalt <ra...@...>
Date:   2018-02-13T18:08:57Z

    Merge branch 'master' of https://git-wip-us.apache.org/repos/asf/curator

commit 04c16b110207f10475059cff2c0363d2c1c43db3
Author: randgalt <ra...@...>
Date:   2018-02-20T18:36:22Z

    When the connection is lost client.getZookeeperClient().getZooKeeper() needs to be called periodically so that the ensemble provider may update the connection string, etc.

----


---

[GitHub] curator pull request #252: [CURATOR-455] Curator's EnsembleProvider.getConne...

Posted by Randgalt <gi...@git.apache.org>.
Github user Randgalt commented on a diff in the pull request:

    https://github.com/apache/curator/pull/252#discussion_r169854109
  
    --- Diff: curator-framework/src/test/java/org/apache/curator/framework/ensemble/TestEnsembleProvider.java ---
    @@ -0,0 +1,162 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.curator.framework.ensemble;
    +
    +import org.apache.curator.ensemble.EnsembleProvider;
    +import org.apache.curator.framework.CuratorFramework;
    +import org.apache.curator.framework.CuratorFrameworkFactory;
    +import org.apache.curator.framework.state.ConnectionState;
    +import org.apache.curator.framework.state.ConnectionStateListener;
    +import org.apache.curator.retry.RetryOneTime;
    +import org.apache.curator.test.BaseClassForTests;
    +import org.apache.curator.test.TestingServer;
    +import org.apache.curator.test.Timing;
    +import org.apache.curator.utils.CloseableUtils;
    +import org.testng.Assert;
    +import org.testng.annotations.Test;
    +import java.util.concurrent.CountDownLatch;
    +import java.util.concurrent.Semaphore;
    +import java.util.concurrent.TimeUnit;
    +
    +public class TestEnsembleProvider extends BaseClassForTests
    +{
    +    private final Timing timing = new Timing();
    +
    +    @Test
    +    public void testBasic()
    +    {
    +        Semaphore counter = new Semaphore(0);
    +        final CuratorFramework client = newClient(counter);
    +        try
    +        {
    +            client.start();
    +            Assert.assertTrue(timing.acquireSemaphore(counter));
    +        }
    +        finally
    +        {
    +            CloseableUtils.closeQuietly(client);
    +        }
    +    }
    +
    +    @Test
    +    public void testAfterSessionExpiration() throws Exception
    +    {
    +        TestingServer oldServer = server;
    +        Semaphore counter = new Semaphore(0);
    +        final CuratorFramework client = newClient(counter);
    +        try
    +        {
    +            client.start();
    +
    +            final CountDownLatch connectedLatch = new CountDownLatch(1);
    +            final CountDownLatch lostLatch = new CountDownLatch(1);
    +            final CountDownLatch reconnectedLatch = new CountDownLatch(1);
    +            ConnectionStateListener listener = new ConnectionStateListener()
    +            {
    +                @Override
    +                public void stateChanged(CuratorFramework client, ConnectionState newState)
    +                {
    +                    if ( newState == ConnectionState.CONNECTED )
    +                    {
    +                        connectedLatch.countDown();
    +                    }
    +                    if ( newState == ConnectionState.LOST )
    +                    {
    +                        lostLatch.countDown();
    +                    }
    +                    if ( newState == ConnectionState.RECONNECTED )
    +                    {
    +                        reconnectedLatch.countDown();
    +                    }
    +                }
    +            };
    +            client.getConnectionStateListenable().addListener(listener);
    --- End diff --
    
    Doh - good catch. Thanks.


---

[GitHub] curator issue #252: [CURATOR-455] Curator's EnsembleProvider.getConnectionSt...

Posted by cammckenzie <gi...@git.apache.org>.
Github user cammckenzie commented on the issue:

    https://github.com/apache/curator/pull/252
  
    Looks good to me.


---

[GitHub] curator pull request #252: [CURATOR-455] Curator's EnsembleProvider.getConne...

Posted by cammckenzie <gi...@git.apache.org>.
Github user cammckenzie commented on a diff in the pull request:

    https://github.com/apache/curator/pull/252#discussion_r169528858
  
    --- Diff: curator-framework/src/test/java/org/apache/curator/framework/ensemble/TestEnsembleProvider.java ---
    @@ -0,0 +1,162 @@
    +/**
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *   http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.curator.framework.ensemble;
    +
    +import org.apache.curator.ensemble.EnsembleProvider;
    +import org.apache.curator.framework.CuratorFramework;
    +import org.apache.curator.framework.CuratorFrameworkFactory;
    +import org.apache.curator.framework.state.ConnectionState;
    +import org.apache.curator.framework.state.ConnectionStateListener;
    +import org.apache.curator.retry.RetryOneTime;
    +import org.apache.curator.test.BaseClassForTests;
    +import org.apache.curator.test.TestingServer;
    +import org.apache.curator.test.Timing;
    +import org.apache.curator.utils.CloseableUtils;
    +import org.testng.Assert;
    +import org.testng.annotations.Test;
    +import java.util.concurrent.CountDownLatch;
    +import java.util.concurrent.Semaphore;
    +import java.util.concurrent.TimeUnit;
    +
    +public class TestEnsembleProvider extends BaseClassForTests
    +{
    +    private final Timing timing = new Timing();
    +
    +    @Test
    +    public void testBasic()
    +    {
    +        Semaphore counter = new Semaphore(0);
    +        final CuratorFramework client = newClient(counter);
    +        try
    +        {
    +            client.start();
    +            Assert.assertTrue(timing.acquireSemaphore(counter));
    +        }
    +        finally
    +        {
    +            CloseableUtils.closeQuietly(client);
    +        }
    +    }
    +
    +    @Test
    +    public void testAfterSessionExpiration() throws Exception
    +    {
    +        TestingServer oldServer = server;
    +        Semaphore counter = new Semaphore(0);
    +        final CuratorFramework client = newClient(counter);
    +        try
    +        {
    +            client.start();
    +
    +            final CountDownLatch connectedLatch = new CountDownLatch(1);
    +            final CountDownLatch lostLatch = new CountDownLatch(1);
    +            final CountDownLatch reconnectedLatch = new CountDownLatch(1);
    +            ConnectionStateListener listener = new ConnectionStateListener()
    +            {
    +                @Override
    +                public void stateChanged(CuratorFramework client, ConnectionState newState)
    +                {
    +                    if ( newState == ConnectionState.CONNECTED )
    +                    {
    +                        connectedLatch.countDown();
    +                    }
    +                    if ( newState == ConnectionState.LOST )
    +                    {
    +                        lostLatch.countDown();
    +                    }
    +                    if ( newState == ConnectionState.RECONNECTED )
    +                    {
    +                        reconnectedLatch.countDown();
    +                    }
    +                }
    +            };
    +            client.getConnectionStateListenable().addListener(listener);
    --- End diff --
    
    Is there a potential race condition here? Can't the connected event come before the listener is added as the client is started prior to the listener being added?


---

[GitHub] curator pull request #252: [CURATOR-455] Curator's EnsembleProvider.getConne...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/curator/pull/252


---