Fix print logs for NamingTraceEvent.
This commit is contained in:
parent
6278e7eadb
commit
a2b997f6a7
@ -27,11 +27,11 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
*/
|
||||
@SuppressWarnings({"PMD.AbstractClassShouldStartWithAbstractNamingRule"})
|
||||
public abstract class Event implements Serializable {
|
||||
|
||||
|
||||
private static final long serialVersionUID = -3731383194964997493L;
|
||||
|
||||
|
||||
private static final AtomicLong SEQUENCE = new AtomicLong(0);
|
||||
|
||||
|
||||
private final long sequence = SEQUENCE.getAndIncrement();
|
||||
|
||||
/**
|
||||
@ -51,5 +51,15 @@ public abstract class Event implements Serializable {
|
||||
public String scope() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether is plugin event. If so, the event can be dropped when no publish and subscriber without any hint. Default
|
||||
* false
|
||||
*
|
||||
* @return {@code true} if is plugin event, otherwise {@code false}
|
||||
*/
|
||||
public boolean isPluginEvent() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -301,6 +301,9 @@ public class NotifyCenter {
|
||||
if (publisher != null) {
|
||||
return publisher.publish(event);
|
||||
}
|
||||
if (event.isPluginEvent()) {
|
||||
return true;
|
||||
}
|
||||
LOGGER.warn("There are no [{}] publishers for this event, please register", topic);
|
||||
return false;
|
||||
}
|
||||
|
@ -31,4 +31,9 @@ public class NamingTraceEvent extends TraceEvent {
|
||||
String serviceNamespace, String serviceGroup, String name) {
|
||||
super(eventType, eventTime, serviceNamespace, serviceGroup, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPluginEvent() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@ -92,7 +93,7 @@ public class NamingEventPublisherTest {
|
||||
}
|
||||
namingEventPublisher.addSubscriber(subscriber, TestEvent.class);
|
||||
namingEventPublisher.publish(testEvent);
|
||||
verify(subscriber).onEvent(testEvent);
|
||||
verify(subscriber, atLeastOnce()).onEvent(testEvent);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user