Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for RESP3 types (Part 1) #55

Merged
Merged
Show file tree
Hide file tree
Changes from 9 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
9 changes: 5 additions & 4 deletions java/client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,28 @@ tasks.register('cleanProtobuf') {
}
}

// TODO: Create a separte task for testing and move conditional compilation Rust flag there
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved
tasks.register('buildRustRelease', Exec) {
commandLine 'cargo', 'build', '--release'
workingDir project.rootDir
environment 'CARGO_TERM_COLOR', 'always'
environment CARGO_TERM_COLOR: 'always', CARGO_BUILD_RUSTFLAGS: '--cfg ffi_test'
}

tasks.register('buildRustReleaseStrip', Exec) {
commandLine 'cargo', 'build', '--release', '--strip'
workingDir project.rootDir
environment 'CARGO_TERM_COLOR', 'always'
environment CARGO_TERM_COLOR: 'always', CARGO_BUILD_RUSTFLAGS: '--cfg ffi_test'
}

tasks.register('buildRust', Exec) {
commandLine 'cargo', 'build'
workingDir project.rootDir
environment 'CARGO_TERM_COLOR', 'always'
environment CARGO_TERM_COLOR: 'always', CARGO_BUILD_RUSTFLAGS: '--cfg ffi_test'
}

tasks.register('buildWithRust') {
dependsOn 'buildRust'
finalizedBy 'build'
finalizedBy 'build', 'test'
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved
}

tasks.register('buildWithRustRelease') {
Expand Down
144 changes: 144 additions & 0 deletions java/client/src/test/java/glide/ffi/FfiTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
package glide.ffi;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import glide.ffi.resolvers.RedisValueResolver;
import java.util.HashMap;
import java.util.HashSet;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class FfiTest {

static {
System.loadLibrary("glide_rs");
}

public static native long createLeakedNil();

public static native long createLeakedSimpleString(String value);

public static native long createLeakedOkay();

public static native long createLeakedInt(long value);

public static native long createLeakedBulkString(byte[] value);

public static native long createLeakedLongArray(long[] value);

public static native long createLeakedMap();

public static native long createLeakedDouble(double value);

public static native long createLeakedBoolean(boolean value);

public static native long createLeakedVerbatimString(String value);

public static native long createLeakedLongSet(long[] value);

@BeforeEach
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved
public void init() {}

@AfterEach
public void teardown() {}
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved

@Test
public void redisValueToJavaValue_Nil() {
long ptr = FfiTest.createLeakedNil();
Object nilValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(nilValue == null);
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void redisValueToJavaValue_SimpleString() {
long ptr = FfiTest.createLeakedSimpleString("hello");
Object simpleStringValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(simpleStringValue instanceof String);
assertEquals((String) simpleStringValue, "hello");
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void redisValueToJavaValue_Okay() {
long ptr = FfiTest.createLeakedOkay();
Object okayValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(okayValue instanceof String);
assertEquals((String) okayValue, "OK");
}

@Test
public void redisValueToJavaValue_Int() {
long ptr = FfiTest.createLeakedInt(100L);
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved
Object longValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(longValue instanceof Long);
assertEquals((Long) longValue, 100L);
}

@Test
public void redisValueToJavaValue_BulkString() {
byte[] bulkString = "hello".getBytes();
long ptr = FfiTest.createLeakedBulkString(bulkString);
Object bulkStringValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(bulkStringValue instanceof String);
assertEquals((String) bulkStringValue, "hello");
}

@Test
public void redisValueToJavaValue_Array() {
long[] array = {1L, 2L, 3L};
long ptr = FfiTest.createLeakedLongArray(array);
Object longArrayValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(longArrayValue instanceof Object[]);
Object[] result = (Object[]) longArrayValue;
assertEquals((Long) result[0], 1L);
assertEquals((Long) result[1], 2L);
assertEquals((Long) result[2], 3L);
jonathanl-bq marked this conversation as resolved.
Show resolved Hide resolved
}

@Test
public void redisValueToJavaValue_Map() {
long ptr = FfiTest.createLeakedMap();
Object mapValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(mapValue instanceof HashMap);
HashMap<Object, Object> result = (HashMap<Object, Object>) mapValue;
assertEquals(result.get(1L), 2L);
assertEquals(result.get(3L), "hi");
}

@Test
public void redisValueToJavaValue_Double() {
long ptr = FfiTest.createLeakedDouble(1.0d);
Object doubleValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(doubleValue instanceof Double);
assertEquals((Double) doubleValue, 1.0d);
}

@Test
public void redisValueToJavaValue_Boolean() {
long ptr = FfiTest.createLeakedBoolean(true);
Object booleanValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(booleanValue instanceof Boolean);
assertEquals((Boolean) booleanValue, true);
}

@Test
public void redisValueToJavaValue_VerbatimString() {
long ptr = FfiTest.createLeakedVerbatimString("hello");
Object verbatimStringValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(verbatimStringValue instanceof String);
assertEquals((String) verbatimStringValue, "hello");
}

@Test
public void redisValueToJavaValue_Set() {
long[] array = {1L, 2L, 2L};
long ptr = FfiTest.createLeakedLongSet(array);
Object longSetValue = RedisValueResolver.valueFromPointer(ptr);
assertTrue(longSetValue instanceof HashSet);
HashSet<Long> result = (HashSet<Long>) longSetValue;
assertTrue(result.contains(1L));
assertTrue(result.contains(2L));
assertEquals(result.size(), 2);
}
}
Loading
Loading