Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/main/java/io/lettuce/core/output/ObjectOutput.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.lettuce.core.output;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
Expand Down Expand Up @@ -42,11 +41,6 @@ public ObjectOutput(RedisCodec<K, V> codec) {

@Override
public void set(long integer) {

if (!initialized) {
output = new ArrayList<>();
}

setValue(integer);
}

Expand Down Expand Up @@ -78,6 +72,12 @@ public void setSingle(ByteBuffer bytes) {
@SuppressWarnings("unchecked")
private void setValue(Object value) {

if (!initialized) {
output = value;
initialized = true;
return;
}

if (output != null) {

if (output instanceof Collection) {
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/io/lettuce/core/output/ObjectOutputUnitTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.lettuce.TestTags.UNIT_TEST;
import static org.assertj.core.api.Assertions.*;

import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

Expand All @@ -22,6 +23,53 @@
@Tag(UNIT_TEST)
class ObjectOutputUnitTests {

@Test
void shouldParseTopLevelBulkString() {

String in = "$4\r\ntrue\r\n";
RedisStateMachine rsm = new RedisStateMachine(ByteBufAllocator.DEFAULT);
ObjectOutput<String, String> output = new ObjectOutput<>(StringCodec.UTF8);
rsm.decode(Unpooled.wrappedBuffer(in.getBytes(StandardCharsets.UTF_8)), output, exception -> {
throw (RuntimeException) exception;
});
assertThat(output.get()).isEqualTo("true");
}

@Test
void shouldParseTopLevelBoolean() {

RedisStateMachine rsm = new RedisStateMachine(ByteBufAllocator.DEFAULT);
ObjectOutput<String, String> output = new ObjectOutput<>(StringCodec.UTF8);
rsm.decode(Unpooled.wrappedBuffer("#t\r\n".getBytes(StandardCharsets.UTF_8)), output, exception -> {
throw (RuntimeException) exception;
});
assertThat(output.get()).isEqualTo(true);
}

@Test
void shouldParseTopLevelDouble() {

String in = ",1.5\r\n";
RedisStateMachine rsm = new RedisStateMachine(ByteBufAllocator.DEFAULT);
ObjectOutput<String, String> output = new ObjectOutput<>(StringCodec.UTF8);
rsm.decode(Unpooled.wrappedBuffer(in.getBytes(StandardCharsets.UTF_8)), output, exception -> {
throw (RuntimeException) exception;
});
assertThat(output.get()).isEqualTo(1.5d);
}

@Test
void shouldParseTopLevelIntegerAsScalar() {

String in = ":3\r\n";
RedisStateMachine rsm = new RedisStateMachine(ByteBufAllocator.DEFAULT);
ObjectOutput<String, String> output = new ObjectOutput<>(StringCodec.UTF8);
rsm.decode(Unpooled.wrappedBuffer(in.getBytes(StandardCharsets.UTF_8)), output, exception -> {
throw (RuntimeException) exception;
});
assertThat(output.get()).isEqualTo(3L);
}

@Test
void shouldParseHelloWithModules() {

Expand Down