forked from Ericsson/ecchronos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cassandra based distributed locking mechanism # 741
- Cassandra tables called lock and lock_priority, to manage task execution and synchronization across multiple nodes.
- Loading branch information
sajid riaz
committed
Nov 5, 2024
1 parent
eea5f4d
commit 62343cb
Showing
13 changed files
with
1,120 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
...sson/bss/cassandra/ecchronos/application/config/lockfactory/TestCasLockFactoryConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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.application.config.lockfactory; | ||
|
||
import com.ericsson.bss.cassandra.ecchronos.application.config.Config; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class TestCasLockFactoryConfig | ||
{ | ||
@Test | ||
public void testCasLockFactoryConfigWithProvidedValue() throws IOException | ||
{ | ||
CasLockFactoryConfig casLockFactoryConfig = getCasLockFactoryConfig("all_set.yml"); | ||
assertThat(casLockFactoryConfig.getKeyspaceName()).isEqualTo("ecc"); | ||
assertThat(casLockFactoryConfig.getFailureCacheExpiryTimeInSeconds()).isEqualTo(100L); | ||
} | ||
|
||
@Test | ||
public void testCasLockFactoryConfigDefaultValue() throws IOException | ||
{ | ||
CasLockFactoryConfig casLockFactoryConfig = getCasLockFactoryConfig("nothing_set.yml"); | ||
assertThat(casLockFactoryConfig.getKeyspaceName()).isEqualTo("ecchronos"); | ||
assertThat(casLockFactoryConfig.getFailureCacheExpiryTimeInSeconds()).isEqualTo(30L); | ||
} | ||
|
||
private CasLockFactoryConfig getCasLockFactoryConfig(final String fileName) throws IOException | ||
{ | ||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
File file = new File(classLoader.getResource(fileName).getFile()); | ||
ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); | ||
Config config = mapper.readValue(file, Config.class); | ||
return config.getLockFactory().getCasLockFactoryConfig(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
...t/java/com/ericsson/bss/cassandra/ecchronos/core/impl/AbstractCassandraContainerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
* 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.impl; | ||
|
||
import com.ericsson.bss.cassandra.ecchronos.connection.DistributedNativeConnectionProvider; | ||
import java.net.InetSocketAddress; | ||
|
||
import java.util.List; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.testcontainers.containers.CassandraContainer; | ||
import org.testcontainers.utility.DockerImageName; | ||
|
||
import com.datastax.oss.driver.api.core.CqlSession; | ||
import com.datastax.oss.driver.api.core.metadata.Node; | ||
|
||
public class AbstractCassandraContainerTest | ||
{ | ||
protected static CqlSession mySession; | ||
|
||
private static DistributedNativeConnectionProvider myNativeConnectionProvider; | ||
private static CassandraContainer<?> node; | ||
|
||
@SuppressWarnings ("resource") | ||
@BeforeClass | ||
public static void setUpCluster() | ||
{ | ||
// This is set as an environment variable ('it.cassandra.version') in maven using the '-D' flag. | ||
String cassandraVersion = System.getProperty("it.cassandra.version"); | ||
if (cassandraVersion == null) | ||
{ | ||
// No environment version set, just use latest. | ||
cassandraVersion = "latest"; | ||
} | ||
node = new CassandraContainer<>(DockerImageName.parse("cassandra:" + cassandraVersion)) | ||
.withExposedPorts(9042, 7000, 7199) | ||
.withEnv("CASSANDRA_DC", "DC1") | ||
.withEnv("CASSANDRA_ENDPOINT_SNITCH", "GossipingPropertyFileSnitch") | ||
.withEnv("CASSANDRA_CLUSTER_NAME", "TestCluster") | ||
.withEnv("JMX_PORT", "7199"); | ||
node.start(); | ||
String containerIpAddress = node.getHost(); | ||
Integer containerPort = node.getMappedPort(9042); | ||
|
||
mySession = CqlSession.builder() | ||
.addContactPoint(new InetSocketAddress(containerIpAddress, containerPort)) | ||
.withLocalDatacenter("DC1") | ||
.build(); | ||
|
||
List<Node> nodesList = mySession.getMetadata().getNodes().values().stream().toList(); | ||
myNativeConnectionProvider = new DistributedNativeConnectionProvider() | ||
{ | ||
@Override | ||
public CqlSession getCqlSession() | ||
{ | ||
return mySession; | ||
} | ||
|
||
@Override | ||
public List<Node> getNodes() | ||
{ | ||
return nodesList; | ||
} | ||
|
||
@Override | ||
public boolean getRemoteRouting() | ||
{ | ||
return true; | ||
} | ||
}; | ||
} | ||
|
||
@AfterClass | ||
public static void tearDownCluster() | ||
{ | ||
if (mySession != null) | ||
{ | ||
mySession.close(); | ||
} | ||
node.stop(); | ||
} | ||
|
||
public static DistributedNativeConnectionProvider getNativeConnectionProvider() | ||
{ | ||
return myNativeConnectionProvider; | ||
} | ||
|
||
public static CassandraContainer<?> getContainerNode() | ||
{ | ||
return node; | ||
} | ||
} |
Oops, something went wrong.