Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install early fix #2782

Merged
merged 6 commits into from
Oct 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package webapp.tier.service;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand Down Expand Up @@ -31,19 +32,21 @@ public class ActiveMqSubscribeService implements Runnable {
String topicname;

private final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
private final ExecutorService scheduler = Executors.newSingleThreadExecutor();
static boolean isEnableReceived = true;

private final ScheduledExecutorService scheduler = Executors
.newSingleThreadScheduledExecutor();
private static boolean isEnableReceived = true;

void onStart(@Observes StartupEvent ev) {
scheduler.submit(this);
scheduler.scheduleWithFixedDelay(this, 0L, 5L, TimeUnit.SECONDS);
logger.log(Level.INFO, "Subscribe is starting...");
}

void onStop(@Observes ShutdownEvent ev) {
stopReceived();
scheduler.shutdown();
logger.log(Level.INFO, "Subscribe is stopping...");
}

public static void stopReceived() {
ActiveMqSubscribeService.isEnableReceived = false;
}
Expand All @@ -57,7 +60,6 @@ public void run() {
amqdelconsumer.consume(consumer);
} catch (Exception e) {
logger.log(Level.SEVERE, "Subscribe Error.", e);
stopReceived();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ quarkus.log.console.color=true
quarkus.log.category."io.quarkus".level=INFO

# Opentracing
quarkus.jaeger.service-name=activemq-mysql-quarkus
quarkus.jaeger.service-name=consumer-activemq-quarkus
quarkus.jaeger.sampler-type=const
quarkus.jaeger.sampler-param=1
quarkus.jaeger.agent-host-port=jaeger-agent:6831
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package webapp.tier.service;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import javax.inject.Inject;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.Session;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.quarkus.artemis.test.ArtemisTestResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTest;
import webapp.tier.bean.MsgBean;
import webapp.tier.util.CreateId;
import webapp.tier.util.MsgUtils;

@QuarkusTest
@QuarkusTestResource(ArtemisTestResource.class)
class ActiveMqSubscribeServiceErrorTest {

@Inject
ConnectionFactory connectionFactory;

@ConfigProperty(name = "common.message")
String message;
@ConfigProperty(name = "activemq.split.key")
String splitkey;
@ConfigProperty(name = "activemq.topic.name")
String topicname;

private static final String respbody = "Test Response OK from Mock";

private static MockDeliverService mock = null;

@BeforeAll
static void init() {
mock = mock(MockDeliverService.class);
}

@BeforeEach
void setup() {
clearInvocations(mock);
}

@AfterEach
void tearDown() {
reset(mock);
}

@Test
void testSubscribeError() {
when(mock.random()).thenThrow(new RuntimeException("Rest response error"));
QuarkusMock.installMockForType(mock, MockDeliverService.class);

try {
MsgBean msgbean = new MsgBean(CreateId.createid(), message, "Publish");
String body = MsgUtils.createBody(msgbean, splitkey);
try (JMSContext context = connectionFactory
.createContext(Session.AUTO_ACKNOWLEDGE)) {
context.createProducer().send(context.createTopic(topicname),
context.createTextMessage(body));
}
Thread.sleep(1000);
assertThat(msgbean.getFullmsg(), not(containsString(respbody)));
verify(mock, atLeastOnce()).random();
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import javax.inject.Inject;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.Session;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import io.quarkus.artemis.test.ArtemisTestResource;
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusMock;
import io.quarkus.test.junit.QuarkusTest;
import webapp.tier.bean.MsgBean;
import webapp.tier.util.CreateId;
Expand All @@ -23,9 +28,6 @@
@QuarkusTestResource(ArtemisTestResource.class)
class ActiveMqSubscribeServiceTest {

@Inject
ActiveMqSubscribeService subsvc;

@Inject
ConnectionFactory connectionFactory;

Expand All @@ -36,10 +38,30 @@ class ActiveMqSubscribeServiceTest {
@ConfigProperty(name = "activemq.topic.name")
String topicname;

private static final String respbody = "message: Hello k8s-3tier-webapp with quarkus";
private static final String respbody = "Test Response OK from Mock";

private static MockDeliverService mock = null;

@BeforeAll
static void init() {
mock = mock(MockDeliverService.class);
}

@BeforeEach
void setup() {
clearInvocations(mock);
}

@AfterEach
void tearDown() {
reset(mock);
}

@Test
void testSubscribe() {
when(mock.random()).thenReturn(respbody);
QuarkusMock.installMockForType(mock, MockDeliverService.class);

try {
MsgBean msgbean = new MsgBean(CreateId.createid(), message, "Publish");
String body = MsgUtils.createBody(msgbean, splitkey);
Expand All @@ -49,7 +71,8 @@ void testSubscribe() {
context.createTextMessage(body));
}
Thread.sleep(1000);
assertThat(msgbean.getFullmsg(), containsString(respbody));
assertThat(msgbean.getFullmsg(), not(containsString(respbody)));
verify(mock, atLeastOnce()).random();
} catch (Exception e) {
e.printStackTrace();
fail();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package webapp.tier.service;

import java.util.logging.Level;
import java.util.logging.Logger;

import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
Expand All @@ -13,8 +16,11 @@
@Consumes(MediaType.APPLICATION_JSON)
public class MockDeliverService {

private final Logger logger = Logger.getLogger(this.getClass().getSimpleName());

@GET
public String random() {
logger.log(Level.INFO, "Received rest request form consumer");
return "Test";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ quarkus.log.category."com.hazelcast.client".level=WARN
quarkus.log.category."com.hazelcast.internal".level=WARN

# Opentracing
quarkus.jaeger.service-name=hazelcast-mysql-quarkus
quarkus.jaeger.service-name=consumer-hazelcast-quarkus
quarkus.jaeger.sampler-type=const
quarkus.jaeger.sampler-param=1
quarkus.jaeger.agent-host-port=jaeger-agent:6831
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ quarkus.package.type=native
kafka.bootstrap.servers=kafka:9092
%test.kafka.bootstrap.servers=localhost:9092
mp.messaging.incoming.message.connector=smallrye-kafka
mp.messaging.incoming.message.auto.offset.reset=earliest
mp.messaging.incoming.message.auto.offset.reset=latest
mp.messaging.incoming.message.group.id=recycle

quarkus.kafka.devservices.topic-partitions.message=2
Expand All @@ -24,3 +24,9 @@ quarkus.kafka.devservices.topic-partitions.message=2
random/mp-rest/url=http://randompublish-quarkus:8080
%test.random/mp-rest/url=http://localhost:8081
random/mp-rest/scope=javax.inject.Singleton

# Opentracing
quarkus.jaeger.service-name=consumer-kafka-quarkus
quarkus.jaeger.sampler-type=const
quarkus.jaeger.sampler-param=1
quarkus.jaeger.agent-host-port=jaeger-agent:6831
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,9 @@ common.message=Hello k8s-3tier-webapp with quarkus
quarkus.rabbitmq.devservices.port=5672
mp.messaging.incoming.message.connector=smallrye-rabbitmq
mp.messaging.incoming.message.queue.name=queuemsg
#mp.messaging.incoming.message.exchange.name=exchangemsg
mp.messaging.incoming.message.routing-keys=routingkeymsg
rabbitmq.split.key=,

# Rabbitmq Client Test
#mp.messaging.outgoing.message.connector=smallrye-rabbitmq
#mp.messaging.outgoing.message.queue.name=queuemsg
#mp.messaging.outgoing.message.exchange.name=exchangemsg
#mp.messaging.outgoing.message.routing-keys=routingkeymsg


# rest client
random/mp-rest/url=http://randompublish-quarkus:8080
%test.random/mp-rest/url=http://localhost:8081
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ quarkus.log.console.color=true
quarkus.log.category."io.quarkus".level=INFO

# Opentracing
quarkus.jaeger.service-name=redis-mysql-quarkus
quarkus.jaeger.service-name=consumer-redis-quarkus
quarkus.jaeger.sampler-type=const
quarkus.jaeger.sampler-param=1
quarkus.jaeger.agent-host-port=jaeger-agent:6831
Expand Down