-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add testcase for Spring Boot Starter
- Loading branch information
Showing
20 changed files
with
758 additions
and
1 deletion.
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
58 changes: 58 additions & 0 deletions
58
...test/java/org/apache/shardingsphere/elasticjob/reg/boot/RegistryCenterSpringBootTest.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,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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 org.apache.shardingsphere.elasticjob.reg.boot; | ||
|
||
import org.apache.shardingsphere.elasticjob.reg.boot.fixture.EmbedTestingServer; | ||
import org.apache.shardingsphere.elasticjob.reg.zookeeper.ZookeeperRegistryCenter; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
@SpringBootTest | ||
@SpringBootApplication | ||
@ActiveProfiles("elasticjob") | ||
public class RegistryCenterSpringBootTest extends AbstractJUnit4SpringContextTests { | ||
|
||
@BeforeClass | ||
public static void init() { | ||
EmbedTestingServer.start(); | ||
} | ||
|
||
@Test | ||
public void testZookeeperProperties() { | ||
assertNotNull(applicationContext); | ||
ZookeeperProperties zookeeperProperties = applicationContext.getBean(ZookeeperProperties.class); | ||
assertEquals(EmbedTestingServer.getConnectionString(), zookeeperProperties.getServerLists()); | ||
assertEquals("elasticjob-registry-center-spring-boot-starter", zookeeperProperties.getNamespace()); | ||
} | ||
|
||
@Test | ||
public void testRegistryCenterCreation() { | ||
assertNotNull(applicationContext); | ||
ZookeeperRegistryCenter zookeeperRegistryCenter = applicationContext.getBean(ZookeeperRegistryCenter.class); | ||
assertNotNull(zookeeperRegistryCenter); | ||
zookeeperRegistryCenter.persist("/foo", "bar"); | ||
assertEquals("bar", zookeeperRegistryCenter.get("/foo")); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
...c/test/java/org/apache/shardingsphere/elasticjob/reg/boot/fixture/EmbedTestingServer.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,69 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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 org.apache.shardingsphere.elasticjob.reg.boot.fixture; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.curator.test.TestingServer; | ||
import org.apache.shardingsphere.elasticjob.reg.exception.RegExceptionHandler; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class EmbedTestingServer { | ||
|
||
private static final int PORT = 16181; | ||
|
||
private static volatile TestingServer testingServer; | ||
|
||
/** | ||
* Get the connection string. | ||
* | ||
* @return connection string | ||
*/ | ||
public static String getConnectionString() { | ||
return "localhost:" + PORT; | ||
} | ||
|
||
/** | ||
* Start the server. | ||
*/ | ||
public static void start() { | ||
if (null != testingServer) { | ||
return; | ||
} | ||
try { | ||
testingServer = new TestingServer(PORT, new File(String.format("target/test_zk_data/%s/", System.nanoTime()))); | ||
// CHECKSTYLE:OFF | ||
} catch (final Exception ex) { | ||
// CHECKSTYLE:ON | ||
RegExceptionHandler.handleException(ex); | ||
} finally { | ||
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | ||
try { | ||
Thread.sleep(1000); | ||
testingServer.close(); | ||
} catch (final IOException | InterruptedException ex) { | ||
RegExceptionHandler.handleException(ex); | ||
} | ||
})); | ||
} | ||
} | ||
} | ||
|
21 changes: 21 additions & 0 deletions
21
...sticjob-registry-center-spring-boot-starter/src/test/resources/application-elasticjob.yml
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,21 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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 | ||
# | ||
# http://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. | ||
# | ||
|
||
elasticjob: | ||
regCenter: | ||
serverLists: localhost:16181 | ||
namespace: elasticjob-registry-center-spring-boot-starter |
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
56 changes: 56 additions & 0 deletions
56
...org/apache/shardingsphere/elasticjob/tracing/boot/TracingConfigurationSpringBootTest.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,56 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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 org.apache.shardingsphere.elasticjob.tracing.boot; | ||
|
||
import org.apache.shardingsphere.elasticjob.tracing.api.TracingConfiguration; | ||
import org.apache.shardingsphere.elasticjob.tracing.boot.fixture.EmbedTestingServer; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; | ||
|
||
import javax.sql.DataSource; | ||
import java.sql.SQLException; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
@SpringBootTest | ||
@SpringBootApplication | ||
@ActiveProfiles("elasticjob") | ||
public class TracingConfigurationSpringBootTest extends AbstractJUnit4SpringContextTests { | ||
|
||
@BeforeClass | ||
public static void setUp() { | ||
EmbedTestingServer.start(); | ||
} | ||
|
||
@Test | ||
public void testTracingConfigurationCreation() throws SQLException { | ||
assertNotNull(applicationContext); | ||
TracingConfiguration tracingConfiguration = applicationContext.getBean(TracingConfiguration.class); | ||
assertNotNull(tracingConfiguration); | ||
assertEquals("RDB", tracingConfiguration.getType()); | ||
assertTrue(tracingConfiguration.getStorage() instanceof DataSource); | ||
DataSource dataSource = (DataSource) tracingConfiguration.getStorage(); | ||
assertNotNull(dataSource.getConnection()); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
...st/java/org/apache/shardingsphere/elasticjob/tracing/boot/fixture/EmbedTestingServer.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,68 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 | ||
* | ||
* http://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 org.apache.shardingsphere.elasticjob.tracing.boot.fixture; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.NoArgsConstructor; | ||
import org.apache.curator.test.TestingServer; | ||
import org.apache.shardingsphere.elasticjob.reg.exception.RegExceptionHandler; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
public final class EmbedTestingServer { | ||
|
||
private static final int PORT = 17181; | ||
|
||
private static volatile TestingServer testingServer; | ||
|
||
/** | ||
* Get the connection string. | ||
* | ||
* @return connection string | ||
*/ | ||
public static String getConnectionString() { | ||
return "localhost:" + PORT; | ||
} | ||
|
||
/** | ||
* Start the server. | ||
*/ | ||
public static void start() { | ||
if (null != testingServer) { | ||
return; | ||
} | ||
try { | ||
testingServer = new TestingServer(PORT, new File(String.format("target/test_zk_data/%s/", System.nanoTime()))); | ||
// CHECKSTYLE:OFF | ||
} catch (final Exception ex) { | ||
// CHECKSTYLE:ON | ||
RegExceptionHandler.handleException(ex); | ||
} finally { | ||
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | ||
try { | ||
Thread.sleep(1000); | ||
testingServer.close(); | ||
} catch (final IOException | InterruptedException ex) { | ||
RegExceptionHandler.handleException(ex); | ||
} | ||
})); | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...cing/elasticjob-tracing-spring-boot-starter/src/test/resources/application-elasticjob.yml
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,29 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You 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 | ||
# | ||
# http://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. | ||
# | ||
|
||
spring: | ||
datasource: | ||
url: jdbc:h2:mem:job_event_storage | ||
driver-class-name: org.h2.Driver | ||
username: sa | ||
password: | ||
elasticjob: | ||
reg-center: | ||
server-lists: localhost:17181 | ||
namespace: elasticjob-tracing-spring-boot-starter | ||
tracing: | ||
type: RDB |
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
Oops, something went wrong.