Fixed - RObject.migrate method.

pull/1423/head
Nikita 7 years ago
parent dece260e2b
commit 601ba4d16f

@ -94,15 +94,15 @@ public abstract class RedissonObject implements RObject {
} }
@Override @Override
public void migrate(String host, int port, int database) { public void migrate(String host, int port, int database, long timeout) {
get(migrateAsync(host, port, database)); get(migrateAsync(host, port, database, timeout));
} }
@Override @Override
public RFuture<Void> migrateAsync(String host, int port, int database) { public RFuture<Void> migrateAsync(String host, int port, int database, long timeout) {
return commandExecutor.writeAsync(getName(), RedisCommands.MIGRATE, host, port, getName(), database); return commandExecutor.writeAsync(getName(), RedisCommands.MIGRATE, host, port, getName(), database, timeout);
} }
@Override @Override
public boolean move(int database) { public boolean move(int database) {
return get(moveAsync(database)); return get(moveAsync(database));

@ -38,8 +38,9 @@ public interface RObject extends RObjectAsync {
* @param host - destination host * @param host - destination host
* @param port - destination port * @param port - destination port
* @param database - destination database * @param database - destination database
* @param timeout - maximum idle time in any moment of the communication with the destination instance in milliseconds
*/ */
void migrate(String host, int port, int database); void migrate(String host, int port, int database, long timeout);
/** /**
* Move object to another database * Move object to another database

@ -37,9 +37,10 @@ public interface RObjectAsync {
* @param host - destination host * @param host - destination host
* @param port - destination port * @param port - destination port
* @param database - destination database * @param database - destination database
* @param timeout - maximum idle time in any moment of the communication with the destination instance in milliseconds
* @return void * @return void
*/ */
RFuture<Void> migrateAsync(String host, int port, int database); RFuture<Void> migrateAsync(String host, int port, int database, long timeout);
/** /**
* Move object to another database in async mode * Move object to another database in async mode

@ -2,13 +2,18 @@ package org.redisson;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.redisson.RedisRunner.FailedToStartRedisException;
import org.redisson.RedisRunner.RedisProcess;
import org.redisson.api.RBucket; import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
public class RedissonBucketTest extends BaseTest { public class RedissonBucketTest extends BaseTest {
@ -112,6 +117,31 @@ public class RedissonBucketTest extends BaseTest {
Assert.assertEquals("someValue", newBucket.get()); Assert.assertEquals("someValue", newBucket.get());
Assert.assertFalse(newBucket.renamenx("test2")); Assert.assertFalse(newBucket.renamenx("test2"));
} }
@Test
public void testMigrate() throws FailedToStartRedisException, IOException, InterruptedException {
RedisProcess runner = new RedisRunner()
.appendonly(true)
.randomDir()
.randomPort()
.run();
RBucket<String> bucket = redisson.getBucket("test");
bucket.set("someValue");
bucket.migrate(runner.getRedisServerBindAddress(), runner.getRedisServerPort(), 0, 5000);
Config config = new Config();
config.useSingleServer().setAddress(runner.getRedisServerAddressAndPort());
RedissonClient r = Redisson.create(config);
RBucket<String> bucket2 = r.getBucket("test");
assertThat(bucket2.get()).isEqualTo("someValue");
assertThat(bucket.isExists()).isFalse();
runner.stop();
}
@Test @Test
public void testRename() { public void testRename() {

Loading…
Cancel
Save