-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change RedisBackedJobService to use a connection pool (#439)
* Change job service connection to use a connection pool * Close connection * Remove isConnected condition * Add simple test to test that pool recovers broken connections * Catch JedisExceptions separately * Catch only JedisConnectionException
- Loading branch information
1 parent
fe520a9
commit 0a8987e
Showing
8 changed files
with
131 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
serving/src/test/java/feast/serving/service/RedisBackedJobServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* Copyright 2018-2020 The Feast Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package feast.serving.service; | ||
|
||
import java.io.IOException; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import redis.clients.jedis.JedisPool; | ||
import redis.clients.jedis.JedisPoolConfig; | ||
import redis.embedded.RedisServer; | ||
|
||
public class RedisBackedJobServiceTest { | ||
private static String REDIS_HOST = "localhost"; | ||
private static int REDIS_PORT = 51235; | ||
private RedisServer redis; | ||
|
||
@Before | ||
public void setUp() throws IOException { | ||
redis = new RedisServer(REDIS_PORT); | ||
redis.start(); | ||
} | ||
|
||
@After | ||
public void teardown() { | ||
redis.stop(); | ||
} | ||
|
||
@Test | ||
public void shouldRecoverIfRedisConnectionIsLost() { | ||
JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); | ||
jedisPoolConfig.setMaxTotal(1); | ||
jedisPoolConfig.setMaxWaitMillis(10); | ||
JedisPool jedisPool = new JedisPool(jedisPoolConfig, REDIS_HOST, REDIS_PORT); | ||
RedisBackedJobService jobService = new RedisBackedJobService(jedisPool); | ||
jobService.get("does not exist"); | ||
redis.stop(); | ||
try { | ||
jobService.get("does not exist"); | ||
} catch (Exception e) { | ||
// pass, this should fail, and return a broken connection to the pool | ||
} | ||
redis.start(); | ||
jobService.get("does not exist"); | ||
} | ||
} |