Skip to content

Commit

Permalink
Merge branch 'main' into lettuce-connection-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
big-cir authored Jan 31, 2025
2 parents d7bd9da + 9dd83b1 commit e2fe8a1
Show file tree
Hide file tree
Showing 13 changed files with 375 additions and 14 deletions.
37 changes: 25 additions & 12 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,35 @@ on:
schedule:
- cron: '0 1 * * *' # nightly build
workflow_dispatch:
inputs:
redis_version:
description: "Redis stack version to use for testing"
required: false
default: "8.0-M02"
type: choice
options:
- "8.0-M02"
- "rs-7.4.0-v1"
- "rs-7.2.0-v13"

jobs:

build:
name: Build and Test
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
redis_version:
- "unstable"
- "8.0"
- "7.4"
- "7.2"

steps:
- name: Test Redis Server Version
id: map-tags
run: |
# Map requested version to github or tag
case "${{ matrix.redis_version }}" in
"unstable") redis_branch="unstable" stack_version="8.0-M04-pre" ;;
"8.0") redis_branch="8.0" stack_version="8.0-M04-pre" ;;
"7.4") redis_branch="7.4" stack_version="rs-7.4.0-v2" ;;
"7.2") redis_branch="7.2" stack_version="rs-7.2.0-v14" ;;
*) echo "Unsupported version: ${{ matrix.redis_version }}" && exit 1 ;;
esac
# Save them as outputs for later use
echo "redis_branch=$redis_branch" >> $GITHUB_OUTPUT
echo "redis_stack_version=$stack_version" >> $GITHUB_OUTPUT
- name: Checkout project
uses: actions/checkout@v4
- name: Set Java up in the runner
Expand Down Expand Up @@ -61,7 +73,8 @@ jobs:
run: |
make test-coverage
env:
REDIS_STACK_VERSION: ${{ inputs.redis_version || '8.0-M02' }}
REDIS: ${{ steps.map-tags.outputs.redis_branch }}
REDIS_STACK_VERSION: ${{ steps.map-tags.outputs.redis_stack_version }}
JVM_OPTS: -Xmx3200m
TERM: dumb
- name: Upload coverage reports to Codecov
Expand Down
42 changes: 41 additions & 1 deletion src/main/java/io/lettuce/core/AclCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,45 @@ public enum AclCategory {
/**
* scripting command
*/
SCRIPTING
SCRIPTING,

/**
* bloom command
*/
BLOOM,

/**
* cuckoo command
*/
CUCKOO,

/**
* count-min-sketch command
*/
CMS,

/**
* top-k command
*/
TOPK,

/**
* t-digest command
*/
TDIGEST,

/**
* search command
*/
SEARCH,

/**
* timeseries command
*/
TIMESERIES,

/**
* json command
*/
JSON
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ public class CommandDetailParser {
aclCategoriesMap.put("@connection", AclCategory.CONNECTION);
aclCategoriesMap.put("@transaction", AclCategory.TRANSACTION);
aclCategoriesMap.put("@scripting", AclCategory.SCRIPTING);
aclCategoriesMap.put("@bloom", AclCategory.BLOOM);
aclCategoriesMap.put("@cuckoo", AclCategory.CUCKOO);
aclCategoriesMap.put("@cms", AclCategory.CMS);
aclCategoriesMap.put("@topk", AclCategory.TOPK);
aclCategoriesMap.put("@tdigest", AclCategory.TDIGEST);
aclCategoriesMap.put("@search", AclCategory.SEARCH);
aclCategoriesMap.put("@timeseries", AclCategory.TIMESERIES);
aclCategoriesMap.put("@json", AclCategory.JSON);

ACL_CATEGORY_MAPPING = Collections.unmodifiableMap(aclCategoriesMap);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class RedisContainerIntegrationTests {

private static final String REDIS_STACK_CLUSTER = "clustered-stack";

private static final String REDIS_STACK_VERSION = System.getProperty("REDIS_STACK_VERSION", "8.0-M02");;
private static final String REDIS_STACK_VERSION = System.getProperty("REDIS_STACK_VERSION", "8.0-M04-pre");;

private static Exception initializationException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static io.lettuce.TestTags.INTEGRATION_TEST;
import static org.assertj.core.api.AssertionsForClassTypes.*;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,6 +31,7 @@

import javax.inject.Inject;

import io.lettuce.test.condition.RedisConditions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -161,6 +163,8 @@ void hashSinglePass() {

@Test
void hashNoValuesSinglePass() {
// NOVALUES flag (since Redis 7.4)
assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("7.4"));

redis.hmset(key, KeysAndValues.MAP);

Expand Down Expand Up @@ -194,6 +198,8 @@ void hashMultiPass() {

@Test
void hashNoValuesMultiPass() {
// NOVALUES flag (since Redis 7.4)
assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("7.4"));

redis.hmset(key, KeysAndValues.MAP);

Expand Down
6 changes: 6 additions & 0 deletions src/test/java/io/lettuce/core/ScanStreamIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@

import static io.lettuce.TestTags.INTEGRATION_TEST;
import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.util.List;
import java.util.stream.IntStream;

import javax.inject.Inject;

import io.lettuce.test.condition.RedisConditions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -95,6 +97,8 @@ void shouldHscanIteratively() {

@Test
void shouldHscanNovaluesIteratively() {
// NOVALUES flag (since Redis 7.4)
assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("7.4"));

for (int i = 0; i < 1000; i++) {
redis.hset(key, "field-" + i, "value-" + i);
Expand Down Expand Up @@ -160,6 +164,8 @@ void shouldCorrectlyEmitItemsWithConcurrentPoll() {

@Test
void shouldCorrectlyEmitKeysWithConcurrentPoll() {
// NOVALUES flag (since Redis 7.4)
assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("7.4"));

RedisReactiveCommands<String, String> commands = connection.reactive();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static io.lettuce.TestTags.INTEGRATION_TEST;
import static org.assertj.core.api.AssertionsForClassTypes.*;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -30,6 +31,7 @@

import javax.inject.Inject;

import io.lettuce.test.condition.RedisConditions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -185,6 +187,8 @@ void hashSinglePass() {

@Test
void hashNovaluesSinglePass() {
// NOVALUES flag (since Redis 7.4)
assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("7.4"));

redis.hmset(key, KeysAndValues.MAP);

Expand Down Expand Up @@ -215,6 +219,8 @@ void hashMultiPass() {

@Test
void hashNovaluesMultiPass() {
// NOVALUES flag (since Redis 7.4)
assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("7.4"));

redis.hmset(key, KeysAndValues.MAP);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
/*
* Copyright 2011-Present, Redis Ltd. and Contributors
* All rights reserved.
*
* Licensed under the MIT License.
*
* This file contains contributions from third-party contributors
* 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 io.lettuce.core.commands;

import io.lettuce.core.*;
import io.lettuce.core.api.sync.RedisCommands;

import io.lettuce.test.condition.RedisConditions;
import org.junit.jupiter.api.*;

import java.util.Arrays;

import static io.lettuce.TestTags.INTEGRATION_TEST;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

/**
* Integration tests for ACL commands with Redis modules since Redis 8.0.
*
* @author M Sazzadul Hoque
*/
@Tag(INTEGRATION_TEST)
public class ConsolidatedAclCommandIntegrationTests extends RedisContainerIntegrationTests {

private static RedisClient client;

private static RedisCommands<String, String> redis;

@BeforeAll
public static void setup() {
RedisURI redisURI = RedisURI.Builder.redis("127.0.0.1").withPort(16379).build();

client = RedisClient.create(redisURI);
redis = client.connect().sync();
assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("7.9"));
}

@AfterAll
static void teardown() {
if (client != null) {
client.shutdown();
}
}

@BeforeEach
void setUp() {
redis.flushall();
redis.aclUsers().stream().filter(o -> !"default".equals(o)).forEach(redis::aclDeluser);
redis.aclLogReset();
}

@Test
public void listACLCategoriesTest() {
assertThat(redis.aclCat()).containsAll(Arrays.asList(AclCategory.BLOOM, AclCategory.CUCKOO, AclCategory.CMS,
AclCategory.TOPK, AclCategory.TDIGEST, AclCategory.SEARCH, AclCategory.TIMESERIES, AclCategory.JSON));
}

@Test
void grantBloomCommandCatTest() {
grantModuleCommandCatTest(AclCategory.BLOOM, "bloom");
}

@Test
void grantCuckooCommandCatTest() {
grantModuleCommandCatTest(AclCategory.CUCKOO, "cuckoo");
}

@Test
void grantCmsCommandCatTest() {
grantModuleCommandCatTest(AclCategory.CMS, "cms");
}

@Test
void grantTopkCommandCatTest() {
grantModuleCommandCatTest(AclCategory.TOPK, "topk");
}

@Test
void grantTdigestCommandCatTest() {
grantModuleCommandCatTest(AclCategory.TDIGEST, "tdigest");
}

@Test
void grantSearchCommandCatTest() {
grantModuleCommandCatTest(AclCategory.SEARCH, "search");
}

@Test
void grantTimeseriesCommandCatTest() {
grantModuleCommandCatTest(AclCategory.TIMESERIES, "timeseries");
}

@Test
void grantJsonCommandCatTest() {
grantModuleCommandCatTest(AclCategory.JSON, "json");
}

private void grantModuleCommandCatTest(AclCategory category, String categoryStr) {
assertThat(redis.aclDeluser("foo")).isNotNull();
AclSetuserArgs args = AclSetuserArgs.Builder.on().addCategory(category);
assertThat(redis.aclSetuser("foo", args)).isEqualTo("OK");
assertThat(redis.aclGetuser("foo")).contains("-@all +@" + categoryStr);
assertThat(redis.aclDeluser("foo")).isNotNull();
}

}
Loading

0 comments on commit e2fe8a1

Please sign in to comment.