Skip to content

Commit

Permalink
GEODE-9932: Change naming convention for Redish hash tags in tests (a…
Browse files Browse the repository at this point in the history
…pache#7244)

 - Instead of {user1} or variants thereof, use {tag1} to prevent
 confusion

Authored-by: Donal Evans <[email protected]>
  • Loading branch information
DonalEvans authored Jan 7, 2022
1 parent a4dc904 commit 87c32e4
Show file tree
Hide file tree
Showing 20 changed files with 300 additions and 300 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public class PartitionedRegionStatsUpdateTest {

private static JedisCluster jedis;

private static final String STRING_KEY = "{user1}string key";
private static final String SET_KEY = "{user1}set key";
private static final String HASH_KEY = "{user1}hash key";
private static final String STRING_KEY = "{tag1}string key";
private static final String SET_KEY = "{tag1}set key";
private static final String HASH_KEY = "{tag1}hash key";
private static final String LONG_APPEND_VALUE = String.valueOf(Integer.MAX_VALUE);
private static final String FIELD = "field";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void testDel_deletingNonexistentKey_returnsZero() {

@Test
public void testDel_deletingMultipleKeys_returnsCountOfOnlyDeletedKeys() {
String key1 = "{user1}firstKey";
String key2 = "{user1}secondKey";
String key3 = "{user1}thirdKey";
String key1 = "{tag1}firstKey";
String key2 = "{tag1}secondKey";
String key3 = "{tag1}thirdKey";

jedis.set(key1, "value1");
jedis.set(key2, "value2");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ public void shouldReturn0_givenBitMapDoesNotExist() {

@Test
public void shouldReturnTotalNumber_givenMultipleKeys() {
String key1 = "{user1}key1";
String key2 = "{user1}key2";
String key1 = "{tag1}key1";
String key2 = "{tag1}key2";

jedis.set(key1, "value1");
jedis.set(key2, "value2");

assertThat(jedis.exists(toArray(key1, "{user1}doesNotExist1", key2, "{user1}doesNotExist2")))
assertThat(jedis.exists(toArray(key1, "{tag1}doesNotExist1", key2, "{tag1}doesNotExist2")))
.isEqualTo(2L);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ public void deletingAnExistingKeyAndRecreatingTheSameKey_ShouldClearExistingExpi
@Test
public void callingSDIFFSTOREonExistingKey_ShouldClearExpirationTime() {

String key1 = "{user1}key1";
String key2 = "{user1}key2";
String key3 = "{user1}key3";
String key1 = "{tag1}key1";
String key2 = "{tag1}key2";
String key3 = "{tag1}key3";
String value1 = "value1";
String value2 = "value2";
String value3 = "value3";
Expand All @@ -200,9 +200,9 @@ public void callingSDIFFSTOREonExistingKey_ShouldClearExpirationTime() {

@Test
public void callingSINTERSTOREonExistingKey_ShouldClearExpirationTime() {
String key1 = "{user1}key1";
String key2 = "{user1}key2";
String key3 = "{user1}key3";
String key1 = "{tag1}key1";
String key2 = "{tag1}key2";
String key3 = "{tag1}key3";
String value1 = "value1";
String value2 = "value2";
String value3 = "value3";
Expand All @@ -223,9 +223,9 @@ public void callingSINTERSTOREonExistingKey_ShouldClearExpirationTime() {

@Test
public void callingSUNIONSTOREonExistingKey_ShouldClearExpirationTime() {
String key1 = "{user1}key1";
String key2 = "{user1}key2";
String key3 = "{user1}key3";
String key1 = "{tag1}key1";
String key2 = "{tag1}key2";
String key3 = "{tag1}key3";
String value1 = "value1";
String value2 = "value2";
String value3 = "value3";
Expand Down Expand Up @@ -278,8 +278,8 @@ public void usingHSETCommandToAlterAFieldValue_should_NOT_ClearExpirationTimeOnK

@Test
public void callingRENAMEonExistingKey_shouldTransferExpirationTimeToNewKeyName_GivenNewName_Not_InUse() {
String key = "{user1}key";
String newKeyName = "{user1}new key name";
String key = "{tag1}key";
String newKeyName = "{tag1}new key name";
String value = "value";
jedis.set(key, value);
jedis.expire(key, 20L);
Expand All @@ -292,8 +292,8 @@ public void callingRENAMEonExistingKey_shouldTransferExpirationTimeToNewKeyName_

@Test
public void callingRENAMEonExistingKey_shouldTransferExpirationTimeToNewKeyName_GivenNewName_is_InUse_ButNo_ExpirationSet() {
String key = "{user1}key";
String key2 = "{user1}key2";
String key = "{tag1}key";
String key2 = "{tag1}key2";
String value = "value";

jedis.set(key, value);
Expand All @@ -309,8 +309,8 @@ public void callingRENAMEonExistingKey_shouldTransferExpirationTimeToNewKeyName_

@Test
public void callingRENAMEonExistingKey_shouldTransferExpirationTimeToNewKeyName_GivenNewName_is_InUse_AndHas_ExpirationSet() {
String key = "{user1}key";
String key2 = "{user1}key2";
String key = "{tag1}key";
String key2 = "{tag1}key2";
String value = "value";

jedis.set(key, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public void should_removeSetKey_AfterExpirationPeriod() {

@Test
public void should_passivelyExpireKeys() {
jedis.sadd("{user1}key", "value");
jedis.pexpire("{user1}key", 100);
jedis.sadd("{tag1}key", "value");
jedis.pexpire("{tag1}key", 100);

GeodeAwaitility.await().until(() -> jedis.keys("{user1}key").isEmpty());
GeodeAwaitility.await().until(() -> jedis.keys("{tag1}key").isEmpty());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,53 +72,53 @@ public void errors_GivenWrongNumberOfArguments() {

@Test
public void shouldRename_givenNewKey() {
jedis.set("{user1}foo", "bar");
assertThat(jedis.rename("{user1}foo", "{user1}newfoo")).isEqualTo("OK");
assertThat(jedis.get("{user1}newfoo")).isEqualTo("bar");
jedis.set("{tag1}foo", "bar");
assertThat(jedis.rename("{tag1}foo", "{tag1}newfoo")).isEqualTo("OK");
assertThat(jedis.get("{tag1}newfoo")).isEqualTo("bar");
}

@Test
public void shouldDeleteOldKey_whenRenamed() {
jedis.set("{user1}foo", "bar");
jedis.rename("{user1}foo", "{user1}newfoo");
assertThat(jedis.get("{user1}foo")).isNull();
jedis.set("{tag1}foo", "bar");
jedis.rename("{tag1}foo", "{tag1}newfoo");
assertThat(jedis.get("{tag1}foo")).isNull();
}

@Test
public void shouldReturnError_givenNonexistantKey() {
assertThatThrownBy(() -> jedis.rename("{user1}foo", "{user1}newfoo"))
assertThatThrownBy(() -> jedis.rename("{tag1}foo", "{tag1}newfoo"))
.hasMessageContaining(RedisConstants.ERROR_NO_SUCH_KEY);
}

@Test
public void shouldRename_withHash() {
jedis.hset("{user1}foo", "field", "va");
jedis.rename("{user1}foo", "{user1}newfoo");
assertThat(jedis.hget("{user1}newfoo", "field")).isEqualTo("va");
jedis.hset("{tag1}foo", "field", "va");
jedis.rename("{tag1}foo", "{tag1}newfoo");
assertThat(jedis.hget("{tag1}newfoo", "field")).isEqualTo("va");
}

@Test
public void shouldRename_withSet() {
jedis.sadd("{user1}foo", "data");
jedis.rename("{user1}foo", "{user1}newfoo");
assertThat(jedis.smembers("{user1}newfoo")).containsExactly("data");
jedis.sadd("{tag1}foo", "data");
jedis.rename("{tag1}foo", "{tag1}newfoo");
assertThat(jedis.smembers("{tag1}newfoo")).containsExactly("data");
}

@Test
public void shouldReturnOkay_withSameSourceAndTargetKey() {
jedis.set("{user1}blue", "moon");
assertThat(jedis.rename("{user1}blue", "{user1}blue")).isEqualTo("OK");
assertThat(jedis.get("{user1}blue")).isEqualTo("moon");
jedis.set("{tag1}blue", "moon");
assertThat(jedis.rename("{tag1}blue", "{tag1}blue")).isEqualTo("OK");
assertThat(jedis.get("{tag1}blue")).isEqualTo("moon");
}

@Test
public void shouldRename_withExistingTargetKey() {
jedis.set("{user1}foo1", "bar1");
jedis.set("{user1}foo12", "bar2");
String result = jedis.rename("{user1}foo1", "{user1}foo12");
jedis.set("{tag1}foo1", "bar1");
jedis.set("{tag1}foo12", "bar2");
String result = jedis.rename("{tag1}foo1", "{tag1}foo12");
assertThat(result).isEqualTo("OK");
assertThat(jedis.get("{user1}foo12")).isEqualTo("bar1");
assertThat(jedis.get("{user1}foo1")).isNull();
assertThat(jedis.get("{tag1}foo12")).isEqualTo("bar1");
assertThat(jedis.get("{tag1}foo1")).isNull();
}

@Test
Expand All @@ -145,8 +145,8 @@ public void shouldRenameAtomically() {
int numStringsFirstKey = 500000;
int numStringsSecondKey = 30000;

String k1 = "{user1}k1";
String k2 = "{user1}k2";
String k1 = "{tag1}k1";
String k2 = "{tag1}k2";

Runnable initAction = () -> {
flushAll();
Expand Down Expand Up @@ -247,17 +247,17 @@ public void shouldNotDeadlock_concurrentRenames_givenStripeContention()
public void shouldError_givenKeyDeletedDuringRename() {
int iterations = 2000;

jedis.set("{user1}oldKey", "foo");
jedis.set("{tag1}oldKey", "foo");

try {
new ConcurrentLoopingThreads(iterations,
i -> jedis.rename("{user1}oldKey", "{user1}newKey"),
i -> jedis.del("{user1}oldKey"))
i -> jedis.rename("{tag1}oldKey", "{tag1}newKey"),
i -> jedis.del("{tag1}oldKey"))
.runWithAction(() -> {
assertThat(jedis.get("{user1}newKey")).isEqualTo("foo");
assertThat(jedis.exists("{user1}oldKey")).isFalse();
assertThat(jedis.get("{tag1}newKey")).isEqualTo("foo");
assertThat(jedis.exists("{tag1}oldKey")).isFalse();
flushAll();
jedis.set("{user1}oldKey", "foo");
jedis.set("{tag1}oldKey", "foo");
});
} catch (RuntimeException e) {
assertThat(e).hasMessageContaining(ERROR_NO_SUCH_KEY);
Expand All @@ -280,14 +280,14 @@ public void shouldNotDeadlock_concurrentRenames_givenTwoKeysOnSameStripe()
}

private List<String> getKeysOnDifferentStripes() {
String key1 = "{user1}keyz" + new Random().nextInt();
String key1 = "{tag1}keyz" + new Random().nextInt();

RedisKey key1RedisKey = new RedisKey(key1.getBytes());
StripedCoordinator stripedCoordinator = new LockingStripedCoordinator();
int iterator = 0;
String key2;
do {
key2 = "{user1}key" + iterator;
key2 = "{tag1}key" + iterator;
iterator++;
} while (stripedCoordinator.compareStripes(key1RedisKey,
new RedisKey(key2.getBytes())) == 0);
Expand All @@ -297,14 +297,14 @@ private List<String> getKeysOnDifferentStripes() {

private Set<String> getKeysOnSameRandomStripe(int numKeysNeeded) {
Random random = new Random();
String key1 = "{user1}keyz" + random.nextInt();
String key1 = "{tag1}keyz" + random.nextInt();
RedisKey key1RedisKey = new RedisKey(key1.getBytes());
StripedCoordinator stripedCoordinator = new LockingStripedCoordinator();
Set<String> keys = new HashSet<>();
keys.add(key1);

do {
String key2 = "{user1}key" + random.nextInt();
String key2 = "{tag1}key" + random.nextInt();
if (stripedCoordinator.compareStripes(key1RedisKey,
new RedisKey(key2.getBytes())) == 0) {
keys.add(key2);
Expand Down Expand Up @@ -363,12 +363,12 @@ private List<String> getKeysOnSameRandomStripe(int numKeysNeeded, Object toAvoid
String key1;
RedisKey key1RedisKey;
do {
key1 = "{user1}keyz" + new Random().nextInt();
key1 = "{tag1}keyz" + new Random().nextInt();
key1RedisKey = new RedisKey(key1.getBytes());
} while (stripedCoordinator.compareStripes(key1RedisKey, toAvoid) == 0 && keys.add(key1));

do {
String key2 = "{user1}key" + new Random().nextInt();
String key2 = "{tag1}key" + new Random().nextInt();

if (stripedCoordinator.compareStripes(key1RedisKey,
new RedisKey(key2.getBytes())) == 0) {
Expand Down
Loading

0 comments on commit 87c32e4

Please sign in to comment.