curator-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cammckenzie <...@git.apache.org>
Subject [GitHub] curator pull request #243: [Fix] Curator-444
Date Sun, 03 Dec 2017 22:31:51 GMT
Github user cammckenzie commented on a diff in the pull request:

    https://github.com/apache/curator/pull/243#discussion_r154539158
  
    --- Diff: curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatchIsolatedZookeeper.java
---
    @@ -0,0 +1,224 @@
    +/**
    + * 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.recipes.leader;
    +
    +import static org.testng.Assert.assertEquals;
    +import static org.testng.Assert.assertNotEquals;
    +import static org.testng.Assert.assertTrue;
    +
    +import java.io.IOException;
    +import java.net.Socket;
    +import java.net.SocketException;
    +
    +import org.apache.curator.framework.recipes.leader.testing.DummyLeaderLatch;
    +import org.apache.curator.test.TestingCluster;
    +import org.apache.curator.test.TestingZooKeeperServer;
    +import org.apache.zookeeper.server.quorum.Leader;
    +import org.apache.zookeeper.server.quorum.LearnerHandler;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +import org.testng.annotations.AfterMethod;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +/** Tests issue: CURATOR-444: Zookeeper node is isolated from other zookeepers but not
from curator
    + *  temporally */
    +
    +
    +public class TestLeaderLatchIsolatedZookeeper {
    +
    +	private static final Logger logger = LoggerFactory.getLogger(TestLeaderLatchIsolatedZookeeper.class);
    +	private static final int CONNECTION_TIMEOUT_MS = 15000;
    +	private static final int SESSION_TIMEOUT_MS = 10000;
    +
    +	private TestingCluster cluster;
    +	private DummyLeaderLatch firstClient;
    +	private DummyLeaderLatch secondClient;
    +
    +	@BeforeMethod
    +	public void beforeMethod() throws Exception {
    +		cluster = new TestingCluster(3);
    +		cluster.start();
    +		firstClient  = new DummyLeaderLatch(cluster.getConnectString(), SESSION_TIMEOUT_MS,
CONNECTION_TIMEOUT_MS, "First");
    +		secondClient = new DummyLeaderLatch(cluster.getConnectString(), SESSION_TIMEOUT_MS,
CONNECTION_TIMEOUT_MS, "Second");
    +		firstClient.startAndAwaitElection();
    +		secondClient.startAndAwaitElection();
    +		logger.info("Session: " + SESSION_TIMEOUT_MS + " connection " + CONNECTION_TIMEOUT_MS
);
    +	}
    +
    +	@AfterMethod
    +	public void afterMethod() throws IOException {
    +		firstClient.stop();
    +		secondClient.stop();
    +		cluster.close();
    +		DummyLeaderLatch.resetHistory();
    +	}
    +
    +	@Test
    +	public void testThatStartsWithOnlyOneLeader() throws Exception {
    +		assertNotEquals(firstClient.isLeaderAccordingToLatch(), secondClient.isLeaderAccordingToLatch());
    +	}
    +
    +	@Test
    +	public void testThatStartCoherent() throws Exception {
    +		assertEquals(firstClient.isLeaderAccordingToLatch(),  firstClient.isLeaderAccordingToEvents());
    +		assertEquals(secondClient.isLeaderAccordingToLatch(), secondClient.isLeaderAccordingToEvents());
    +	}
    +
    +	@Test(invocationCount = 10)
    +	public void testThatResistsNetworkGlitches() throws Exception {
    --- End diff --
    
    Is it possible to make the test more reliable? Running it 10 times at 30 seconds an invocation
increases our regression run by 5 minutes, which isn't ideal.


---

Mime
View raw message