Search in sources :

Example 71 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project redisson by redisson.

the class RedissonBatchTest method testConnectionLeakAfterError.

@ParameterizedTest
@MethodSource("data")
public void testConnectionLeakAfterError() throws InterruptedException {
    Config config = createConfig();
    config.useSingleServer().setRetryInterval(100).setTimeout(200).setConnectionMinimumIdleSize(1).setConnectionPoolSize(1);
    RedissonClient redisson = Redisson.create(config);
    BatchOptions batchOptions = BatchOptions.defaults().executionMode(ExecutionMode.REDIS_WRITE_ATOMIC);
    RBatch batch1 = redisson.createBatch(batchOptions);
    for (int i = 0; i < 150000; i++) {
        batch1.getBucket("test").setAsync(123);
    }
    Assertions.assertThatThrownBy(() -> {
        batch1.execute();
    });
    // time to reconnect broken connection
    Thread.sleep(300);
    redisson.getBucket("test3").set(4);
    assertThat(redisson.getBucket("test3").get()).isEqualTo(4);
    RBatch batch = redisson.createBatch(batchOptions);
    batch.getBucket("test1").setAsync(1);
    batch.getBucket("test2").setAsync(2);
    batch.execute();
    assertThat(redisson.getBucket("test1").get()).isEqualTo(1);
    assertThat(redisson.getBucket("test2").get()).isEqualTo(2);
    redisson.shutdown();
}
Also used : Config(org.redisson.config.Config) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 72 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project redisson by redisson.

the class RedissonBatchTest method testWriteTimeout.

@ParameterizedTest
@MethodSource("data")
public void testWriteTimeout(BatchOptions batchOptions) {
    Config config = createConfig();
    config.useSingleServer().setRetryInterval(700).setTimeout(1500);
    RedissonClient redisson = Redisson.create(config);
    RBatch batch = redisson.createBatch(batchOptions);
    RMapCacheAsync<String, String> map = batch.getMapCache("test");
    int total = 10000;
    for (int i = 0; i < total; i++) {
        RFuture<String> f = map.putAsync("" + i, "" + i, 5, TimeUnit.MINUTES);
        if (batchOptions.getExecutionMode() == ExecutionMode.REDIS_WRITE_ATOMIC) {
            ((BatchPromise) f.toCompletableFuture()).getSentPromise().join();
        }
    }
    long s = System.currentTimeMillis();
    batch.execute();
    long executionTime = System.currentTimeMillis() - s;
    if (batchOptions.getExecutionMode() == ExecutionMode.IN_MEMORY) {
        assertThat(executionTime).isLessThan(1000);
    } else {
        assertThat(executionTime).isLessThan(300);
    }
    assertThat(redisson.getMapCache("test").size()).isEqualTo(total);
    redisson.shutdown();
}
Also used : Config(org.redisson.config.Config) RandomString(net.bytebuddy.utility.RandomString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 73 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project redisson by redisson.

the class RedissonBatchTest method testSlotMigrationInCluster.

@ParameterizedTest
@MethodSource("data")
public void testSlotMigrationInCluster(BatchOptions batchOptions) throws Exception {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slot1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slot2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slot3 = new RedisRunner().randomPort().randomDir().nosave();
    ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slot1).addNode(master2, slot2).addNode(master3, slot3);
    ClusterRunner.ClusterProcesses process = clusterRunner.run();
    Config config = new Config();
    config.useClusterServers().setScanInterval(1000).setSubscriptionMode(SubscriptionMode.MASTER).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    RedisClientConfig cfg = new RedisClientConfig();
    cfg.setAddress(process.getNodes().iterator().next().getRedisServerAddressAndPort());
    RedisClient c = RedisClient.create(cfg);
    RedisConnection cc = c.connect();
    List<ClusterNodeInfo> mastersList = cc.sync(RedisCommands.CLUSTER_NODES);
    mastersList = mastersList.stream().filter(i -> i.containsFlag(ClusterNodeInfo.Flag.MASTER)).collect(Collectors.toList());
    c.shutdown();
    ClusterNodeInfo destination = mastersList.stream().filter(i -> i.getSlotRanges().iterator().next().getStartSlot() != 10922).findAny().get();
    ClusterNodeInfo source = mastersList.stream().filter(i -> i.getSlotRanges().iterator().next().getStartSlot() == 10922).findAny().get();
    RedisClientConfig sourceCfg = new RedisClientConfig();
    sourceCfg.setAddress(source.getAddress());
    RedisClient sourceClient = RedisClient.create(sourceCfg);
    RedisConnection sourceConnection = sourceClient.connect();
    RedisClientConfig destinationCfg = new RedisClientConfig();
    destinationCfg.setAddress(destination.getAddress());
    RedisClient destinationClient = RedisClient.create(destinationCfg);
    RedisConnection destinationConnection = destinationClient.connect();
    String lockName = "test{kaO}";
    RBatch batch = redisson.createBatch(batchOptions);
    List<RFuture<Boolean>> futures = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        RFuture<Boolean> f = batch.getMap(lockName).fastPutAsync("" + i, i);
        futures.add(f);
    }
    destinationConnection.sync(RedisCommands.CLUSTER_SETSLOT, source.getSlotRanges().iterator().next().getStartSlot(), "IMPORTING", source.getNodeId());
    sourceConnection.sync(RedisCommands.CLUSTER_SETSLOT, source.getSlotRanges().iterator().next().getStartSlot(), "MIGRATING", destination.getNodeId());
    List<String> keys = sourceConnection.sync(RedisCommands.CLUSTER_GETKEYSINSLOT, source.getSlotRanges().iterator().next().getStartSlot(), 100);
    List<Object> params = new ArrayList<Object>();
    params.add(destination.getAddress().getHost());
    params.add(destination.getAddress().getPort());
    params.add("");
    params.add(0);
    params.add(2000);
    params.add("KEYS");
    params.addAll(keys);
    sourceConnection.async(RedisCommands.MIGRATE, params.toArray());
    for (ClusterNodeInfo node : mastersList) {
        RedisClientConfig cc1 = new RedisClientConfig();
        cc1.setAddress(node.getAddress());
        RedisClient ccc = RedisClient.create(cc1);
        RedisConnection connection = ccc.connect();
        connection.sync(RedisCommands.CLUSTER_SETSLOT, source.getSlotRanges().iterator().next().getStartSlot(), "NODE", destination.getNodeId());
        ccc.shutdownAsync();
    }
    Thread.sleep(2000);
    batch.execute();
    futures.forEach(f -> {
        try {
            f.toCompletableFuture().get(1, TimeUnit.MILLISECONDS);
        } catch (TimeoutException e) {
            org.junit.jupiter.api.Assertions.fail(e);
        } catch (ExecutionException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    });
    sourceClient.shutdown();
    destinationClient.shutdown();
    redisson.shutdown();
    process.shutdown();
}
Also used : ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) Config(org.redisson.config.Config) RandomString(net.bytebuddy.utility.RandomString) ClusterNodeInfo(org.redisson.cluster.ClusterNodeInfo) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 74 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project redisson by redisson.

the class RedissonBatchTest method testAtomicSyncSlaves.

@ParameterizedTest
@MethodSource("data")
public void testAtomicSyncSlaves(BatchOptions batchOptions) throws FailedToStartRedisException, IOException, InterruptedException {
    RedisRunner master1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner master3 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave1 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave2 = new RedisRunner().randomPort().randomDir().nosave();
    RedisRunner slave3 = new RedisRunner().randomPort().randomDir().nosave();
    ClusterRunner clusterRunner = new ClusterRunner().addNode(master1, slave1).addNode(master2, slave2).addNode(master3, slave3);
    ClusterProcesses process = clusterRunner.run();
    Config config = new Config();
    config.useClusterServers().setTimeout(123000).addNodeAddress(process.getNodes().stream().findAny().get().getRedisServerAddressAndPort());
    RedissonClient redisson = Redisson.create(config);
    batchOptions.executionMode(ExecutionMode.IN_MEMORY_ATOMIC).syncSlaves(1, 1, TimeUnit.SECONDS);
    RBatch batch = redisson.createBatch(batchOptions);
    for (int i = 0; i < 10; i++) {
        batch.getAtomicLong("{test}" + i).addAndGetAsync(i);
    }
    BatchResult<?> result = batch.execute();
    assertThat(result.getSyncedSlaves()).isEqualTo(1);
    int i = 0;
    for (Object res : result.getResponses()) {
        assertThat((Long) res).isEqualTo(i++);
    }
    process.shutdown();
    redisson.shutdown();
}
Also used : ClusterProcesses(org.redisson.ClusterRunner.ClusterProcesses) Config(org.redisson.config.Config) AtomicLong(java.util.concurrent.atomic.AtomicLong) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 75 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project redisson by redisson.

the class RedissonLockHeavyTest method tryLockUnlockRLock.

@ParameterizedTest
@MethodSource("mapClasses")
public void tryLockUnlockRLock(int threads, int loops) throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(threads);
    for (int i = 0; i < threads; i++) {
        Runnable worker = new Runnable() {

            @Override
            public void run() {
                for (int j = 0; j < loops; j++) {
                    RLock lock = redisson.getLock("RLOCK_" + j);
                    try {
                        if (lock.tryLock(ThreadLocalRandom.current().nextInt(10), TimeUnit.MILLISECONDS)) {
                            try {
                                RBucket<String> bucket = redisson.getBucket("RBUCKET_" + j);
                                bucket.set("TEST", 30, TimeUnit.SECONDS);
                                RSemaphore semaphore = redisson.getSemaphore("SEMAPHORE_" + j);
                                semaphore.release();
                                try {
                                    semaphore.acquire();
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            } finally {
                                lock.unlock();
                            }
                        }
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        };
        executor.execute(worker);
    }
    executor.shutdown();
    executor.awaitTermination(threads * loops, TimeUnit.SECONDS);
}
Also used : RSemaphore(org.redisson.api.RSemaphore) ExecutorService(java.util.concurrent.ExecutorService) RLock(org.redisson.api.RLock) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2045 MethodSource (org.junit.jupiter.params.provider.MethodSource)1116 EnumSource (org.junit.jupiter.params.provider.EnumSource)325 ValueSource (org.junit.jupiter.params.provider.ValueSource)302 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)181 Transaction (org.neo4j.graphdb.Transaction)117 CsvSource (org.junit.jupiter.params.provider.CsvSource)113 ArrayList (java.util.ArrayList)112 ByteBuffer (java.nio.ByteBuffer)81 List (java.util.List)81 Path (java.nio.file.Path)75 Test (org.junit.jupiter.api.Test)74 InterruptAfter (io.aeron.test.InterruptAfter)72 IOException (java.io.IOException)72 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)67 TimeUnit (java.util.concurrent.TimeUnit)65 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)62 CountDownLatch (java.util.concurrent.CountDownLatch)61 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)60 Stream (java.util.stream.Stream)59