|
| 1 | +/* |
| 2 | + * Copyright 2011-Present, Redis Ltd. and Contributors |
| 3 | + * All rights reserved. |
| 4 | + * |
| 5 | + * Licensed under the MIT License. |
| 6 | + * |
| 7 | + * This file contains contributions from third-party contributors |
| 8 | + * licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | +package io.lettuce.core.commands; |
| 21 | + |
| 22 | +import static io.lettuce.TestTags.INTEGRATION_TEST; |
| 23 | +import static org.assertj.core.api.Assertions.assertThat; |
| 24 | +import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 25 | +import static org.junit.jupiter.api.Assumptions.assumeTrue; |
| 26 | + |
| 27 | +import io.lettuce.core.*; |
| 28 | +import io.lettuce.core.api.sync.RedisCommands; |
| 29 | +import io.lettuce.test.condition.RedisConditions; |
| 30 | + |
| 31 | +import org.junit.jupiter.api.*; |
| 32 | + |
| 33 | +import java.util.Collections; |
| 34 | +import java.util.Map; |
| 35 | + |
| 36 | +/** |
| 37 | + * Integration tests for {@link io.lettuce.core.api.sync.RedisServerCommands} with Redis modules since Redis 8.0. |
| 38 | + * |
| 39 | + * @author M Sazzadul Hoque |
| 40 | + */ |
| 41 | +@Tag(INTEGRATION_TEST) |
| 42 | +public class ConsolidatedConfigurationCommandIntegrationTests extends RedisContainerIntegrationTests { |
| 43 | + |
| 44 | + private static RedisClient client; |
| 45 | + |
| 46 | + private static RedisCommands<String, String> redis; |
| 47 | + |
| 48 | + @BeforeAll |
| 49 | + public static void setup() { |
| 50 | + RedisURI redisURI = RedisURI.Builder.redis("127.0.0.1").withPort(16379).build(); |
| 51 | + |
| 52 | + client = RedisClient.create(redisURI); |
| 53 | + redis = client.connect().sync(); |
| 54 | + assumeTrue(RedisConditions.of(redis).hasVersionGreaterOrEqualsTo("7.9")); |
| 55 | + } |
| 56 | + |
| 57 | + @AfterAll |
| 58 | + static void teardown() { |
| 59 | + if (client != null) { |
| 60 | + client.shutdown(); |
| 61 | + } |
| 62 | + } |
| 63 | + |
| 64 | + @BeforeEach |
| 65 | + void setUp() { |
| 66 | + redis.flushall(); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void setSearchConfigGloballyTest() { |
| 71 | + final String configParam = "search-default-dialect"; |
| 72 | + // confirm default |
| 73 | + assertThat(redis.configGet(configParam)).isEqualTo(Collections.singletonMap(configParam, "1")); |
| 74 | + |
| 75 | + try { |
| 76 | + assertThat(redis.configSet(configParam, "2")).isEqualTo("OK"); |
| 77 | + assertThat(redis.configGet(configParam)).isEqualTo(Collections.singletonMap(configParam, "2")); |
| 78 | + } finally { |
| 79 | + // restore to default |
| 80 | + assertThat(redis.configSet(configParam, "1")).isEqualTo("OK"); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + public void setReadOnlySearchConfigTest() { |
| 86 | + assertThatThrownBy(() -> redis.configSet("search-max-doctablesize", "10")) |
| 87 | + .isInstanceOf(RedisCommandExecutionException.class); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void getSearchConfigSettingTest() { |
| 92 | + assertThat(redis.configGet("search-timeout")).hasSize(1); |
| 93 | + } |
| 94 | + |
| 95 | + @Test |
| 96 | + public void getTSConfigSettingTest() { |
| 97 | + assertThat(redis.configGet("ts-retention-policy")).hasSize(1); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + public void getBFConfigSettingTest() { |
| 102 | + assertThat(redis.configGet("bf-error-rate")).hasSize(1); |
| 103 | + } |
| 104 | + |
| 105 | + @Test |
| 106 | + public void getCFConfigSettingTest() { |
| 107 | + assertThat(redis.configGet("cf-initial-size")).hasSize(1); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void getAllConfigSettings() { |
| 112 | + assertThat(redis.configGet("*").keySet()).contains("search-default-dialect", "search-timeout", "ts-retention-policy", |
| 113 | + "bf-error-rate", "cf-initial-size"); |
| 114 | + } |
| 115 | + |
| 116 | +} |
0 commit comments