1818import org .junit .jupiter .api .Test ;
1919import org .junit .jupiter .api .TestInstance ;
2020import org .junit .jupiter .api .TestInstance .Lifecycle ;
21- import org .junit .jupiter .api .condition .EnabledOnOs ;
22- import org .junit .jupiter .api .condition .OS ;
2321import org .springframework .util .unit .DataSize ;
24- import org .testcontainers .junit .jupiter .Container ;
25- import org .testcontainers .junit .jupiter .Testcontainers ;
26-
27- import com .redis .testcontainers .RedisEnterpriseContainer ;
2822
2923import io .lettuce .core .RedisURI ;
3024import io .lettuce .core .cluster .RedisClusterClient ;
3125import io .lettuce .core .cluster .api .StatefulRedisClusterConnection ;
3226
33- @ Testcontainers
3427@ TestInstance (Lifecycle .PER_CLASS )
35- @ EnabledOnOs (value = OS .LINUX )
36- class AdminTests {
37-
38- private static final Logger log = Logger .getLogger (AdminTests .class .getName ());
28+ abstract class AbstractTestBase {
3929
40- @ Container
41- private static RedisEnterpriseContainer server = new RedisEnterpriseContainer (
42- RedisEnterpriseContainer .DEFAULT_IMAGE_NAME .withTag (RedisEnterpriseContainer .DEFAULT_TAG ));
30+ private static final Logger log = Logger .getLogger (AbstractTestBase .class .getName ());
4331
44- private static Admin admin ;
32+ protected Admin admin ;
4533
4634 @ BeforeAll
47- static void setupAdmin () throws ParseException , GeneralSecurityException , IOException {
48- admin = new Admin ();
49- admin .withUserName (RedisEnterpriseContainer .ADMIN_USERNAME )
50- .withPassword (RedisEnterpriseContainer .ADMIN_PASSWORD ).withHost (server .getHost ());
35+ void setupAdmin () throws ParseException , GeneralSecurityException , IOException {
36+ admin = admin ();
5137 }
5238
39+ protected abstract Admin admin ();
40+
5341 @ AfterAll
54- static void teardownAdmin () throws Exception {
42+ void teardownAdmin () throws Exception {
5543 admin .close ();
5644 }
5745
@@ -77,13 +65,12 @@ void createDatabase() throws ParseException, GeneralSecurityException, IOExcepti
7765 @ Test
7866 void createClusterDatabase () throws ParseException , GeneralSecurityException , IOException {
7967 String databaseName = "CreateClusterDBTest" ;
80- admin .createDatabase (Database .builder ().name (databaseName ).ossCluster (true )
81- .port (RedisEnterpriseContainer .DEFAULT_DATABASE_PORT ).build ());
68+ admin .createDatabase (Database .builder ().name (databaseName ).ossCluster (true ).port (12000 ).build ());
8269 List <Database > databases = admin .getDatabases ();
8370 Assertions .assertEquals (1 , databases .size ());
8471 Assertions .assertEquals (databaseName , databases .get (0 ).getName ());
8572 Database database = databases .get (0 );
86- RedisClusterClient client = RedisClusterClient .create (RedisURI .create (server .getHost (), database .getPort ()));
73+ RedisClusterClient client = RedisClusterClient .create (RedisURI .create (admin .getHost (), database .getPort ()));
8774 try (StatefulRedisClusterConnection <String , String > connection = client .connect ()) {
8875 Assertions .assertEquals ("PONG" , connection .sync ().ping ());
8976 }
0 commit comments