From 9a94664d2b4bc6fec3e1c9977ff5675102d1ab21 Mon Sep 17 00:00:00 2001 From: VictorCavichioli Date: Wed, 21 Feb 2024 09:14:29 -0300 Subject: [PATCH] Remove unnecessary variables and lines --- .../ecchronos/core/CASLockFactory.java | 21 ++++++++----------- .../ecchronos/core/TestCASLockFactory.java | 15 ------------- 2 files changed, 9 insertions(+), 27 deletions(-) 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 5dd2c216b..4babbd23e 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 @@ -106,8 +106,6 @@ public final class CASLockFactory implements LockFactory, Closeable private final StatementDecorator myStatementDecorator; private final HostStates myHostStates; private final boolean myRemoteRouting; - private final ConsistencyType mySerialConsistency; - private final CqlSession mySession; private final String myKeyspaceName; private final PreparedStatement myCompeteStatement; @@ -119,7 +117,7 @@ public final class CASLockFactory implements LockFactory, Closeable private final PreparedStatement myRemoveLockPriorityStatement; private final LockCache myLockCache; - private final ConsistencyLevel serialConsistencyLevel; + private final ConsistencyLevel mySerialConsistencyLevel; private CASLockFactory(final Builder builder) { @@ -132,19 +130,18 @@ private CASLockFactory(final Builder builder) mySession = builder.myNativeConnectionProvider.getSession(); myRemoteRouting = builder.myNativeConnectionProvider.getRemoteRouting(); - mySerialConsistency = builder.myConsistencyType; verifySchemasExists(); - if (ConsistencyType.DEFAULT.equals(mySerialConsistency)) + if (ConsistencyType.DEFAULT.equals(builder.myConsistencyType)) { - serialConsistencyLevel = myRemoteRouting + mySerialConsistencyLevel = myRemoteRouting ? ConsistencyLevel.LOCAL_SERIAL : ConsistencyLevel.SERIAL; } else { - serialConsistencyLevel = ConsistencyType.LOCAL.equals(mySerialConsistency) + mySerialConsistencyLevel = ConsistencyType.LOCAL.equals(builder.myConsistencyType) ? ConsistencyLevel.LOCAL_SERIAL : ConsistencyLevel.SERIAL; } @@ -156,19 +153,19 @@ private CASLockFactory(final Builder builder) .ifNotExists() .build() .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM) - .setSerialConsistencyLevel(serialConsistencyLevel); + .setSerialConsistencyLevel(mySerialConsistencyLevel); SimpleStatement getLockMetadataStatement = QueryBuilder.selectFrom(myKeyspaceName, TABLE_LOCK) .column(COLUMN_METADATA) .whereColumn(COLUMN_RESOURCE).isEqualTo(bindMarker()) .build() - .setSerialConsistencyLevel(serialConsistencyLevel); + .setSerialConsistencyLevel(mySerialConsistencyLevel); SimpleStatement removeLockStatement = QueryBuilder.deleteFrom(myKeyspaceName, TABLE_LOCK) .whereColumn(COLUMN_RESOURCE).isEqualTo(bindMarker()) .ifColumn(COLUMN_NODE).isEqualTo(bindMarker()) .build() - .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM).setSerialConsistencyLevel(serialConsistencyLevel); + .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM).setSerialConsistencyLevel(mySerialConsistencyLevel); SimpleStatement updateLockStatement = QueryBuilder.update(myKeyspaceName, TABLE_LOCK) .setColumn(COLUMN_NODE, bindMarker()) @@ -176,7 +173,7 @@ private CASLockFactory(final Builder builder) .whereColumn(COLUMN_RESOURCE).isEqualTo(bindMarker()) .ifColumn(COLUMN_NODE).isEqualTo(bindMarker()) .build() - .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM).setSerialConsistencyLevel(serialConsistencyLevel); + .setConsistencyLevel(ConsistencyLevel.LOCAL_QUORUM).setSerialConsistencyLevel(mySerialConsistencyLevel); SimpleStatement competeStatement = QueryBuilder.insertInto(myKeyspaceName, TABLE_LOCK_PRIORITY) .value(COLUMN_RESOURCE, bindMarker()) @@ -304,7 +301,7 @@ UUID getHostId() @VisibleForTesting ConsistencyLevel getSerialConsistencyLevel() { - return serialConsistencyLevel; + return mySerialConsistencyLevel; } public static Builder builder() 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 e8464b871..af481f8e0 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 @@ -373,15 +373,11 @@ public boolean getRemoteRouting() @Test 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() @@ -392,22 +388,17 @@ public void testRemoteRoutingTrueWithDefaultSerialConsistency() .withConsistencySerial(ConsistencyType.DEFAULT) .build(); - assertEquals(ConsistencyLevel.LOCAL_SERIAL, myLockFactory.getSerialConsistencyLevel()); } @Test public void testRemoteRoutingFalseWithDefaultSerialConsistency() { - Node nodeMock = mock(Node.class); - NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); when(connectionProviderMock.getSession()).thenReturn(mySession); - when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); - when(connectionProviderMock.getRemoteRouting()).thenReturn(false); myLockFactory = new CASLockFactory.Builder() @@ -424,13 +415,10 @@ public void testRemoteRoutingFalseWithDefaultSerialConsistency() @Test public void testLocalSerialConsistency() { - NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); - Node nodeMock = mock(Node.class); when(connectionProviderMock.getSession()).thenReturn(mySession); - when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); myLockFactory = new CASLockFactory.Builder() @@ -442,18 +430,15 @@ public void testLocalSerialConsistency() .build(); assertEquals(ConsistencyLevel.LOCAL_SERIAL, myLockFactory.getSerialConsistencyLevel()); - } @Test public void testSerialConsistency() { NativeConnectionProvider connectionProviderMock = mock(NativeConnectionProvider.class); - Node nodeMock = mock(Node.class); when(connectionProviderMock.getSession()).thenReturn(mySession); - when(connectionProviderMock.getLocalNode()).thenReturn(nodeMock); myLockFactory = new CASLockFactory.Builder()