下面列出了org.quartz.spi.SchedulerSignaler#redis.embedded.RedisServer 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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);
}
@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);
}
@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));
}
@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);
}
@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);
}
}
}
@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();
}
@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);
}
@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();
}
@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();
}
@Before
public void setUp() throws Exception {
int redisPort = NetUtils.getAvailablePort();
if (name.getMethodName().equals("testAuthRedis") || name.getMethodName().equals("testWrongAuthRedis")) {
String password = "123456";
this.redisServer = RedisServer.builder().port(redisPort).setting("requirepass " + password).build();
this.registryUrl = URL.valueOf("redis://username:"+password+"@localhost:"+redisPort+"?db.index=0");
} else {
this.redisServer = RedisServer.builder().port(redisPort).build();
this.registryUrl = URL.valueOf("redis://localhost:" + redisPort);
}
this.redisServer.start();
}
@Before
public void setUp() throws Exception {
int redisPort = NetUtils.getAvailablePort();
this.redisServer = new RedisServer(redisPort);
this.redisServer.start();
this.registryUrl = URL.valueOf("redis://localhost:" + redisPort);
redisRegistry = (RedisRegistry) new RedisRegistryFactory().createRegistry(registryUrl);
}
@Override
public void setUp(Blackhole blackhole) throws IOException {
super.setUp(blackhole);
int redisPort = getAvailablePort();
server = RedisServer.builder()
.setting("bind 127.0.0.1")
.port(redisPort)
.build();
server.start();
RedisClient client = RedisClient.create(RedisURI.create("localhost", redisPort));
connection = client.connect();
sync = connection.sync();
sync.set("foo", "bar");
}
@Before
@BeforeEach
public final void initRedis() throws IOException {
redisPort = getAvailablePort();
server = RedisServer.builder()
.setting("bind 127.0.0.1")
.port(redisPort)
.build();
server.start();
}
@BeforeClass
public static void beforeClass() throws Exception {
redisServer = new RedisServer();
TestUtil.retry(new Callable<Void>() {
@Override
public Void call() throws Exception {
redisServer.start();
return null;
}
}, 10);
}
@BeforeClass
public static void beforeClass() throws Exception {
redisServer = new RedisServer();
TestUtil.retry(new Callable<Void>() {
@Override
public Void call() throws Exception {
redisServer.start();
return null;
}
}, 10);
}
public static void main(final String[] args) throws Exception {
final RedisServer redisServer = new RedisServer();
TestUtil.retry(new Runnable() {
@Override
public void run() {
redisServer.start();
}
}, 10);
try {
final Config config = new Config();
config.useSingleServer().setAddress("redis://127.0.0.1:6379");
final RedissonClient redissonClient = Redisson.create(config);
try {
final RMap<String,String> map = redissonClient.getMap("map");
map.put("key", "value");
if (!"value".equals(map.get("key")))
throw new AssertionError("ERROR: failed to get key value");
}
finally {
redissonClient.shutdown();
}
}
finally {
redisServer.stop();
TestUtil.checkSpan(new ComponentSpanCount("java-redis", 2));
// RedisServer process doesn't exit on 'stop' therefore call System.exit
System.exit(0);
}
}
public static void main(final String[] args) throws Exception {
final RedisServer redisServer = new RedisServer();
TestUtil.retry(new Runnable() {
@Override
public void run() {
redisServer.start();
}
}, 10);
try (final Jedis jedis = new Jedis()) {
try {
if (!"OK".equals(jedis.set("key", "value")))
throw new AssertionError("ERROR: failed to set key/value");
if (!"value".equals(jedis.get("key")))
throw new AssertionError("ERROR: failed to get key value");
TestUtil.checkSpan(new ComponentSpanCount("java-redis", 2));
}
finally {
jedis.shutdown();
}
}
finally {
redisServer.stop();
// RedisServer process doesn't exit on 'stop' therefore call System.exit
System.exit(0);
}
}
/**
* Init.
*
* @throws IOException the io exception
*/
@PostConstruct
public void init() throws IOException {
logger.info("Load Auto Configuration : {}", this.getClass().getName());
logger.info("Enabled Dew Test");
redisServer = new RedisServer();
if (!redisServer.isActive()) {
try {
redisServer.start();
redisTemplate.getConnectionFactory().getConnection();
} catch (Exception e) {
logger.warn("Start embedded redis error.");
}
}
}
@Before
public void before() {
mockTracer.reset();
redisServer = RedisServer.builder().setting("bind 127.0.0.1").build();
redisServer.start();
}
@Before
public void before() {
mockTracer.reset();
redisServer = RedisServer.builder().setting("bind 127.0.0.1").build();
redisServer.start();
}
@Before
public void before() {
mockTracer.reset();
redisServer = RedisServer.builder().setting("bind 127.0.0.1").build();
redisServer.start();
}
@Before
public void before() {
mockTracer.reset();
redisServer = RedisServer.builder().build();
redisServer.start();
redisSentinel = RedisSentinel.builder().port(Protocol.DEFAULT_PORT + 1).build();
redisSentinel.start();
}
@Before
public void before() {
mockTracer.reset();
redisServer = RedisServer.builder().setting("bind 127.0.0.1").build();
redisServer.start();
}
@Before
public void before() throws Exception {
mockTracer.reset();
redisServer = RedisServer.builder().setting("bind 127.0.0.1").build();
redisServer.start();
}
@Before
public void before() {
mockTracer.reset();
redisServer = RedisServer.builder().build();
redisServer.start();
redisSentinel = RedisSentinel.builder().port(Protocol.DEFAULT_PORT + 1).build();
redisSentinel.start();
}
@Before
public void before() {
mockTracer.reset();
redisServer = RedisServer.builder().setting("bind 127.0.0.1").build();
redisServer.start();
}
@Before
public void before() throws Exception {
mockTracer.reset();
redisServer = RedisServer.builder().setting("bind 127.0.0.1").build();
redisServer.start();
}
@BeforeClass
public static void beforeClass() {
redisServer = RedisServer.builder().setting("bind 127.0.0.1").build();
redisServer.start();
Config config = new Config();
config.useSingleServer().setAddress("redis://127.0.0.1:6379");
client = new TracingRedissonClient(Redisson.create(config),
new TracingConfiguration.Builder(tracer).build());
}
@PostConstruct
void init() {
try {
redisServer = new RedisServer(6379);
redisServer.start();
} catch (Exception ex) {
System.out.println(ex);
}
}