Search in sources :

Example 11 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class StoreConfigurationChangeListenerTest method testAttributeSet.

@Test
public void testAttributeSet() {
    notifyBrokerStarted();
    Broker broker = mock(Broker.class);
    when(broker.getCategoryClass()).thenReturn(Broker.class);
    when(broker.isDurable()).thenReturn(true);
    final ConfiguredObjectRecord record = mock(ConfiguredObjectRecord.class);
    when(broker.asObjectRecord()).thenReturn(record);
    _listener.attributeSet(broker, Broker.DESCRIPTION, null, "test description");
    verify(_store).update(eq(false), eq(record));
}
Also used : Broker(org.apache.qpid.server.model.Broker) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) Test(org.junit.Test)

Example 12 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class VirtualHostStoreUpgraderAndRecovererTest method setUp.

@Before
public void setUp() throws Exception {
    final Broker broker = mock(Broker.class);
    _virtualHostNode = mock(VirtualHostNode.class);
    when(_virtualHostNode.getParent()).thenReturn(broker);
    _store = mock(DurableConfigurationStore.class);
    _upgraderAndRecoverer = new VirtualHostStoreUpgraderAndRecoverer(_virtualHostNode);
}
Also used : Broker(org.apache.qpid.server.model.Broker) VirtualHostNode(org.apache.qpid.server.model.VirtualHostNode) Before(org.junit.Before)

Example 13 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class AMQChannelTest method setUp.

@Before
public void setUp() throws Exception {
    TaskExecutor taskExecutor = mock(TaskExecutor.class);
    _broker = mock(Broker.class);
    when(_broker.getEventLogger()).thenReturn(mock(EventLogger.class));
    when(_broker.getContextValue(Long.class, Broker.CHANNEL_FLOW_CONTROL_ENFORCEMENT_TIMEOUT)).thenReturn(1l);
    _messageStore = mock(MessageStore.class);
    _virtualHost = mock(QueueManagingVirtualHost.class);
    when(_virtualHost.getContextValue(Integer.class, Broker.MESSAGE_COMPRESSION_THRESHOLD_SIZE)).thenReturn(1);
    when(_virtualHost.getContextValue(Long.class, Connection.MAX_UNCOMMITTED_IN_MEMORY_SIZE)).thenReturn(1l);
    when(_virtualHost.getContextValue(Boolean.class, Broker.BROKER_MSG_AUTH)).thenReturn(false);
    when(_virtualHost.getPrincipal()).thenReturn(mock(Principal.class));
    when(_virtualHost.getEventLogger()).thenReturn(mock(EventLogger.class));
    _port = mock(AmqpPort.class);
    when(_port.getChildExecutor()).thenReturn(taskExecutor);
    when(_port.getModel()).thenReturn(BrokerModel.getInstance());
    when(_port.getContextValue(Integer.class, Connection.MAX_MESSAGE_SIZE)).thenReturn(1);
    AuthenticatedPrincipal authenticatedPrincipal = new AuthenticatedPrincipal(new UsernamePrincipal("user", null));
    Set<Principal> authenticatedUser = Collections.<Principal>singleton(authenticatedPrincipal);
    Subject authenticatedSubject = new Subject(true, authenticatedUser, Collections.<Principal>emptySet(), Collections.<Principal>emptySet());
    _protocolOutputConverter = mock(ProtocolOutputConverter.class);
    _amqConnection = mock(AMQPConnection_0_8.class);
    when(_amqConnection.getSubject()).thenReturn(authenticatedSubject);
    when(_amqConnection.getAuthorizedPrincipal()).thenReturn(authenticatedPrincipal);
    when(_amqConnection.getAddressSpace()).thenReturn((VirtualHost) _virtualHost);
    when(_amqConnection.getProtocolOutputConverter()).thenReturn(_protocolOutputConverter);
    when(_amqConnection.getBroker()).thenReturn((Broker) _broker);
    when(_amqConnection.getMethodRegistry()).thenReturn(new MethodRegistry(ProtocolVersion.v0_9));
    when(_amqConnection.getContextProvider()).thenReturn(_virtualHost);
    when(_amqConnection.getContextValue(Long.class, Session.PRODUCER_AUTH_CACHE_TIMEOUT)).thenReturn(Session.PRODUCER_AUTH_CACHE_TIMEOUT_DEFAULT);
    when(_amqConnection.getContextValue(Integer.class, Session.PRODUCER_AUTH_CACHE_SIZE)).thenReturn(Session.PRODUCER_AUTH_CACHE_SIZE_DEFAULT);
    when(_amqConnection.getContextValue(Long.class, Connection.MAX_UNCOMMITTED_IN_MEMORY_SIZE)).thenReturn(Connection.DEFAULT_MAX_UNCOMMITTED_IN_MEMORY_SIZE);
    when(_amqConnection.getContextValue(Boolean.class, AMQPConnection_0_8.FORCE_MESSAGE_VALIDATION)).thenReturn(true);
    when(_amqConnection.getTaskExecutor()).thenReturn(taskExecutor);
    when(_amqConnection.getChildExecutor()).thenReturn(taskExecutor);
    when(_amqConnection.getModel()).thenReturn(BrokerModel.getInstance());
    when(_amqConnection.getContextValue(Long.class, AMQPConnection_0_8.BATCH_LIMIT)).thenReturn(AMQPConnection_0_8.DEFAULT_BATCH_LIMIT);
    when(_amqConnection.getContextValue(Long.class, AMQPConnection_0_8.HIGH_PREFETCH_LIMIT)).thenReturn(AMQPConnection_0_8.DEFAULT_BATCH_LIMIT);
    when(_amqConnection.getEventLogger()).thenReturn(mock(EventLogger.class));
    _messageDestination = mock(MessageDestination.class);
}
Also used : MessageStore(org.apache.qpid.server.store.MessageStore) NullMessageStore(org.apache.qpid.server.store.NullMessageStore) Broker(org.apache.qpid.server.model.Broker) MessageDestination(org.apache.qpid.server.message.MessageDestination) QueueManagingVirtualHost(org.apache.qpid.server.virtualhost.QueueManagingVirtualHost) EventLogger(org.apache.qpid.server.logging.EventLogger) MethodRegistry(org.apache.qpid.server.protocol.v0_8.transport.MethodRegistry) Subject(javax.security.auth.Subject) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Principal(java.security.Principal) Before(org.junit.Before)

Example 14 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class ProtocolEngine_1_0_0Test method setUp.

@Before
public void setUp() throws Exception {
    _networkConnection = mock(ServerNetworkConnection.class);
    when(_networkConnection.getLocalAddress()).thenReturn(new InetSocketAddress(0));
    when(_networkConnection.getSelectedHost()).thenReturn("localhost");
    _broker = mock(Broker.class);
    when(_broker.getModel()).thenReturn(BrokerModel.getInstance());
    when(_broker.getNetworkBufferSize()).thenReturn(256 * 1026);
    final TaskExecutor taskExecutor = new TaskExecutorImpl();
    taskExecutor.start();
    when(_broker.getChildExecutor()).thenReturn(taskExecutor);
    when(_broker.getTaskExecutor()).thenReturn(taskExecutor);
    when(_broker.getId()).thenReturn(UUID.randomUUID());
    when(_broker.getEventLogger()).thenReturn(new EventLogger());
    when(((Broker) _broker).getCategoryClass()).thenReturn(Broker.class);
    _port = mock(AmqpPort.class);
    when(_port.getChildExecutor()).thenReturn(taskExecutor);
    when(_port.getCategoryClass()).thenReturn(Port.class);
    when(_port.getModel()).thenReturn(BrokerModel.getInstance());
    final SubjectCreator subjectCreator = mock(SubjectCreator.class);
    _authenticationProvider = mock(AuthenticationProvider.class);
    when(_port.getAuthenticationProvider()).thenReturn(_authenticationProvider);
    _virtualHost = mock(VirtualHost.class);
    when(_virtualHost.getChildExecutor()).thenReturn(taskExecutor);
    when(_virtualHost.getModel()).thenReturn(BrokerModel.getInstance());
    when(_virtualHost.getState()).thenReturn(State.ACTIVE);
    when(_virtualHost.isActive()).thenReturn(true);
    final ArgumentCaptor<AMQPConnection> connectionCaptor = ArgumentCaptor.forClass(AMQPConnection.class);
    doAnswer(new Answer() {

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            _connection = connectionCaptor.getValue();
            throw new SoleConnectionEnforcementPolicyException(null, Collections.emptySet(), "abc1");
        }
    }).when(_virtualHost).registerConnection(connectionCaptor.capture());
    when(_virtualHost.getPrincipal()).thenReturn(mock(VirtualHostPrincipal.class));
    when(_port.getAddressSpace(anyString())).thenReturn(_virtualHost);
    when(_port.getSubjectCreator(anyBoolean(), anyString())).thenReturn(subjectCreator);
    final ArgumentCaptor<Principal> userCaptor = ArgumentCaptor.forClass(Principal.class);
    when(subjectCreator.createSubjectWithGroups(userCaptor.capture())).then(new Answer<Subject>() {

        @Override
        public Subject answer(final InvocationOnMock invocation) throws Throwable {
            Subject subject = new Subject();
            subject.getPrincipals().add(userCaptor.getValue());
            return subject;
        }
    });
    final ByteBufferSender sender = mock(ByteBufferSender.class);
    when(_networkConnection.getSender()).thenReturn(sender);
    AMQPDescribedTypeRegistry registry = AMQPDescribedTypeRegistry.newInstance().registerTransportLayer().registerMessagingLayer().registerTransactionLayer().registerSecurityLayer();
    _frameWriter = new FrameWriter(registry, new ByteBufferSender() {

        @Override
        public boolean isDirectBufferPreferred() {
            return false;
        }

        @Override
        public void send(final QpidByteBuffer msg) {
            _protocolEngine_1_0_0.received(msg);
        }

        @Override
        public void flush() {
        }

        @Override
        public void close() {
        }
    });
}
Also used : ByteBufferSender(org.apache.qpid.server.transport.ByteBufferSender) InetSocketAddress(java.net.InetSocketAddress) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) AmqpPort(org.apache.qpid.server.model.port.AmqpPort) ServerNetworkConnection(org.apache.qpid.server.transport.ServerNetworkConnection) TaskExecutorImpl(org.apache.qpid.server.configuration.updater.TaskExecutorImpl) AMQPDescribedTypeRegistry(org.apache.qpid.server.protocol.v1_0.type.codec.AMQPDescribedTypeRegistry) Broker(org.apache.qpid.server.model.Broker) SoleConnectionEnforcementPolicyException(org.apache.qpid.server.protocol.v1_0.type.extensions.soleconn.SoleConnectionEnforcementPolicyException) EventLogger(org.apache.qpid.server.logging.EventLogger) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider) Subject(javax.security.auth.Subject) FrameWriter(org.apache.qpid.server.protocol.v1_0.codec.FrameWriter) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) TaskExecutor(org.apache.qpid.server.configuration.updater.TaskExecutor) AMQPConnection(org.apache.qpid.server.transport.AMQPConnection) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) QpidByteBuffer(org.apache.qpid.server.bytebuffer.QpidByteBuffer) VirtualHost(org.apache.qpid.server.model.VirtualHost) SubjectCreator(org.apache.qpid.server.security.SubjectCreator) VirtualHostPrincipal(org.apache.qpid.server.virtualhost.VirtualHostPrincipal) Principal(java.security.Principal) AuthenticatedPrincipal(org.apache.qpid.server.security.auth.AuthenticatedPrincipal) Before(org.junit.Before)

Example 15 with Broker

use of org.apache.qpid.server.model.Broker in project qpid-broker-j by apache.

the class BrokerMemoryLoggerTest method testCreateDeleteBrokerMemoryLogger.

@Test
public void testCreateDeleteBrokerMemoryLogger() {
    final String brokerLoggerName = "TestBrokerLogger";
    ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    Broker broker = _systemConfig.getContainer(Broker.class);
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(ConfiguredObject.NAME, brokerLoggerName);
    attributes.put(ConfiguredObject.TYPE, BrokerMemoryLogger.TYPE);
    BrokerLogger brokerLogger = (BrokerLogger) broker.createChild(BrokerLogger.class, attributes);
    assertEquals("Created BrokerLogger has unexpected name", brokerLoggerName, brokerLogger.getName());
    final boolean condition = brokerLogger instanceof BrokerMemoryLogger;
    assertTrue("BrokerLogger has unexpected type", condition);
    assertNotNull("Appender not attached to root logger after BrokerLogger creation", rootLogger.getAppender(brokerLoggerName));
    brokerLogger.delete();
    assertNull("Appender should be no longer attached to root logger after BrokerLogger deletion", rootLogger.getAppender(brokerLoggerName));
}
Also used : Broker(org.apache.qpid.server.model.Broker) HashMap(java.util.HashMap) BrokerLogger(org.apache.qpid.server.model.BrokerLogger) EventLogger(org.apache.qpid.server.logging.EventLogger) Logger(org.slf4j.Logger) BrokerLogger(org.apache.qpid.server.model.BrokerLogger) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) Test(org.junit.Test)

Aggregations

Broker (org.apache.qpid.server.model.Broker)38 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)15 EventLogger (org.apache.qpid.server.logging.EventLogger)13 Before (org.junit.Before)11 Test (org.junit.Test)8 Subject (javax.security.auth.Subject)7 HashMap (java.util.HashMap)6 TaskExecutor (org.apache.qpid.server.configuration.updater.TaskExecutor)6 VirtualHost (org.apache.qpid.server.model.VirtualHost)6 VirtualHostNode (org.apache.qpid.server.model.VirtualHostNode)6 CurrentThreadTaskExecutor (org.apache.qpid.server.configuration.updater.CurrentThreadTaskExecutor)5 Model (org.apache.qpid.server.model.Model)5 TaskExecutorImpl (org.apache.qpid.server.configuration.updater.TaskExecutorImpl)4 SubjectAuthenticationResult (org.apache.qpid.server.security.auth.SubjectAuthenticationResult)4 DurableConfigurationStore (org.apache.qpid.server.store.DurableConfigurationStore)4 AccessControlException (java.security.AccessControlException)3 Principal (java.security.Principal)3 SSLContext (javax.net.ssl.SSLContext)3 BrokerModel (org.apache.qpid.server.model.BrokerModel)3 Queue (org.apache.qpid.server.model.Queue)3