Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Refine assertions usage.

Original pull request: #2985
Closes #2982
  • Loading branch information
mp911de committed Sep 10, 2024
1 parent f5ad90a commit fcbe0fd
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2024 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.connection;

import static org.assertj.core.api.Assertions.*;
Expand All @@ -24,7 +39,7 @@ void pendingRecordsCommandRangeShouldThrowExceptionWhenRangeIsNull() {

PendingRecordsCommand command = PendingRecordsCommand.pending(key, groupName);

assertThatThrownBy(() -> command.range(null, 10L)).isInstanceOf(IllegalArgumentException.class);
assertThatIllegalArgumentException().isThrownBy(() -> command.range(null, 10L));
}

@Test // GH-2982
Expand All @@ -36,6 +51,6 @@ void pendingRecordsCommandRangeShouldThrowExceptionWhenCountIsNegative() {
PendingRecordsCommand command = PendingRecordsCommand.pending(key, groupName);
Range<?> range = Range.closed("0", "10");

assertThatThrownBy(() -> command.range(range, -1L)).isInstanceOf(IllegalArgumentException.class);
assertThatIllegalArgumentException().isThrownBy(() -> command.range(range, -1L));
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2024 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.connection;

import static org.assertj.core.api.Assertions.*;
Expand All @@ -16,21 +31,19 @@ class RedisStreamCommandsUnitTests {

@Test // GH-2982
void xPendingOptionsUnboundedShouldThrowExceptionWhenCountIsNegative() {

assertThatThrownBy(() -> XPendingOptions.unbounded(-1L)).isInstanceOf(IllegalArgumentException.class);
assertThatIllegalArgumentException().isThrownBy(() -> XPendingOptions.unbounded(-1L));
}

@Test // GH-2982
void xPendingOptionsRangeShouldThrowExceptionWhenRangeIsNull() {

assertThatThrownBy(() -> XPendingOptions.range(null, 10L)).isInstanceOf(IllegalArgumentException.class);
assertThatIllegalArgumentException().isThrownBy(() -> XPendingOptions.range(null, 10L));
}

@Test // GH-2982
void xPendingOptionsRangeShouldThrowExceptionWhenCountIsNegative() {

Range<?> range = Range.closed("0", "10");

assertThatThrownBy(() -> XPendingOptions.range(range, -1L)).isInstanceOf(IllegalArgumentException.class);
assertThatIllegalArgumentException().isThrownBy(() -> XPendingOptions.range(range, -1L));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ public class DefaultReactiveStreamOperationsIntegrationTests<K, HK, HV> {
return ReactiveOperationsTestParams.testParams();
}

/**
* @param redisTemplate
* @param keyFactory
* @param valueFactory
* @param label parameterized test label, no further use besides that.
*/
public DefaultReactiveStreamOperationsIntegrationTests(Fixture<K, HV> fixture) {

this.serializer = fixture.getSerializer();
Expand Down Expand Up @@ -359,7 +353,6 @@ void pendingShouldReadMessageDetails() {
assertThat(pending.get(0).getConsumerName()).isEqualTo("my-consumer");
assertThat(pending.get(0).getTotalDeliveryCount()).isOne();
}).verifyComplete();

}

@ParameterizedRedisTest // GH-2465
Expand All @@ -384,6 +377,5 @@ void claimShouldReadMessageDetails() {
assertThat(claimed.getValue()).isEqualTo(content);
assertThat(claimed.getId()).isEqualTo(messageId);
}).verifyComplete();

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
import org.springframework.data.redis.connection.stream.*;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ObjectRecord;
import org.springframework.data.redis.connection.stream.PendingMessages;
import org.springframework.data.redis.connection.stream.PendingMessagesSummary;
import org.springframework.data.redis.connection.stream.ReadOffset;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.connection.stream.StreamReadOptions;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.condition.EnabledOnRedisDriver;
import org.springframework.data.redis.test.condition.EnabledOnRedisVersion;
Expand Down Expand Up @@ -65,7 +74,7 @@ public class DefaultStreamOperationsIntegrationTests<K, HK, HV> {
private final StreamOperations<K, HK, HV> streamOps;

public DefaultStreamOperationsIntegrationTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<?> objectFactory) {
ObjectFactory<?> objectFactory) {

this.redisTemplate = redisTemplate;
this.connectionFactory = redisTemplate.getRequiredConnectionFactory();
Expand All @@ -81,15 +90,15 @@ public static Collection<Object[]> testParams() {
params.addAll(AbstractOperationsTestParams
.testParams(JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class)));

if(RedisDetector.isClusterAvailable()) {
if (RedisDetector.isClusterAvailable()) {
params.addAll(AbstractOperationsTestParams
.testParams(JedisConnectionFactoryExtension.getConnectionFactory(RedisCluster.class)));
}

params.addAll(AbstractOperationsTestParams
.testParams(LettuceConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class)));

if(RedisDetector.isClusterAvailable()) {
if (RedisDetector.isClusterAvailable()) {
params.addAll(AbstractOperationsTestParams
.testParams(LettuceConnectionFactoryExtension.getConnectionFactory(RedisCluster.class)));
}
Expand Down Expand Up @@ -305,7 +314,8 @@ void readShouldReadSimpleMessage() {
RecordId messageId1 = streamOps.add(StreamRecords.objectBacked(value).withStreamKey(key));
streamOps.add(StreamRecords.objectBacked(value).withStreamKey(key));

List<ObjectRecord<K, HV>> messages = streamOps.read((Class<HV>) value.getClass(), StreamOffset.create(key, ReadOffset.from("0-0")));
List<ObjectRecord<K, HV>> messages = streamOps.read((Class<HV>) value.getClass(),
StreamOffset.create(key, ReadOffset.from("0-0")));

assertThat(messages).hasSize(2);

Expand Down Expand Up @@ -384,8 +394,7 @@ void pendingShouldReadMessageSummary() {
RecordId messageId = streamOps.add(key, Collections.singletonMap(hashKey, value));
streamOps.createGroup(key, ReadOffset.from("0-0"), "my-group");

streamOps.read(Consumer.from("my-group", "my-consumer"),
StreamOffset.create(key, ReadOffset.lastConsumed()));
streamOps.read(Consumer.from("my-group", "my-consumer"), StreamOffset.create(key, ReadOffset.lastConsumed()));

PendingMessagesSummary pending = streamOps.pending(key, "my-group");

Expand All @@ -403,8 +412,7 @@ void pendingShouldReadMessageDetails() {
RecordId messageId = streamOps.add(key, Collections.singletonMap(hashKey, value));
streamOps.createGroup(key, ReadOffset.from("0-0"), "my-group");

streamOps.read(Consumer.from("my-group", "my-consumer"),
StreamOffset.create(key, ReadOffset.lastConsumed()));
streamOps.read(Consumer.from("my-group", "my-consumer"), StreamOffset.create(key, ReadOffset.lastConsumed()));

PendingMessages pending = streamOps.pending(key, "my-group", Range.unbounded(), 10L);

Expand Down

0 comments on commit fcbe0fd

Please sign in to comment.