From 6ddfa2eeeb3499dcca81d79c0489283c6ddc2e27 Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Tue, 20 Feb 2024 16:39:15 -0300 Subject: [PATCH] Introduce ConsistencyType and change consistencySerial to lock config --- .../DefaultNativeConnectionProvider.java | 8 ---- .../application/ECChronosInternals.java | 1 + .../ecchronos/application/config/Config.java | 25 ++++++------ application/src/main/resources/ecc.yml | 21 +++++----- .../application/config/TestConfig.java | 13 ++----- application/src/test/resources/all_set.yml | 2 +- .../impl/LocalNativeConnectionProvider.java | 23 +---------- .../OSGiLocalNativeConnectionProvider.java | 13 +------ .../connection/NativeConnectionProvider.java | 2 - .../ecchronos/core/CASLockFactory.java | 18 +++++++-- .../ecchronos/core/utils/ConsistencyType.java | 22 +++++++++++ .../ecchronos/core/AbstractCassandraTest.java | 5 --- .../ecchronos/core/TestCASLockFactory.java | 38 +++++++++++-------- ...estDefaultRepairConfigurationProvider.java | 5 --- pmd-rules.xml | 2 - 15 files changed, 92 insertions(+), 106 deletions(-) create mode 100644 core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java index 63c781279..89c17d534 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/DefaultNativeConnectionProvider.java @@ -51,7 +51,6 @@ public DefaultNativeConnectionProvider(final Config config, String host = nativeConfig.getHost(); int port = nativeConfig.getPort(); boolean remoteRouting = nativeConfig.getRemoteRouting(); - String consistencySerial = nativeConfig.getConsistencySerial(); Security.CqlSecurity cqlSecurity = cqlSecuritySupplier.get(); boolean authEnabled = cqlSecurity.getCredentials().isEnabled(); boolean tlsEnabled = cqlSecurity.getTls().isEnabled(); @@ -73,7 +72,6 @@ public DefaultNativeConnectionProvider(final Config config, .withLocalhost(host) .withPort(port) .withRemoteRouting(remoteRouting) - .withConsistencySerial(consistencySerial) .withAuthProvider(authProvider) .withSslEngineFactory(sslEngineFactory) .withMetricsEnabled(config.getStatistics().isEnabled()) @@ -146,12 +144,6 @@ public final boolean getRemoteRouting() return myLocalNativeConnectionProvider.getRemoteRouting(); } - @Override - public final String getSerialConsistency() - { - return myLocalNativeConnectionProvider.getSerialConsistency(); - } - @Override public final void close() { diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java index 18c88cf93..0c49cb246 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/ECChronosInternals.java @@ -82,6 +82,7 @@ public ECChronosInternals(final Config configuration, .withHostStates(myHostStatesImpl) .withStatementDecorator(statementDecorator) .withKeyspaceName(configuration.getLockFactory().getCas().getKeyspace()) + .withConsistencySerial(configuration.getLockFactory().getCas().getConsistencySerial()) .build(); Node node = nativeConnectionProvider.getLocalNode(); diff --git a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/Config.java b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/Config.java index fda0a0b2d..59c057c9d 100644 --- a/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/Config.java +++ b/application/src/main/java/com/ericsson/bss/cassandra/ecchronos/application/config/Config.java @@ -42,6 +42,7 @@ import com.ericsson.bss.cassandra.ecchronos.connection.NativeConnectionProvider; import com.ericsson.bss.cassandra.ecchronos.connection.StatementDecorator; import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairLockType; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; @SuppressWarnings({"checkstyle:methodname", "checkstyle:membername"}) public class Config @@ -325,7 +326,6 @@ public static class NativeConnection extends Connection decoratorClass = NoopStatementDecorator.class; private boolean remoteRouting = true; - private String consistencySerial = "DEFAULT"; public NativeConnection() { @@ -364,16 +364,6 @@ public final void setRemoteRouting(final boolean aRemoteRouting) this.remoteRouting = aRemoteRouting; } - public final String getConsistencySerial() - { - return consistencySerial; - } - - public final void setConsistencySerial(final String aConsistencySerial) - { - this.consistencySerial = aConsistencySerial; - } - @Override protected final Class[] expectedConstructor() { @@ -747,6 +737,7 @@ public final void setCas(final CasLockFactoryConfig aCas) public static class CasLockFactoryConfig { private String keyspace = "ecchronos"; + private ConsistencyType consistencySerial = ConsistencyType.DEFAULT; public final String getKeyspace() { @@ -757,7 +748,17 @@ public final void setKeyspace(final String aKeyspace) { this.keyspace = aKeyspace; } - } + + public final ConsistencyType getConsistencySerial() + { + return consistencySerial; + } + + public final void setConsistencySerial(final String aConsistencySerial) + { + consistencySerial = ConsistencyType.valueOf(aConsistencySerial.toUpperCase(Locale.US)); + } + } public static class RunPolicyConfig { diff --git a/application/src/main/resources/ecc.yml b/application/src/main/resources/ecc.yml index 0a6445068..0e9a9b02b 100644 --- a/application/src/main/resources/ecc.yml +++ b/application/src/main/resources/ecc.yml @@ -57,16 +57,6 @@ connection: ## instead SERIAL consistency will be used for those request. ## remoteRouting: true - # # Allow to override consistency level for LWT (lightweight transactions). Possible values are: - # # "DEFAULT" - Use consistency level based on remoteRouting. - # # "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. - # # "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. - ## - # # if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally - # # in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the - # # same nodes causing multiple repairs on the same range/node at the same time. - ## - consistencySerial: "DEFAULT" jmx: ## ## Host and port properties for JMX. @@ -231,6 +221,17 @@ lock_factory: ## The keyspace used for the CAS lock factory tables. ## keyspace: ecchronos + ## + ## Allow to override consistency level for LWT (lightweight transactions). Possible values are: + ## "DEFAULT" - Use consistency level based on remoteRouting. + ## "SERIAL" - Use SERIAL consistency for LWT regardless of remoteRouting. + ## "LOCAL_SERIAL" - Use LOCAL_SERIAL consistency for LWT regardless of remoteRouting. + ## + ## if you use remoteRouting: false and LOCAL_SERIAL then all locks will be taken locally + ## in DC. I.e There's a risk that multiple nodes in different datacenters will be able to lock the + ## same nodes causing multiple repairs on the same range/node at the same time. + ## + consistencySerial: "DEFAULT" run_policy: time_based: diff --git a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java index b226fa326..933ac5f99 100644 --- a/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java +++ b/application/src/test/java/com/ericsson/bss/cassandra/ecchronos/application/config/TestConfig.java @@ -32,6 +32,7 @@ import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairConfiguration; import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairLockType; import com.ericsson.bss.cassandra.ecchronos.core.repair.RepairOptions; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; import com.ericsson.bss.cassandra.ecchronos.core.utils.TableReference; import com.ericsson.bss.cassandra.ecchronos.core.utils.UnitConverter; import com.ericsson.bss.cassandra.ecchronos.fm.RepairFaultReporter; @@ -71,7 +72,6 @@ public void testAllValues() throws Exception assertThat(nativeConnection.getHost()).isEqualTo("127.0.0.2"); assertThat(nativeConnection.getPort()).isEqualTo(9100); assertThat(nativeConnection.getRemoteRouting()).isFalse(); - assertThat(nativeConnection.getConsistencySerial().equals("LOCAL")).isTrue(); assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.SECONDS)).isEqualTo(5); assertThat(nativeConnection.getProviderClass()).isEqualTo(TestNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(TestCertificateHandler.class); @@ -136,6 +136,7 @@ public void testAllValues() throws Exception Config.LockFactoryConfig lockFactoryConfig = config.getLockFactory(); assertThat(lockFactoryConfig.getCas().getKeyspace()).isEqualTo("ecc"); + assertThat(lockFactoryConfig.getCas().getConsistencySerial().equals(ConsistencyType.LOCAL)).isTrue(); Config.RunPolicyConfig runPolicyConfig = config.getRunPolicy(); assertThat(runPolicyConfig.getTimeBased().getKeyspace()).isEqualTo("ecc"); @@ -164,7 +165,6 @@ public void testWithDefaultFile() throws Exception assertThat(nativeConnection.getHost()).isEqualTo("localhost"); assertThat(nativeConnection.getPort()).isEqualTo(9042); assertThat(nativeConnection.getRemoteRouting()).isTrue(); - assertThat(nativeConnection.getConsistencySerial().equals("DEFAULT")).isTrue(); assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.MILLISECONDS)).isEqualTo(0); assertThat(nativeConnection.getProviderClass()).isEqualTo(DefaultNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(ReloadingCertificateHandler.class); @@ -220,6 +220,7 @@ public void testWithDefaultFile() throws Exception Config.LockFactoryConfig lockFactoryConfig = config.getLockFactory(); assertThat(lockFactoryConfig.getCas().getKeyspace()).isEqualTo("ecchronos"); + assertThat(lockFactoryConfig.getCas().getConsistencySerial().equals(ConsistencyType.DEFAULT)).isTrue(); Config.RunPolicyConfig runPolicyConfig = config.getRunPolicy(); assertThat(runPolicyConfig.getTimeBased().getKeyspace()).isEqualTo("ecchronos"); @@ -248,7 +249,6 @@ public void testDefault() throws Exception assertThat(nativeConnection.getHost()).isEqualTo("localhost"); assertThat(nativeConnection.getPort()).isEqualTo(9042); assertThat(nativeConnection.getRemoteRouting()).isTrue(); - assertThat(nativeConnection.getConsistencySerial().equals("DEFAULT")).isTrue(); assertThat(nativeConnection.getTimeout().getConnectionTimeout(TimeUnit.MILLISECONDS)).isEqualTo(0); assertThat(nativeConnection.getProviderClass()).isEqualTo(DefaultNativeConnectionProvider.class); assertThat(nativeConnection.getCertificateHandlerClass()).isEqualTo(ReloadingCertificateHandler.class); @@ -303,6 +303,7 @@ public void testDefault() throws Exception Config.LockFactoryConfig lockFactoryConfig = config.getLockFactory(); assertThat(lockFactoryConfig.getCas().getKeyspace()).isEqualTo("ecchronos"); + assertThat(lockFactoryConfig.getCas().getConsistencySerial().equals(ConsistencyType.DEFAULT)).isTrue(); Config.RunPolicyConfig runPolicyConfig = config.getRunPolicy(); assertThat(runPolicyConfig.getTimeBased().getKeyspace()).isEqualTo("ecchronos"); @@ -357,12 +358,6 @@ public boolean getRemoteRouting() { throw new UnsupportedOperationException(); } - - @Override - public String getSerialConsistency() - { - throw new UnsupportedOperationException(); - } } public static class TestCertificateHandler implements CertificateHandler diff --git a/application/src/test/resources/all_set.yml b/application/src/test/resources/all_set.yml index efc3bf613..3eaf551bb 100644 --- a/application/src/test/resources/all_set.yml +++ b/application/src/test/resources/all_set.yml @@ -24,7 +24,6 @@ connection: certificateHandler: com.ericsson.bss.cassandra.ecchronos.application.config.TestConfig$TestCertificateHandler decoratorClass: com.ericsson.bss.cassandra.ecchronos.application.config.TestConfig$TestStatementDecorator remoteRouting: false - consistencySerial: "LOCAL" jmx: host: 127.0.0.3 port: 7100 @@ -77,6 +76,7 @@ statistics: lock_factory: cas: keyspace: ecc + consistencySerial: "LOCAL" run_policy: time_based: diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java index d5a725f08..e8fc24af6 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/LocalNativeConnectionProvider.java @@ -71,18 +71,12 @@ public final class LocalNativeConnectionProvider implements NativeConnectionProv private final CqlSession mySession; private final Node myLocalNode; private final boolean myRemoteRouting; - private final String mySerialConsistencyLevel; - private LocalNativeConnectionProvider( - final CqlSession session, - final Node node, - final boolean remoteRouting, - final String serialConsistencyLevel) + private LocalNativeConnectionProvider(final CqlSession session, final Node node, final boolean remoteRouting) { mySession = session; myLocalNode = node; myRemoteRouting = remoteRouting; - mySerialConsistencyLevel = serialConsistencyLevel; } @Override @@ -103,12 +97,6 @@ public boolean getRemoteRouting() return myRemoteRouting; } - @Override - public String getSerialConsistency() - { - return mySerialConsistencyLevel; - } - @Override public void close() { @@ -127,7 +115,6 @@ public static class Builder private String myLocalhost = DEFAULT_LOCAL_HOST; private int myPort = DEFAULT_NATIVE_PORT; private boolean myRemoteRouting = true; - private String mySerialConsistency = "DEFAULT"; private boolean myIsMetricsEnabled = true; private AuthProvider myAuthProvider = null; private SslEngineFactory mySslEngineFactory = null; @@ -152,12 +139,6 @@ public final Builder withRemoteRouting(final boolean remoteRouting) return this; } - public final Builder withConsistencySerial(final String serialConsistency) - { - mySerialConsistency = serialConsistency; - return this; - } - public final Builder withAuthProvider(final AuthProvider authProvider) { this.myAuthProvider = authProvider; @@ -192,7 +173,7 @@ public final LocalNativeConnectionProvider build() { CqlSession session = createSession(this); Node node = resolveLocalhost(session, localEndPoint()); - return new LocalNativeConnectionProvider(session, node, myRemoteRouting, mySerialConsistency); + return new LocalNativeConnectionProvider(session, node, myRemoteRouting); } private EndPoint localEndPoint() diff --git a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java index 0bc7ea534..e941fc3ad 100644 --- a/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java +++ b/connection.impl/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/impl/OSGiLocalNativeConnectionProvider.java @@ -50,13 +50,11 @@ public final synchronized void activate(final Configuration configuration) String localhost = configuration.localHost(); int port = configuration.nativePort(); boolean remoteRouting = configuration.remoteRouting(); - String serialConsistency = configuration.serialConsistency(); LocalNativeConnectionProvider.Builder builder = LocalNativeConnectionProvider.builder() .withLocalhost(localhost) .withPort(port) - .withRemoteRouting(remoteRouting) - .withConsistencySerial(serialConsistency); + .withRemoteRouting(remoteRouting); if (!configuration.credentialsFile().isEmpty()) { @@ -102,12 +100,6 @@ public final boolean getRemoteRouting() return myDelegateNativeConnectionProvider.getRemoteRouting(); } - @Override - public final String getSerialConsistency() - { - return myDelegateNativeConnectionProvider.getSerialConsistency(); - } - @ObjectClassDefinition public @interface Configuration { @@ -125,8 +117,5 @@ public final String getSerialConsistency() @AttributeDefinition(name = "Remote routing", description = "Enables remote routing between datacenters") boolean remoteRouting() default true; - - @AttributeDefinition(name = "Serial consistency", description = "Define serial consistency level used") - String serialConsistency() default "DEFAULT"; } } diff --git a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java index e5b97d367..10ae256be 100644 --- a/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java +++ b/connection/src/main/java/com/ericsson/bss/cassandra/ecchronos/connection/NativeConnectionProvider.java @@ -31,8 +31,6 @@ public interface NativeConnectionProvider extends Closeable boolean getRemoteRouting(); - String getSerialConsistency(); - @Override default void close() throws IOException { diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java index 4bb5f58c0..5dd2c216b 100644 --- a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/CASLockFactory.java @@ -32,6 +32,7 @@ import com.ericsson.bss.cassandra.ecchronos.connection.StatementDecorator; import com.ericsson.bss.cassandra.ecchronos.core.exceptions.LockException; import com.ericsson.bss.cassandra.ecchronos.core.scheduling.LockFactory; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; import com.google.common.annotations.VisibleForTesting; import com.google.common.util.concurrent.ThreadFactoryBuilder; import org.slf4j.Logger; @@ -80,6 +81,7 @@ * WITH default_time_to_live = 600 AND gc_grace_seconds = 0; * */ +@SuppressWarnings({"PMD.GodClass", "PMD.TooManyFields", "PMD.SingularField", "PMD.ExcessiveMethodLength"}) public final class CASLockFactory implements LockFactory, Closeable { private static final Logger LOG = LoggerFactory.getLogger(CASLockFactory.class); @@ -104,7 +106,7 @@ public final class CASLockFactory implements LockFactory, Closeable private final StatementDecorator myStatementDecorator; private final HostStates myHostStates; private final boolean myRemoteRouting; - private final String mySerialConsistency; + private final ConsistencyType mySerialConsistency; private final CqlSession mySession; private final String myKeyspaceName; @@ -130,11 +132,11 @@ private CASLockFactory(final Builder builder) mySession = builder.myNativeConnectionProvider.getSession(); myRemoteRouting = builder.myNativeConnectionProvider.getRemoteRouting(); - mySerialConsistency = builder.myNativeConnectionProvider.getSerialConsistency(); + mySerialConsistency = builder.myConsistencyType; verifySchemasExists(); - if ("DEFAULT".equals(mySerialConsistency)) + if (ConsistencyType.DEFAULT.equals(mySerialConsistency)) { serialConsistencyLevel = myRemoteRouting ? ConsistencyLevel.LOCAL_SERIAL @@ -142,10 +144,11 @@ private CASLockFactory(final Builder builder) } else { - serialConsistencyLevel = "LOCAL".equals(mySerialConsistency) + serialConsistencyLevel = ConsistencyType.LOCAL.equals(mySerialConsistency) ? ConsistencyLevel.LOCAL_SERIAL : ConsistencyLevel.SERIAL; } + SimpleStatement insertLockStatement = QueryBuilder.insertInto(myKeyspaceName, TABLE_LOCK) .value(COLUMN_RESOURCE, bindMarker()) .value(COLUMN_NODE, bindMarker()) @@ -317,6 +320,7 @@ public static class Builder private HostStates myHostStates; private StatementDecorator myStatementDecorator; private String myKeyspaceName = DEFAULT_KEYSPACE_NAME; + private ConsistencyType myConsistencyType; public final Builder withNativeConnectionProvider(final NativeConnectionProvider nativeConnectionProvider) { @@ -342,6 +346,12 @@ public final Builder withKeyspaceName(final String keyspaceName) return this; } + public final Builder withConsistencySerial(final ConsistencyType consistencyType) + { + myConsistencyType = consistencyType; + return this; + } + public final CASLockFactory build() { if (myNativeConnectionProvider == null) diff --git a/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java new file mode 100644 index 000000000..341f484e6 --- /dev/null +++ b/core/src/main/java/com/ericsson/bss/cassandra/ecchronos/core/utils/ConsistencyType.java @@ -0,0 +1,22 @@ +/* + * Copyright 2024 Telefonaktiebolaget LM Ericsson + * + * Licensed 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 com.ericsson.bss.cassandra.ecchronos.core.utils; + +public enum ConsistencyType +{ + DEFAULT, + LOCAL, + SERIAL +} diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java index ac7eb3cb3..101eea929 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/AbstractCassandraTest.java @@ -77,11 +77,6 @@ public boolean getRemoteRouting() { return true; } - - @Override - public String getSerialConsistency(){ - return "DEFAULT"; - } }; } diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java index 640d65e15..e8464b871 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/TestCASLockFactory.java @@ -62,6 +62,7 @@ import com.ericsson.bss.cassandra.ecchronos.core.exceptions.LockException; import com.ericsson.bss.cassandra.ecchronos.core.scheduling.LockFactory.DistributedLock; +import com.ericsson.bss.cassandra.ecchronos.core.utils.ConsistencyType; import net.jcip.annotations.NotThreadSafe; import org.junit.runner.RunWith; @@ -362,11 +363,6 @@ public boolean getRemoteRouting() { return true; } - - @Override - public String getSerialConsistency(){ - return "DEFAULT"; - } }) .withHostStates(hostStates) .withStatementDecorator(s -> s) @@ -375,13 +371,25 @@ public String getSerialConsistency(){ } @Test - public void testRemoteRoutingTrueWithDefaultSerialConsistency() { + public void testRemoteRoutingTrueWithDefaultSerialConsistency() + { + + Node nodeMock = mock(Node.class); + + NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); + + when(connectionProviderMock.getSession()).thenReturn(mySession); + + when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); + + when(connectionProviderMock.getRemoteRouting()).thenReturn(true); myLockFactory = new CASLockFactory.Builder() .withNativeConnectionProvider(getNativeConnectionProvider()) .withHostStates(hostStates) .withStatementDecorator(s -> s) .withKeyspaceName(myKeyspaceName) + .withConsistencySerial(ConsistencyType.DEFAULT) .build(); @@ -389,7 +397,8 @@ public void testRemoteRoutingTrueWithDefaultSerialConsistency() { } @Test - public void testRemoteRoutingFalseWithDefaultSerialConsistency() { + public void testRemoteRoutingFalseWithDefaultSerialConsistency() + { Node nodeMock = mock(Node.class); @@ -401,27 +410,25 @@ public void testRemoteRoutingFalseWithDefaultSerialConsistency() { when(connectionProviderMock.getRemoteRouting()).thenReturn(false); - when(connectionProviderMock.getSerialConsistency()).thenReturn("DEFAULT"); - myLockFactory = new CASLockFactory.Builder() .withNativeConnectionProvider(connectionProviderMock) .withHostStates(hostStates) .withStatementDecorator(s -> s) .withKeyspaceName(myKeyspaceName) + .withConsistencySerial(ConsistencyType.DEFAULT) .build(); assertEquals(ConsistencyLevel.SERIAL, myLockFactory.getSerialConsistencyLevel()); } @Test - public void testLocalSerialConsistency(){ + public void testLocalSerialConsistency() + { NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); Node nodeMock = mock(Node.class); - when(connectionProviderMock.getSerialConsistency()).thenReturn("LOCAL"); - when(connectionProviderMock.getSession()).thenReturn(mySession); when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); @@ -431,6 +438,7 @@ public void testLocalSerialConsistency(){ .withHostStates(hostStates) .withStatementDecorator(s -> s) .withKeyspaceName(myKeyspaceName) + .withConsistencySerial(ConsistencyType.LOCAL) .build(); assertEquals(ConsistencyLevel.LOCAL_SERIAL, myLockFactory.getSerialConsistencyLevel()); @@ -438,13 +446,12 @@ public void testLocalSerialConsistency(){ } @Test - public void testSerialConsistency(){ + public void testSerialConsistency() + { NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); Node nodeMock = mock(Node.class); - when(connectionProviderMock.getSerialConsistency()).thenReturn("SERIAL"); - when(connectionProviderMock.getSession()).thenReturn(mySession); when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); @@ -454,6 +461,7 @@ public void testSerialConsistency(){ .withHostStates(hostStates) .withStatementDecorator(s -> s) .withKeyspaceName(myKeyspaceName) + .withConsistencySerial(ConsistencyType.SERIAL) .build(); assertEquals(ConsistencyLevel.SERIAL, myLockFactory.getSerialConsistencyLevel()); diff --git a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java index cf793993a..649344414 100644 --- a/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java +++ b/core/src/test/java/com/ericsson/bss/cassandra/ecchronos/core/repair/TestDefaultRepairConfigurationProvider.java @@ -99,11 +99,6 @@ public boolean getRemoteRouting() { return true; } - - @Override - public String getSerialConsistency(){ - return "DEFAULT"; - } }; when(session.getMetadata()).thenReturn(metadata); diff --git a/pmd-rules.xml b/pmd-rules.xml index 3b8057faa..6c7eef5d9 100644 --- a/pmd-rules.xml +++ b/pmd-rules.xml @@ -30,8 +30,6 @@ - -