redis.embedded.RedisServer Java Examples

The following examples show how to use redis.embedded.RedisServer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyRotationExampleIT.java    From fernet-java8 with Apache License 2.0 7 votes vote down vote up
@Before
public void setUp() throws IOException {
    initMocks(this);
    final SecureRandom random = new SecureRandom();
    redisServer = new RedisServer();
    redisServer.start();

    pool = new JedisPool();
    repository = new RedisKeyRepository(pool);
    manager = new RedisKeyManager(random, pool, repository);
    manager.setMaxActiveKeys(3);

    clearData();
    manager.initialiseNewRepository();

    resource = new ProtectedResource(repository, random);
}
 
Example #2
Source File: RedisServerExtension.java    From incubator-tuweni with Apache License 2.0 6 votes vote down vote up
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
    throws ParameterResolutionException {
  if (redisServer == null) {
    String localhost = InetAddress.getLoopbackAddress().getHostAddress();

    redisServer = RedisServer
        .builder()
        .setting("bind " + localhost)
        .setting("maxmemory 128mb")
        .setting("maxmemory-policy allkeys-lru")
        .setting("appendonly no")
        .setting("save \"\"")
        .port(findFreePort())
        .build();
    Runtime.getRuntime().addShutdownHook(shutdownThread);
    redisServer.start();
  }
  return redisServer.ports().get(0);
}
 
Example #3
Source File: RedisRule.java    From spring-cloud-gateway with Apache License 2.0 6 votes vote down vote up
@Override
protected void before() {
	try {
		redisServer = RedisServer.builder().port(port).setting("maxmemory 16MB")
				.build();
		redisServer.start();
	}
	catch (final Exception e) {
		if (port == DEFAULT_REDIS_PORT && ignoreDefaultPortFailure) {
			log.info(
					"Unable to start embedded Redis on default port. Ignoring error. Assuming redis is already running.");
		}
		else {
			throw new RuntimeException(format(
					"Error while initializing the Redis server" + " on port %d",
					port), e);
		}
	}
}
 
Example #4
Source File: BaseTest.java    From quartz-redis-jobstore with Apache License 2.0 6 votes vote down vote up
@Before
public void setUpRedis() throws IOException, SchedulerConfigException {
    port = getPort();
    logger.debug("Attempting to start embedded Redis server on port " + port);
    redisServer = RedisServer.builder()
            .port(port)
            .build();
    redisServer.start();
    final short database = 1;
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setTestOnBorrow(true);
    jedisPool = new JedisPool(jedisPoolConfig, host, port, Protocol.DEFAULT_TIMEOUT, null, database);

    jobStore = new RedisJobStore();
    jobStore.setHost(host);
    jobStore.setLockTimeout(2000);
    jobStore.setPort(port);
    jobStore.setInstanceId("testJobStore1");
    jobStore.setDatabase(database);
    mockScheduleSignaler = mock(SchedulerSignaler.class);
    jobStore.initialize(null, mockScheduleSignaler);
    schema = new RedisJobStoreSchema();

    jedis = jedisPool.getResource();
    jedis.flushDB();
}
 
Example #5
Source File: EmbeddedRedis.java    From distributed-lock with MIT License 6 votes vote down vote up
@PostConstruct
public void start() throws IOException {
  // find free port
  final var serverSocket = new ServerSocket(0);
  final var port = serverSocket.getLocalPort();
  serverSocket.close();

  server = RedisServer.builder().setting("bind 127.0.0.1").port(port).build(); // bind to ignore windows firewall popup each time the server starts
  server.start();

  final var connectionFactory = new LettuceConnectionFactory(new RedisStandaloneConfiguration("localhost", port));
  connectionFactory.setDatabase(0);
  connectionFactory.afterPropertiesSet();

  // set the property so that RedisAutoConfiguration picks up the right port
  System.setProperty("spring.redis.port", String.valueOf(port));
}
 
Example #6
Source File: RedisAuthenticationIntegrationTest.java    From dyno with Apache License 2.0 6 votes vote down vote up
@Test
public void testDynoClient_noAuthSuccess() throws Exception {
    redisServer = new RedisServer(REDIS_PORT);
    redisServer.start();

    Host noAuthHost = new HostBuilder().setHostname("localhost").setPort(REDIS_PORT).setRack(REDIS_RACK).setStatus(Status.Up).createHost();
    TokenMapSupplierImpl tokenMapSupplier = new TokenMapSupplierImpl(noAuthHost);
    DynoJedisClient dynoClient = constructJedisClient(tokenMapSupplier,
            () -> Collections.singletonList(noAuthHost));

    String statusCodeReply = dynoClient.set("some-key", "some-value");
    Assert.assertEquals("OK", statusCodeReply);

    String value = dynoClient.get("some-key");
    Assert.assertEquals("some-value", value);
}
 
Example #7
Source File: RedisAuthenticationIntegrationTest.java    From dyno with Apache License 2.0 6 votes vote down vote up
@Test
public void testJedisConnFactory_noAuthSuccess() throws Exception {
    redisServer = new RedisServer(REDIS_PORT);
    redisServer.start();

    Host noAuthHost = new HostBuilder().setHostname("localhost").setPort(REDIS_PORT).setRack(REDIS_RACK).setStatus(Status.Up).createHost();

    JedisConnectionFactory conFactory =
            new JedisConnectionFactory(new DynoOPMonitor("some-application-name"), null);
    ConnectionPoolConfiguration cpConfig = new ConnectionPoolConfigurationImpl("some-name");
    CountingConnectionPoolMonitor poolMonitor = new CountingConnectionPoolMonitor();
    HostConnectionPool<Jedis> hostConnectionPool =
            new HostConnectionPoolImpl<>(noAuthHost, conFactory, cpConfig, poolMonitor);
    Connection<Jedis> connection = conFactory
            .createConnection(hostConnectionPool);

    connection.execPing();
}
 
Example #8
Source File: LocalRedisLockTest.java    From dyno with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws IOException {
    redisServer = new RedisServer(REDIS_PORT);
    redisServer.start();
    Assume.assumeFalse(System.getProperty("os.name").toLowerCase().startsWith("win"));
    host = new HostBuilder()
            .setHostname("localhost")
            .setIpAddress("127.0.0.1")
            .setDatastorePort(REDIS_PORT)
            .setPort(REDIS_PORT)
            .setRack(REDIS_RACK)
            .setStatus(Host.Status.Up)
            .createHost();

    tokenMapSupplier = new TokenMapSupplierImpl(host);
    dynoLockClient = constructDynoLockClient();
}
 
Example #9
Source File: RedisLockTest.java    From conductor with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    String testServerAddress = "redis://127.0.0.1:6371";
    redisServer = new RedisServer(6371);
    if (redisServer.isActive()) {
        redisServer.stop();
    }
    redisServer.start();

    RedisLockConfiguration redisLockConfiguration = new SystemPropertiesRedisLockConfiguration() {
        @Override
        public String getRedisServerAddress() {
            return testServerAddress;
        }
    };

    Config redissonConfig = new Config();
    redissonConfig.useSingleServer().setAddress(testServerAddress).setTimeout(10000);
    redisLock = new RedisLock((Redisson) Redisson.create(redissonConfig), redisLockConfiguration);

    // Create another instance of redisson for tests.
    config = new Config();
    config.useSingleServer().setAddress(testServerAddress).setTimeout(10000);
    redisson = Redisson.create(config);
}
 
Example #10
Source File: RedisServerExtension.java    From cava with Apache License 2.0 6 votes vote down vote up
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext)
    throws ParameterResolutionException {
  if (redisServer == null) {
    String localhost = InetAddress.getLoopbackAddress().getHostAddress();

    redisServer = RedisServer
        .builder()
        .setting("bind " + localhost)
        .setting("maxmemory 128mb")
        .setting("maxmemory-policy allkeys-lru")
        .setting("appendonly no")
        .setting("save \"\"")
        .port(findFreePort())
        .build();
    Runtime.getRuntime().addShutdownHook(shutdownThread);
    redisServer.start();
  }
  return redisServer.ports().get(0);
}
 
Example #11
Source File: EmailEmbeddedRedis.java    From spring-boot-email-tools with Apache License 2.0 5 votes vote down vote up
private RedisServer createRedisServer() {
    final RedisServerBuilder redisServerBuilder = RedisServer.builder()
            .port(redisPort)
            .setting("appendonly yes")
            .setting("appendfsync everysec");
    settings.stream().forEach(s -> redisServerBuilder.setting(s));

    final RedisServer redisServer = redisServerBuilder.build();
    return redisServer;
}
 
Example #12
Source File: UnitTestTokenMapAndHostSupplierImpl.java    From dyno with Apache License 2.0 5 votes vote down vote up
public UnitTestTokenMapAndHostSupplierImpl(int serverCount, String rack) throws IOException {
    int hostTokenStride = Integer.MAX_VALUE / serverCount;

    for (int i = 0; i < serverCount; i++) {
        int port = findFreePort();
        RedisServer redisServer = new RedisServer(port);
        redisServer.start();
        redisServers.add(Pair.of(redisServer, port));

        Host host = new HostBuilder().setHostname("localhost").setPort(port).setRack(rack).setStatus(Host.Status.Up).createHost();
        hostTokenMap.put(host, new HostToken((long) i * hostTokenStride, host));
    }
}
 
Example #13
Source File: EmailEmbeddedRedisContextTest.java    From spring-boot-email-tools with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldStopRedis() throws Exception {
    //Arrange
    final RedisServer redisServerMock = mock(ForTestRedisServer.class);
    ReflectionTestUtils.setField(emailEmbeddedRedis, REDIS_SERVER_FIELD_NAME, redisServerMock);
    when(redisServerMock.isActive()).thenReturn(false);

    //Act
    emailEmbeddedRedis.stopRedis();

    //Assert
    verify(redisServerMock).stop();
    assertions.assertThat(emailEmbeddedRedis.isActive()).isFalse();
}
 
Example #14
Source File: TestRedisSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  try {
    redisPort = RandomPortFinder.find();
    redisServer = new RedisServer(redisPort);
    redisServer.start();
    initTestData();
  } catch (IOException e) {
    Assert.fail(e.getMessage());
    if (null != redisServer) {
      redisServer.stop();
    }
  }
}
 
Example #15
Source File: RedissonConfigurationIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@BeforeClass
public static void setUp() throws IOException {

    // Take an available port
    ServerSocket s = new ServerSocket(0);
    port = s.getLocalPort();
    s.close();

    redisServer = new RedisServer(port);
    redisServer.start();
}
 
Example #16
Source File: RedisStoreTestEnvironment.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public void setup() {
  if (redisServer == null) {
    redisServer = RedisServer.builder().port(6379).setting("bind 127.0.0.1") // secure + prevents
        // popups on Windows
        .setting("maxmemory 512M").setting("timeout 30000").build();
    redisServer.start();
  }
}
 
Example #17
Source File: RedisScoredSetWrapperTest.java    From geowave with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() {
  server =
      RedisServer.builder().port(6379).setting("bind 127.0.0.1").setting(
          "maxmemory 512M").setting("timeout 30000").build();
  server.start();
  client = RedissonClientCache.getInstance().getClient("redis://127.0.0.1:6379");;
  resetTestSets();
}
 
Example #18
Source File: RedisMiniServer.java    From calcite with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setUp() {
  try {
    RedisServer redisServer = new RedisServer(PORT);
    redisServer.start();
    JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
    jedisPoolConfig.setMaxTotal(10);
    pool = new JedisPool(jedisPoolConfig, HOST, PORT);
    makeData();
    System.out.println("The redis server is started at host: " + HOST + " port: " + PORT);
  } catch (Exception e) {
    assertNotNull(e.getMessage());
  }
}
 
Example #19
Source File: EmbeddedRedis.java    From kork with Apache License 2.0 5 votes vote down vote up
private EmbeddedRedis(int port) throws IOException, URISyntaxException {
  this.connection = URI.create(String.format("redis://127.0.0.1:%d/0", port));
  this.redisServer =
      RedisServer.builder()
          .port(port)
          .setting("bind 127.0.0.1")
          .setting("appendonly no")
          .setting("save \"\"")
          .setting("databases 1")
          .build();
  this.redisServer.start();
}
 
Example #20
Source File: ITRedisDistributedMapCacheClientService.java    From nifi with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() throws IOException {
    this.redisPort = getAvailablePort();

    this.redisServer = new RedisServer(redisPort);
    redisServer.start();

    proc = new TestRedisProcessor();
    testRunner = TestRunners.newTestRunner(proc);
}
 
Example #21
Source File: EmbeddedRedisUtils.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public EmbeddedRedisUtils(String testId) {
    dbPath = Paths.get(testId + "/redis");
    String execFile = "redis-server-2.8.19";
    RedisExecProvider customProvider = RedisExecProvider
        .defaultProvider()
        .override(OS.UNIX, Architecture.x86_64, execFile);
    redisServer = RedisServer.builder()
        .redisExecProvider(customProvider)
        .port(6379)
        .slaveOf("localhost", 6378)
        .setting("daemonize no")
        .setting("appendonly no")
        .build();
}
 
Example #22
Source File: RedisConfigStoreTest.java    From vertx-config with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp(TestContext tc) throws IOException {
  vertx = Vertx.vertx();
  vertx.exceptionHandler(tc.exceptionHandler());

  redisServer = new RedisServer(6379);
  redisServer.start();

  redis = Redis.createClient(vertx, "redis://localhost:6379");
}
 
Example #23
Source File: RedisIOTest.java    From beam with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  port = NetworkTestHelper.getAvailableLocalPort();
  server = new RedisServer(port);
  server.start();
  client = RedisConnectionConfiguration.create(REDIS_HOST, port).connect();
}
 
Example #24
Source File: ScanStrategyIntegrationTest.java    From tutorials with MIT License 5 votes vote down vote up
@BeforeClass
public static void setUp() throws IOException {

    // Take an available port
    ServerSocket s = new ServerSocket(0);
    String ip = "127.0.0.1";
    port = s.getLocalPort();
    s.close();

    redisServer = new RedisServer(port);
}
 
Example #25
Source File: SpringRedisIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Override
public void setup(final ManagementClient managementClient, String containerId) throws Exception {
    int port = AvailablePortFinder.getNextAvailable(6379);
    AvailablePortFinder.storeServerData("redis-port", port);
    redisServer = RedisServer.builder()
        .port(port)
        .setting("maxmemory 128M")
        .build();
    redisServer.start();
}
 
Example #26
Source File: SecurityContextApplication.java    From spring-cloud-zuul-ratelimit with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void setUp() throws IOException {
    this.redisServer = new RedisServer(DEFAULT_PORT);
    if (available(DEFAULT_PORT)) {
        this.redisServer.start();
    }
}
 
Example #27
Source File: RedisBackendConfiguredInJsonTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@BeforeClass
static public void startRedis() throws Exception {
  System.out.println("Creating redis server on port: " + PORT);
  server = new RedisServer(PORT);
  System.out.println("Created embedded redis server on port " + PORT);
  server.start();
}
 
Example #28
Source File: RedisBackendTest.java    From vertx-service-discovery with Apache License 2.0 5 votes vote down vote up
@BeforeClass
static public void startRedis() throws Exception {
  System.out.println("Creating redis server on port: " + DEFAULT_PORT);
  server = new RedisServer(DEFAULT_PORT);
  System.out.println("Created embedded redis server on port " + DEFAULT_PORT);
  server.start();
}
 
Example #29
Source File: RedisConfig.java    From spring-cloud-zuul-ratelimit with Apache License 2.0 5 votes vote down vote up
@PostConstruct
public void setUp() throws IOException {
    this.redisServer = new RedisServer(DEFAULT_PORT);
    if (available(DEFAULT_PORT)) {
        this.redisServer.start();
    }
}
 
Example #30
Source File: BaseIntegrationTest.java    From quartz-redis-jobstore with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    port = getPort();
    redisServer = RedisServer.builder()
            .port(port)
            .build();
    redisServer.start();

    jedisPool = new JedisPool(HOST, port);


    scheduler = new StdSchedulerFactory(schedulerConfig(HOST, port)).getScheduler();
    scheduler.start();
}