// Path: ratelimitj-redis/src/test/java/es/moki/ratelimitj/redis/extensions/RedisStandaloneConnectionSetupExtension.java
// public class RedisStandaloneConnectionSetupExtension implements
//         BeforeAllCallback, AfterAllCallback, AfterEachCallback {
// 
//     private static RedisClient client;
//     private static StatefulRedisConnection<String, String> connect;
//     private static RedisReactiveCommands<String, String> reactiveCommands;
// 
//     @Override
//     @SuppressWarnings("FutureReturnValueIgnored")
//     public void afterAll(ExtensionContext context) {
//         client.shutdownAsync();
//     }
// 
//     @Override
//     public void afterEach(ExtensionContext context) {
//         connect.sync().flushdb();
//     }
// 
//     @Override
//     public void beforeAll(ExtensionContext context) {
//         client = RedisClient.create("redis://localhost:7006");
//         connect = client.connect();
//         reactiveCommands = connect.reactive();
//     }
// 
//     public RedisClient getClient() {
//         return client;
//     }
// 
//     public RedisScriptingReactiveCommands<String, String> getScriptingReactiveCommands() {
//         return reactiveCommands;
//     }
// 
//     public RedisKeyReactiveCommands<String, String> getKeyReactiveCommands() {
//         return reactiveCommands;
//     }
// 
// }


import es.moki.ratelimitj.redis.extensions.RedisStandaloneConnectionSetupExtension;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import static io.lettuce.core.ScriptOutputType.VALUE;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
package es.moki.ratelimitj.redis.request;





class RedisScriptLoaderTest {

    @RegisterExtension
    static RedisStandaloneConnectionSetupExtension extension = new RedisStandaloneConnectionSetupExtension();

    private void scriptFlush() {
        extension.getScriptingReactiveCommands().scriptFlush().block();
    }

    @Test
    @DisplayName("should load rate limit lua script into Redis")
    void shouldLoadScript() {
        RedisScriptLoader scriptLoader = new RedisScriptLoader(extension.getScriptingReactiveCommands(), "hello-world.lua");
        scriptFlush();

        String sha = scriptLoader.storedScript().block(Duration.ofSeconds(5)).getSha();
        assertThat(sha).isNotEmpty();
        assertThat(extension.getScriptingReactiveCommands().scriptExists(sha).blockFirst()).isTrue();
    }

    @Test
    @DisplayName("should cache loaded sha")
    void shouldCache() {
        RedisScriptLoader scriptLoader = new RedisScriptLoader(extension.getScriptingReactiveCommands(), "hello-world.lua");

        assertThat(scriptLoader.storedScript().block(Duration.ofSeconds(5)).getSha()).isNotEmpty();

        scriptFlush();

        assertThat(scriptLoader.storedScript().block(Duration.ofSeconds(5)).getSha()).isNotEmpty();
    }

    @Test
    @DisplayName("should eagerly load rate limit lua script into Redis")
    void shouldEagerlyLoadScript() {
        RedisScriptLoader scriptLoader = new RedisScriptLoader(extension.getScriptingReactiveCommands(), "hello-world.lua", true);
        String sha = scriptLoader.storedScript().block(Duration.ofSeconds(5)).getSha();
// Path: ratelimitj-redis/src/test/java/es/moki/ratelimitj/redis/extensions/RedisStandaloneConnectionSetupExtension.java
// public class RedisStandaloneConnectionSetupExtension implements
//         BeforeAllCallback, AfterAllCallback, AfterEachCallback {
// 
//     private static RedisClient client;
//     private static StatefulRedisConnection<String, String> connect;
//     private static RedisReactiveCommands<String, String> reactiveCommands;
// 
//     @Override
//     @SuppressWarnings("FutureReturnValueIgnored")
//     public void afterAll(ExtensionContext context) {
//         client.shutdownAsync();
//     }
// 
//     @Override
//     public void afterEach(ExtensionContext context) {
//         connect.sync().flushdb();
//     }
// 
//     @Override
//     public void beforeAll(ExtensionContext context) {
//         client = RedisClient.create("redis://localhost:7006");
//         connect = client.connect();
//         reactiveCommands = connect.reactive();
//     }
// 
//     public RedisClient getClient() {
//         return client;
//     }
// 
//     public RedisScriptingReactiveCommands<String, String> getScriptingReactiveCommands() {
//         return reactiveCommands;
//     }
// 
//     public RedisKeyReactiveCommands<String, String> getKeyReactiveCommands() {
//         return reactiveCommands;
//     }
// 
// }


// Path: ratelimitj-redis/src/test/java/es/moki/ratelimitj/redis/request/RedisScriptLoaderTest.java
import es.moki.ratelimitj.redis.extensions.RedisStandaloneConnectionSetupExtension;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import static io.lettuce.core.ScriptOutputType.VALUE;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;

package es.moki.ratelimitj.redis.request;





class RedisScriptLoaderTest {

    @RegisterExtension
    static RedisStandaloneConnectionSetupExtension extension = new RedisStandaloneConnectionSetupExtension();

    private void scriptFlush() {
        extension.getScriptingReactiveCommands().scriptFlush().block();
    }

    @Test
    @DisplayName("should load rate limit lua script into Redis")
    void shouldLoadScript() {
        RedisScriptLoader scriptLoader = new RedisScriptLoader(extension.getScriptingReactiveCommands(), "hello-world.lua");
        scriptFlush();

        String sha = scriptLoader.storedScript().block(Duration.ofSeconds(5)).getSha();
        assertThat(sha).isNotEmpty();
        assertThat(extension.getScriptingReactiveCommands().scriptExists(sha).blockFirst()).isTrue();
    }

    @Test
    @DisplayName("should cache loaded sha")
    void shouldCache() {
        RedisScriptLoader scriptLoader = new RedisScriptLoader(extension.getScriptingReactiveCommands(), "hello-world.lua");

        assertThat(scriptLoader.storedScript().block(Duration.ofSeconds(5)).getSha()).isNotEmpty();

        scriptFlush();

        assertThat(scriptLoader.storedScript().block(Duration.ofSeconds(5)).getSha()).isNotEmpty();
    }

    @Test
    @DisplayName("should eagerly load rate limit lua script into Redis")
    void shouldEagerlyLoadScript() {
        RedisScriptLoader scriptLoader = new RedisScriptLoader(extension.getScriptingReactiveCommands(), "hello-world.lua", true);
        String sha = scriptLoader.storedScript().block(Duration.ofSeconds(5)).getSha();
        assertThat(sha).isNotEmpty();