use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.
the class AbstractTestLogSubject method performLog.
protected List<Object> performLog(boolean statusUpdatesEnabled) {
if (_subject == null) {
throw new NullPointerException("LogSubject has not been set");
}
UnitTestMessageLogger logger = new UnitTestMessageLogger(statusUpdatesEnabled);
EventLogger eventLogger = new EventLogger(logger);
eventLogger.message(_subject, new LogMessage() {
@Override
public String toString() {
return "<Log Message>";
}
@Override
public String getLogHierarchy() {
return "test.hierarchy";
}
});
return logger.getLogMessages();
}
use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.
the class BrokerTestHelper method createBrokerMock.
private static Broker<?> createBrokerMock(AccessControl accessControl) {
ConfiguredObjectFactory objectFactory = new ConfiguredObjectFactoryImpl(BrokerModel.getInstance());
EventLogger eventLogger = new EventLogger();
SystemConfig systemConfig = mock(SystemConfig.class);
when(systemConfig.getEventLogger()).thenReturn(eventLogger);
when(systemConfig.getObjectFactory()).thenReturn(objectFactory);
when(systemConfig.getModel()).thenReturn(objectFactory.getModel());
when(systemConfig.getCategoryClass()).thenReturn(SystemConfig.class);
when(systemConfig.getTypeClass()).thenReturn(SystemConfig.class);
Broker broker = mockWithSystemPrincipalAndAccessControl(Broker.class, SYSTEM_PRINCIPAL, accessControl);
when(broker.getId()).thenReturn(UUID.randomUUID());
when(broker.getObjectFactory()).thenReturn(objectFactory);
when(broker.getModel()).thenReturn(objectFactory.getModel());
when(broker.getModelVersion()).thenReturn(BrokerModel.MODEL_VERSION);
when(broker.getEventLogger()).thenReturn(eventLogger);
when(broker.getCategoryClass()).thenReturn(Broker.class);
when(broker.getTypeClass()).thenReturn(Broker.class);
when(broker.getParent()).thenReturn(systemConfig);
when(broker.getContextValue(eq(Long.class), eq(Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT))).thenReturn(0l);
when(broker.getFlowToDiskThreshold()).thenReturn(Long.MAX_VALUE);
when(broker.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
when(systemConfig.getTaskExecutor()).thenReturn(TASK_EXECUTOR);
when(broker.getChildExecutor()).thenReturn(TASK_EXECUTOR);
when(systemConfig.getChildExecutor()).thenReturn(TASK_EXECUTOR);
when(systemConfig.createPreferenceStore()).thenReturn(mock(PreferenceStore.class));
when(systemConfig.getChildren(Broker.class)).thenReturn(Collections.singleton(broker));
return broker;
}
use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.
the class BrokerImplTest method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
_taskExecutor = new TaskExecutorImpl();
_taskExecutor.start();
_preferenceStore = mock(PreferenceStore.class);
_systemConfig = BrokerTestHelper.mockWithSystemPrincipal(SystemConfig.class, mock(Principal.class));
when(_systemConfig.getTaskExecutor()).thenReturn(_taskExecutor);
when(_systemConfig.getChildExecutor()).thenReturn(_taskExecutor);
when(_systemConfig.getModel()).thenReturn(BrokerModel.getInstance());
when(_systemConfig.getEventLogger()).thenReturn(new EventLogger());
when(_systemConfig.getCategoryClass()).thenReturn(SystemConfig.class);
when(_systemConfig.createPreferenceStore()).thenReturn(_preferenceStore);
}
use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.
the class AmqpPortImplTest method testConnectionCounting.
public void testConnectionCounting() {
Map<String, Object> attributes = new HashMap<>();
attributes.put(AmqpPort.PORT, 0);
attributes.put(AmqpPort.NAME, getTestName());
attributes.put(AmqpPort.AUTHENTICATION_PROVIDER, AUTHENTICATION_PROVIDER_NAME);
attributes.put(AmqpPort.MAX_OPEN_CONNECTIONS, 10);
attributes.put(AmqpPort.CONTEXT, Collections.singletonMap(AmqpPort.OPEN_CONNECTIONS_WARN_PERCENT, "80"));
_port = new AmqpPortImpl(attributes, _broker);
_port.create();
EventLogger mockLogger = mock(EventLogger.class);
when(_broker.getEventLogger()).thenReturn(mockLogger);
for (int i = 0; i < 8; i++) {
assertTrue(_port.canAcceptNewConnection(new InetSocketAddress("example.org", 0)));
_port.incrementConnectionCount();
assertEquals(i + 1, _port.getConnectionCount());
verify(mockLogger, never()).message(any(LogSubject.class), any(LogMessage.class));
}
assertTrue(_port.canAcceptNewConnection(new InetSocketAddress("example.org", 0)));
_port.incrementConnectionCount();
assertEquals(9, _port.getConnectionCount());
verify(mockLogger, times(1)).message(any(LogSubject.class), any(LogMessage.class));
assertTrue(_port.canAcceptNewConnection(new InetSocketAddress("example.org", 0)));
_port.incrementConnectionCount();
assertEquals(10, _port.getConnectionCount());
verify(mockLogger, times(1)).message(any(LogSubject.class), any(LogMessage.class));
assertFalse(_port.canAcceptNewConnection(new InetSocketAddress("example.org", 0)));
}
use of org.apache.qpid.server.logging.EventLogger in project qpid-broker-j by apache.
the class SynchronousMessageStoreRecoverer method recover.
@Override
public ListenableFuture<Void> recover(QueueManagingVirtualHost<?> virtualHost) {
EventLogger eventLogger = virtualHost.getEventLogger();
MessageStore store = virtualHost.getMessageStore();
MessageStore.MessageStoreReader storeReader = store.newMessageStoreReader();
MessageStoreLogSubject logSubject = new MessageStoreLogSubject(virtualHost.getName(), store.getClass().getSimpleName());
Map<Queue<?>, Integer> queueRecoveries = new TreeMap<>();
Map<Long, ServerMessage<?>> recoveredMessages = new HashMap<>();
Map<Long, StoredMessage<?>> unusedMessages = new TreeMap<>();
Map<UUID, Integer> unknownQueuesWithMessages = new HashMap<>();
Map<Queue<?>, Integer> queuesWithUnknownMessages = new HashMap<>();
eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_START());
storeReader.visitMessages(new MessageVisitor(recoveredMessages, unusedMessages));
eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_START(null, false));
try {
storeReader.visitMessageInstances(new MessageInstanceVisitor(virtualHost, store, queueRecoveries, recoveredMessages, unusedMessages, unknownQueuesWithMessages, queuesWithUnknownMessages));
} finally {
if (!unknownQueuesWithMessages.isEmpty()) {
unknownQueuesWithMessages.forEach((queueId, count) -> {
LOGGER.info("Discarded {} entry(s) associated with queue id '{}' as a queue with this " + "id does not appear in the configuration.", count, queueId);
});
}
if (!queuesWithUnknownMessages.isEmpty()) {
queuesWithUnknownMessages.forEach((queue, count) -> {
LOGGER.info("Discarded {} entry(s) associated with queue '{}' as the referenced message " + "does not exist.", count, queue.getName());
});
}
}
for (Map.Entry<Queue<?>, Integer> entry : queueRecoveries.entrySet()) {
Queue<?> queue = entry.getKey();
Integer deliveredCount = entry.getValue();
eventLogger.message(logSubject, TransactionLogMessages.RECOVERED(deliveredCount, queue.getName()));
eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(queue.getName(), true));
queue.completeRecovery();
}
for (Queue<?> q : virtualHost.getChildren(Queue.class)) {
if (!queueRecoveries.containsKey(q)) {
q.completeRecovery();
}
}
storeReader.visitDistributedTransactions(new DistributedTransactionVisitor(virtualHost, eventLogger, logSubject, recoveredMessages, unusedMessages));
for (StoredMessage<?> m : unusedMessages.values()) {
LOGGER.debug("Message id '{}' is orphaned, removing", m.getMessageNumber());
m.remove();
}
if (unusedMessages.size() > 0) {
LOGGER.info("Discarded {} orphaned message(s).", unusedMessages.size());
}
eventLogger.message(logSubject, TransactionLogMessages.RECOVERY_COMPLETE(null, false));
eventLogger.message(logSubject, MessageStoreMessages.RECOVERED(recoveredMessages.size() - unusedMessages.size()));
eventLogger.message(logSubject, MessageStoreMessages.RECOVERY_COMPLETE());
return Futures.immediateFuture(null);
}
Aggregations