}
}
@Test
public void testMultiLock() {
MultiRowUniquenessConstraint unique = new MultiRowUniquenessConstraint(keyspace)
.withConsistencyLevel(ConsistencyLevel.CL_ONE)
.withTtl(60)
.withLockId("abc")
.withColumnPrefix("prefix_")
.withRow(UNIQUE_CF, "testMultiLock_A")
.withRow(UNIQUE_CF, "testMultiLock_B");
ColumnPrefixUniquenessConstraint<String> singleUnique
= new ColumnPrefixUniquenessConstraint<String>(keyspace, UNIQUE_CF, "testMultiLock_A")
.withConsistencyLevel(ConsistencyLevel.CL_ONE)
.withPrefix("prefix_");
try {
unique.acquire();
String uniqueColumn = singleUnique.readUniqueColumn();
Assert.assertEquals("abc", uniqueColumn);
LOG.info("UniqueColumn: " + uniqueColumn);
}
catch (Exception e) {
Assert.fail(e.getMessage());
}
MultiRowUniquenessConstraint unique2 = new MultiRowUniquenessConstraint(keyspace)
.withTtl(60)
.withConsistencyLevel(ConsistencyLevel.CL_ONE)
.withColumnPrefix("prefix_")
.withRow(UNIQUE_CF, "testMultiLock_B");
try {
unique2.acquire();
Assert.fail();
}
catch (Exception e) {
LOG.info(e.getMessage());
}
try {
Assert.assertEquals("abc", singleUnique.readUniqueColumn());
unique.release();
}
catch (Exception e) {
LOG.error(e.getMessage());
Assert.fail();
}
try {
unique2.acquire();
}
catch (Exception e) {
LOG.error(e.getMessage());
Assert.fail();
}
try {
unique2.release();
} catch (Exception e) {
LOG.error(e.getMessage());
Assert.fail();
}
}