Removed deprecated SpinBarrier.

Closes #2222
This commit is contained in:
Hendrik Duerkop
2022-01-04 15:02:30 +01:00
committed by Mark Paluch
parent 13be206128
commit 4b9738d61d
5 changed files with 36 additions and 63 deletions

View File

@@ -1,46 +0,0 @@
/*
* Copyright 2013-2021 the original author or authors.
*
* 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
*
* https://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 org.springframework.data.redis;
import java.util.concurrent.TimeUnit;
import org.awaitility.Awaitility;
/**
* @author Jennifer Hickey
* @author Mark Paluch
* @deprecated Use {@link Awaitility}.
*/
@Deprecated
public abstract class SpinBarrier {
/**
* Periodically tests for a condition until it is met or a timeout occurs
*
* @param condition The condition to periodically test
* @param timeout The timeout
* @return true if condition passes, false if condition does not pass within timeout
*/
public static boolean waitFor(TestCondition condition, long timeout) {
try {
Awaitility.await().atMost(timeout, TimeUnit.MILLISECONDS).until(condition::passes);
return true;
} catch (Exception e) {
return false;
}
}
}

View File

@@ -15,8 +15,10 @@
*/
package org.springframework.data.redis;
import org.awaitility.Awaitility;
/**
* A condition to test periodically, used in conjunction with {@link SpinBarrier}
* A condition to test periodically, used in conjunction with {@link Awaitility}
*
* @author Jennifer Hickey
*/

View File

@@ -17,7 +17,7 @@ package org.springframework.data.redis.connection;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.*;
import static org.springframework.data.redis.SpinBarrier.*;
import static org.awaitility.Awaitility.await;
import static org.springframework.data.redis.connection.BitFieldSubCommands.*;
import static org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldIncrBy.Overflow.*;
import static org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldType.*;
@@ -36,6 +36,7 @@ import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import org.assertj.core.data.Offset;
import org.awaitility.Awaitility;
import org.junit.AssumptionViolatedException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
@@ -162,7 +163,9 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.expire("exp", 1));
verifyResults(Arrays.asList(true, true));
assertThat(waitFor(new KeyExpired("exp"), 3000L)).isTrue();
KeyExpired keyExpired = new KeyExpired("exp");
await().atMost(Duration.ofMillis(3000L)).until(keyExpired::passes);
}
@Test // DATAREDIS-1103
@@ -185,7 +188,9 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.set("exp2", "true"));
actual.add(connection.expireAt("exp2", System.currentTimeMillis() / 1000 + 1));
verifyResults(Arrays.asList(true, true));
assertThat(waitFor(new KeyExpired("exp2"), 3000L)).isTrue();
KeyExpired keyExpired = new KeyExpired("exp2");
await().atMost(Duration.ofMillis(3000L)).until(keyExpired::passes);
}
@LongRunningTest
@@ -194,7 +199,9 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.set("exp", "true"));
actual.add(connection.pExpire("exp", 100));
verifyResults(Arrays.asList(true, true));
assertThat(waitFor(new KeyExpired("exp"), 1000L)).isTrue();
KeyExpired keyExpired = new KeyExpired("exp");
await().atMost(Duration.ofMillis(1000L)).until(keyExpired::passes);
}
@Test
@@ -209,7 +216,9 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.set("exp2", "true"));
actual.add(connection.pExpireAt("exp2", System.currentTimeMillis() + 200));
verifyResults(Arrays.asList(true, true));
assertThat(waitFor(new KeyExpired("exp2"), 1000L)).isTrue();
KeyExpired keyExpired = new KeyExpired("exp2");
await().atMost(Duration.ofMillis(1000L)).until(keyExpired::passes);
}
@LongRunningTest
@@ -390,7 +399,9 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.get("expy"));
verifyResults(Arrays.asList(true, "yep"));
assertThat(waitFor(new KeyExpired("expy"), 2500L)).isTrue();
KeyExpired keyExpired = new KeyExpired("expy");
await().atMost(Duration.ofMillis(2500L)).until(keyExpired::passes);
}
@LongRunningTest // DATAREDIS-271
@@ -400,7 +411,9 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.get("expy"));
verifyResults(Arrays.asList(true, "yep"));
assertThat(waitFor(new KeyExpired("expy"), 2500L)).isTrue();
KeyExpired keyExpired = new KeyExpired("expy");
await().atMost(Duration.ofMillis(2500L)).until(keyExpired::passes);
}
@LongRunningTest
@@ -632,7 +645,8 @@ public abstract class AbstractConnectionIntegrationTests {
Thread th = new Thread(() -> {
// sync to let the registration happen
waitFor(connection::isSubscribed, 2000);
await().atMost(Duration.ofMillis(2000L)).until(connection::isSubscribed);
try {
Thread.sleep(500);
} catch (InterruptedException o_O) {}
@@ -674,7 +688,7 @@ public abstract class AbstractConnectionIntegrationTests {
Thread th = new Thread(() -> {
// sync to let the registration happen
waitFor(connection::isSubscribed, 2000);
await().atMost(Duration.ofMillis(2000L)).until(connection::isSubscribed);
try {
Thread.sleep(500);
@@ -1093,7 +1107,9 @@ public abstract class AbstractConnectionIntegrationTests {
actual.add(connection.get("testing"));
connection.restore("testing".getBytes(), 100L, (byte[]) results.get(1));
verifyResults(Arrays.asList(1L, null));
assertThat(waitFor(new KeyExpired("testing"), 400L)).isTrue();
KeyExpired keyExpired = new KeyExpired("testing");
await().atMost(Duration.ofMillis(400L)).until(keyExpired::passes);
}
@Test

View File

@@ -17,7 +17,7 @@ package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.*;
import static org.springframework.data.redis.SpinBarrier.*;
import static org.awaitility.Awaitility.await;
import java.text.DecimalFormat;
import java.time.Duration;
@@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.test.condition.EnabledIfLongRunningTest;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
@@ -316,7 +317,7 @@ public class DefaultValueOperationsIntegrationTests<K, V> {
valueOps.set(key, value, 1, TimeUnit.MILLISECONDS);
waitFor(() -> (!redisTemplate.hasKey(key)), 500);
await().atMost(Duration.ofMillis(500L)).until(() -> !redisTemplate.hasKey(key));
}
@ParameterizedRedisTest

View File

@@ -17,7 +17,7 @@ package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.*;
import static org.springframework.data.redis.SpinBarrier.*;
import static org.awaitility.Awaitility.await;
import java.time.Duration;
import java.time.Instant;
@@ -617,7 +617,7 @@ public class RedisTemplateIntegrationTests<K, V> {
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
redisTemplate.expireAt(key1, new Date(System.currentTimeMillis() + 5L));
waitFor(() -> (!redisTemplate.hasKey(key1)), 5L);
await().atMost(Duration.ofMillis(5L)).until(() -> !redisTemplate.hasKey(key1));
}
@ParameterizedRedisTest // DATAREDIS-611
@@ -626,7 +626,7 @@ public class RedisTemplateIntegrationTests<K, V> {
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
redisTemplate.expireAt(key1, Instant.now().plus(5, ChronoUnit.MILLIS));
waitFor(() -> (!redisTemplate.hasKey(key1)), 5L);
await().atMost(Duration.ofMillis(5L)).until(() -> !redisTemplate.hasKey(key1));
}
@ParameterizedRedisTest
@@ -644,7 +644,7 @@ public class RedisTemplateIntegrationTests<K, V> {
template2.boundValueOps((String) key1).set((String) value1);
template2.expireAt((String) key1, new Date(System.currentTimeMillis() + 5L));
// Just ensure this works as expected, pExpireAt just adds some precision over expireAt
waitFor(() -> (!template2.hasKey((String) key1)), 5L);
await().atMost(Duration.ofMillis(5L)).until(() -> !template2.hasKey((String) key1));
}
@ParameterizedRedisTest