Skip to content

Commit dc1fb3b

Browse files
authored
Circleci project setup (#53)
NPE Fix in Producer only mode
1 parent eb47156 commit dc1fb3b

7 files changed

Lines changed: 153 additions & 23 deletions

File tree

.circleci/config.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# Java Gradle CircleCI 2.0 configuration file
2+
#
3+
# Check https://circleci.com/docs/2.0/language-java/ for more details
4+
#
5+
version: 2.1
6+
executors:
7+
rqueue-executor:
8+
machine:
9+
image: ubuntu-1604:202007-01
10+
11+
working_directory: ~/repo
12+
13+
environment:
14+
# Customize the JVM maximum heap limit
15+
JVM_OPTS: -Xmx3200m
16+
TERM: dumb
17+
ORG_GRADLE_PROJECT_sonatypeUsername: xxx
18+
ORG_GRADLE_PROJECT_sonatypePassword: xxx
19+
USER_NAME: rqueue
20+
REDIS_RUNNING: "true"
21+
run:
22+
23+
24+
jobs:
25+
boot_2_1:
26+
executor: rqueue-executor
27+
environment:
28+
SPRING_BOOT_VERSION: 2.1.0.RELEASE
29+
SPRING_VERSION: 5.1.2.RELEASE
30+
SPRING_DATA_VERSION: 2.1.2.RELEASE
31+
MICROMETER_VERSION: 1.1.0
32+
33+
steps:
34+
- checkout
35+
36+
# Download and cache dependencies
37+
- restore_cache:
38+
keys:
39+
- v1-dependencies-{{ checksum "build.gradle" }}
40+
# fallback to using the latest cache if no exact match is found
41+
- v1-dependencies-
42+
43+
- run: gradle dependencies
44+
45+
- save_cache:
46+
paths:
47+
- ~/.gradle
48+
key: v1-dependencies-{{ checksum "build.gradle" }}
49+
- run:
50+
name: Install Dependencies
51+
command: |
52+
sudo add-apt-repository ppa:chris-lea/redis-server
53+
sudo apt-get update
54+
sudo apt-get -y install redis-server
55+
redis-cli --version
56+
- run:
57+
name: Setup Redis Cluster
58+
background: true
59+
command: |
60+
mkdir 9000 9001 9002 9003 9004 9005
61+
printf "port 9000 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9000/redis.conf
62+
printf "port 9001 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9001/redis.conf
63+
printf "port 9002 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9002/redis.conf
64+
printf "port 9003 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9003/redis.conf
65+
printf "port 9004 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9004/redis.conf
66+
printf "port 9005 \ncluster-enabled yes \ncluster-config-file nodes.conf \ncluster-node-timeout 5000 \nappendonly yes" >> 9005/redis.conf
67+
cd 9000 && redis-server ./redis.conf &
68+
cd 9001 && redis-server ./redis.conf &
69+
cd 9002 && redis-server ./redis.conf &
70+
cd 9003 && redis-server ./redis.conf &
71+
cd 9004 && redis-server ./redis.conf &
72+
cd 9005 && redis-server ./redis.conf &
73+
sleep 30
74+
redis-cli --cluster create 127.0.0.1:9000 127.0.0.1:9001 127.0.0.1:9002 127.0.0.1:9003 127.0.0.1:9004 127.0.0.1:9005 --cluster-replicas 1 --cluster-yes
75+
76+
- run: ./gradlew codeCoverageReport
77+
- run:
78+
name: Build Success
79+
when: on_success
80+
command: ./gradlew coveralls
81+
82+
boot_2_2:
83+
executor: rqueue-executor
84+
environment:
85+
SPRING_BOOT_VERSION: 2.2.0.RELEASE
86+
SPRING_VERSION: 5.2.0.RELEASE
87+
SPRING_DATA_VERSION: 2.2.0.RELEASE
88+
MICROMETER_VERSION: 1.3.2
89+
steps:
90+
- checkout
91+
92+
# Download and cache dependencies
93+
- restore_cache:
94+
keys:
95+
- v2-dependencies-{{ checksum "build.gradle" }}
96+
# fallback to using the latest cache if no exact match is found
97+
- v2-dependencies-
98+
99+
- run: gradle dependencies
100+
101+
- save_cache:
102+
paths:
103+
- ~/.gradle
104+
key: v2-dependencies-{{ checksum "build.gradle" }}
105+
106+
# run tests!
107+
- run: ./gradlew codeCoverageReport
108+
- run:
109+
name: Upload Code Coverage Data
110+
when: always #on_success
111+
command: ./gradlew coveralls
112+
113+
114+
workflows:
115+
main:
116+
jobs:
117+
- boot_2_1
118+
#- boot_2_2

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'jacoco'
33
id 'com.github.kt3k.coveralls' version '2.6.3'
44
id 'nebula.optional-base' version '5.0.2'
5+
id "com.adarshr.test-logger" version "2.1.1"
56
}
67
allprojects {
78
apply plugin: 'idea'
@@ -11,6 +12,7 @@ allprojects {
1112
apply plugin: 'signing'
1213
apply plugin: 'jacoco'
1314
apply plugin: 'nebula.optional-base'
15+
apply plugin: 'com.adarshr.test-logger'
1416

1517
sourceCompatibility = 1.8
1618
targetCompatibility = 1.8

rqueue-core/src/main/java/com/github/sonus21/rqueue/listener/RqueueMessageListenerContainer.java

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -242,29 +242,29 @@ public void stop(Runnable callback) {
242242
public void afterPropertiesSet() throws Exception {
243243
synchronized (lifecycleMgr) {
244244
if (RqueueMode.PRODUCER.equals(rqueueConfig.getMode())) {
245-
log.info("Producer only mode running.");
246-
return;
247-
}
248-
EndpointRegistry.delete();
249-
for (MappingInformation mappingInformation :
250-
rqueueMessageHandler.getHandlerMethods().keySet()) {
251-
for (String queue : mappingInformation.getQueueNames()) {
252-
for (QueueDetail queueDetail : getQueueDetail(queue, mappingInformation)) {
253-
EndpointRegistry.register(queueDetail);
245+
log.info("Producer mode nothing to do...");
246+
} else {
247+
EndpointRegistry.delete();
248+
for (MappingInformation mappingInformation :
249+
rqueueMessageHandler.getHandlerMethods().keySet()) {
250+
for (String queue : mappingInformation.getQueueNames()) {
251+
for (QueueDetail queueDetail : getQueueDetail(queue, mappingInformation)) {
252+
EndpointRegistry.register(queueDetail);
253+
}
254254
}
255255
}
256+
List<QueueDetail> queueDetails = EndpointRegistry.getActiveQueueDetails();
257+
if (queueDetails.isEmpty()) {
258+
return;
259+
}
260+
if (taskExecutor == null) {
261+
defaultTaskExecutor = true;
262+
taskExecutor = createDefaultTaskExecutor(queueDetails);
263+
} else {
264+
initializeThreadMap(queueDetails, taskExecutor, false, queueDetails.size());
265+
}
266+
initializeRunningQueueState();
256267
}
257-
List<QueueDetail> queueDetails = EndpointRegistry.getActiveQueueDetails();
258-
if (queueDetails.isEmpty()) {
259-
return;
260-
}
261-
if (taskExecutor == null) {
262-
defaultTaskExecutor = true;
263-
taskExecutor = createDefaultTaskExecutor(queueDetails);
264-
} else {
265-
initializeThreadMap(queueDetails, taskExecutor, false, queueDetails.size());
266-
}
267-
initializeRunningQueueState();
268268
lifecycleMgr.notifyAll();
269269
}
270270
}
@@ -413,6 +413,10 @@ private void createPostProcessingHandler() {
413413
}
414414

415415
protected void doStart() {
416+
if (RqueueMode.PRODUCER.equals(rqueueConfig.getMode())) {
417+
log.info("Producer mode nothing to do...");
418+
return;
419+
}
416420
Map<String, List<QueueDetail>> queueGroupToDetails = new HashMap<>();
417421
for (QueueDetail queueDetail : EndpointRegistry.getActiveQueueDetails()) {
418422
int prioritySize = queueDetail.getPriority().size();
@@ -512,6 +516,10 @@ public void stop() {
512516
}
513517

514518
protected void doStop() {
519+
if (RqueueMode.PRODUCER.equals(rqueueConfig.getMode())) {
520+
log.info("Producer mode nothing to do...");
521+
return;
522+
}
515523
for (Map.Entry<String, Boolean> runningStateByQueue : queueRunningState.entrySet()) {
516524
if (Boolean.TRUE.equals(runningStateByQueue.getValue())) {
517525
stopQueue(runningStateByQueue.getKey());

rqueue-spring-boot-starter/src/test/java/com/github/sonus21/rqueue/spring/boot/tests/integration/BootDelayedChannelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
})
4343
@SpringBootTest
4444
@Slf4j
45-
@DisabledIfEnvironmentVariable(named = "CI_ENV", matches = "true")
45+
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
4646
public class BootDelayedChannelTest extends MessageChannelTests {
4747

4848
@Test

rqueue-spring-boot-starter/src/test/java/com/github/sonus21/rqueue/spring/boot/tests/integration/BootMetricsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
public class BootMetricsTest extends MetricTest {
4545

4646
@Test
47-
@DisabledIfEnvironmentVariable(named = "CI_ENV", matches = "true")
47+
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
4848
public void delayedQueueStatus() throws TimedOutException {
4949
this.verifyDelayedQueueStatus();
5050
}

rqueue-spring-boot-starter/src/test/java/com/github/sonus21/rqueue/spring/boot/tests/integration/BootProcessingChannelTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
})
4343
@SpringBootTest
4444
@Slf4j
45-
@DisabledIfEnvironmentVariable(named = "CI_ENV", matches = "true")
45+
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
4646
public class BootProcessingChannelTest extends MessageChannelTests {
4747
@Test
4848
public void publishMessageIsTriggeredOnMessageRemoval() throws TimedOutException {

rqueue-spring-boot-starter/src/test/java/com/github/sonus21/rqueue/spring/boot/tests/integration/ProducerOnlyTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.github.sonus21.rqueue.utils.PriorityUtils;
2626
import lombok.extern.slf4j.Slf4j;
2727
import org.junit.jupiter.api.Test;
28+
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable;
2829
import org.junit.jupiter.api.extension.ExtendWith;
2930
import org.springframework.boot.test.context.SpringBootTest;
3031
import org.springframework.test.context.ContextConfiguration;
@@ -33,6 +34,7 @@
3334
@ContextConfiguration(classes = ProducerOnlyApplication.class)
3435
@SpringBootTest
3536
@Slf4j
37+
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
3638
public class ProducerOnlyTest extends BasicListenerTest {
3739
@Test
3840
public void testQueueCount() {

0 commit comments

Comments
 (0)