IGNITE-9573 Fix ZooKeeper SASL authentication tests. - Fixes #4755. Signed-off-by: Dmitriy Pavlov <dpav...@apache.org>
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/134a687a Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/134a687a Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/134a687a Branch: refs/heads/ignite-gg-14206 Commit: 134a687a86438bc7dd7ccd247fd832d84cbf0b0f Parents: 3a82d4a Author: Ilya Kasnacheev <ilya.kasnach...@gmail.com> Authored: Tue Sep 25 20:28:48 2018 +0300 Committer: Dmitriy Pavlov <dpav...@apache.org> Committed: Tue Sep 25 20:28:48 2018 +0300 ---------------------------------------------------------------------- .../apache/ignite/IgniteSystemProperties.java | 10 ++++++++++ .../discovery/zk/internal/ZookeeperClient.java | 21 +++++++++++++------- ...okeeperDiscoverySpiSaslAuthAbstractTest.java | 14 +++++++++++++ ...ZookeeperDiscoverySpiSaslFailedAuthTest.java | 11 ++++++---- 4 files changed, 45 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/134a687a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java index 71a633f..5932de0 100644 --- a/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java +++ b/modules/core/src/main/java/org/apache/ignite/IgniteSystemProperties.java @@ -979,6 +979,16 @@ public final class IgniteSystemProperties { public static final String IGNITE_EVICTION_PERMITS = "IGNITE_EVICTION_PERMITS"; /** + * Timeout between ZooKeeper client retries, default 2s. + */ + public static final String IGNITE_ZOOKEEPER_DISCOVERY_RETRY_TIMEOUT = "IGNITE_ZOOKEEPER_DISCOVERY_RETRY_TIMEOUT"; + + /** + * Number of attempts to reconnect to ZooKeeper. + */ + public static final String IGNITE_ZOOKEEPER_DISCOVERY_MAX_RETRY_COUNT = "IGNITE_ZOOKEEPER_DISCOVERY_MAX_RETRY_COUNT"; + + /** * Enforces singleton. */ private IgniteSystemProperties() { http://git-wip-us.apache.org/repos/asf/ignite/blob/134a687a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java ---------------------------------------------------------------------- diff --git a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java index 39417c2..a2788a1 100644 --- a/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java +++ b/modules/zookeeper/src/main/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperClient.java @@ -40,17 +40,18 @@ import org.apache.zookeeper.data.ACL; import org.apache.zookeeper.data.Stat; import org.jetbrains.annotations.Nullable; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_ZOOKEEPER_DISCOVERY_MAX_RETRY_COUNT; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_ZOOKEEPER_DISCOVERY_RETRY_TIMEOUT; + /** * Zookeeper Client. */ public class ZookeeperClient implements Watcher { /** */ - private static final long RETRY_TIMEOUT = - IgniteSystemProperties.getLong("IGNITE_ZOOKEEPER_DISCOVERY_RETRY_TIMEOUT", 2000); + private static final int DFLT_RETRY_TIMEOUT = 2000; /** */ - private static final int MAX_RETRY_COUNT = - IgniteSystemProperties.getInteger("IGNITE_ZOOKEEPER_DISCOVERY_MAX_RETRY_COUNT", 10); + private static final int DFLT_MAX_RETRY_COUNT = 10; /** */ private final AtomicInteger retryCount = new AtomicInteger(); @@ -866,13 +867,16 @@ public class ZookeeperClient implements Watcher { } if (err == null) { + long retryTimeout = IgniteSystemProperties.getLong(IGNITE_ZOOKEEPER_DISCOVERY_RETRY_TIMEOUT, + DFLT_RETRY_TIMEOUT); + U.warn(log, "ZooKeeper operation failed, will retry [err=" + e + - ", retryTimeout=" + RETRY_TIMEOUT + + ", retryTimeout=" + retryTimeout + ", connLossTimeout=" + connLossTimeout + ", path=" + ((KeeperException)e).getPath() + ", remainingWaitTime=" + remainingTime + ']'); - stateMux.wait(RETRY_TIMEOUT); + stateMux.wait(retryTimeout); if (closing) throw new ZookeeperClientFailedException("ZooKeeper client is closed."); @@ -906,7 +910,10 @@ public class ZookeeperClient implements Watcher { code == KeeperException.Code.OPERATIONTIMEOUT.intValue(); if (retryByErrorCode) { - if (MAX_RETRY_COUNT <= 0 || retryCount.incrementAndGet() < MAX_RETRY_COUNT) + int maxRetryCount = IgniteSystemProperties.getInteger(IGNITE_ZOOKEEPER_DISCOVERY_MAX_RETRY_COUNT, + DFLT_MAX_RETRY_COUNT); + + if (maxRetryCount <= 0 || retryCount.incrementAndGet() < maxRetryCount) return true; else return false; http://git-wip-us.apache.org/repos/asf/ignite/blob/134a687a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslAuthAbstractTest.java ---------------------------------------------------------------------- diff --git a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslAuthAbstractTest.java b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslAuthAbstractTest.java index ac94bf2..14d02f4 100644 --- a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslAuthAbstractTest.java +++ b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslAuthAbstractTest.java @@ -20,10 +20,12 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.file.Paths; +import javax.security.auth.login.Configuration; import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.spi.discovery.zk.ZookeeperDiscoverySpi; +import org.apache.ignite.testframework.GridTestUtils; import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; import org.apache.zookeeper.client.ZooKeeperSaslClient; import org.apache.zookeeper.server.ServerCnxnFactory; @@ -109,6 +111,8 @@ public abstract class ZookeeperDiscoverySpiSaslAuthAbstractTest extends GridComm /** */ protected void clearSaslSystemProperties() { + resetSaslStaticFields(); + System.clearProperty(AUTH_PROVIDER); System.clearProperty(SASL_CONFIG); @@ -137,12 +141,22 @@ public abstract class ZookeeperDiscoverySpiSaslAuthAbstractTest extends GridComm /** */ private void prepareSaslSystemProperties() { + resetSaslStaticFields(); + System.setProperty(SASL_CONFIG, Paths.get(tmpDir.getPath().toString(), JAAS_CONF_FILE).toString()); System.setProperty(AUTH_PROVIDER, "org.apache.zookeeper.server.auth.SASLAuthenticationProvider"); } /** */ + private void resetSaslStaticFields() { + Configuration.setConfiguration(null); + + GridTestUtils.setFieldValue(ZooKeeperSaslClient.class, "initializedLogin", false); + GridTestUtils.setFieldValue(ZooKeeperSaslClient.class, "login", null); + } + + /** */ private void writeClientConfigSection(FileWriter fwriter, String clientName, String pass) throws IOException { fwriter.write(clientName + "{\n" + " org.apache.zookeeper.server.auth.DigestLoginModule required\n" + http://git-wip-us.apache.org/repos/asf/ignite/blob/134a687a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslFailedAuthTest.java ---------------------------------------------------------------------- diff --git a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslFailedAuthTest.java b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslFailedAuthTest.java index 097b7c5..c90f6d4 100644 --- a/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslFailedAuthTest.java +++ b/modules/zookeeper/src/test/java/org/apache/ignite/spi/discovery/zk/internal/ZookeeperDiscoverySpiSaslFailedAuthTest.java @@ -19,6 +19,8 @@ package org.apache.ignite.spi.discovery.zk.internal; import org.apache.zookeeper.client.ZooKeeperSaslClient; import org.junit.Assert; +import static org.apache.ignite.IgniteSystemProperties.IGNITE_ZOOKEEPER_DISCOVERY_MAX_RETRY_COUNT; + /** * */ @@ -27,20 +29,21 @@ public class ZookeeperDiscoverySpiSaslFailedAuthTest extends ZookeeperDiscoveryS * @throws Exception If failed. */ public void testIgniteNodeWithInvalidPasswordFailsToJoin() throws Exception { - fail("https://issues.apache.org/jira/browse/IGNITE-9573"); - System.setProperty(ZooKeeperSaslClient.LOGIN_CONTEXT_NAME_KEY, "InvalidZookeeperClient"); - System.setProperty("IGNITE_ZOOKEEPER_DISCOVERY_MAX_RETRY_COUNT", Integer.toString(1)); + System.setProperty(IGNITE_ZOOKEEPER_DISCOVERY_MAX_RETRY_COUNT, "1"); try { startGrid(0); Assert.fail("Ignite node with invalid password should fail on join."); } - catch (Exception e) { + catch (Exception ignored) { //ignored } + finally { + System.clearProperty(IGNITE_ZOOKEEPER_DISCOVERY_MAX_RETRY_COUNT); + } } }