Skip to content

Commit

Permalink
Remove unnecessary variables and lines
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorCavichioli committed Feb 21, 2024
1 parent 6ddfa2e commit 9a94664
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
{
Expand All @@ -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;
}
Expand All @@ -156,27 +153,27 @@ 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())
.setColumn(COLUMN_METADATA, bindMarker())
.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())
Expand Down Expand Up @@ -304,7 +301,7 @@ UUID getHostId()
@VisibleForTesting
ConsistencyLevel getSerialConsistencyLevel()
{
return serialConsistencyLevel;
return mySerialConsistencyLevel;
}

public static Builder builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 9a94664

Please sign in to comment.