Search in sources :

Example 1 with BrokerInterceptor

use of org.apache.pulsar.broker.intercept.BrokerInterceptor in project pulsar by apache.

the class ProcessHandlerFilterTest method testChainDoFilter.

@Test
public void testChainDoFilter() throws ServletException, IOException {
    PulsarService mockPulsarService = Mockito.mock(PulsarService.class);
    BrokerInterceptor spyInterceptor = Mockito.mock(BrokerInterceptor.class);
    HttpServletResponse mockHttpServletResponse = Mockito.mock(HttpServletResponse.class);
    ServiceConfiguration mockConfig = Mockito.mock(ServiceConfiguration.class);
    FilterChain spyFilterChain = Mockito.spy(FilterChain.class);
    Mockito.doReturn(spyInterceptor).when(mockPulsarService).getBrokerInterceptor();
    Mockito.doReturn(mockConfig).when(mockPulsarService).getConfig();
    Mockito.doReturn(Sets.newHashSet()).when(mockConfig).getBrokerInterceptors();
    // empty interceptor list
    HttpServletRequest mockHttpServletRequest = Mockito.mock(HttpServletRequest.class);
    ProcessHandlerFilter processHandlerFilter = new ProcessHandlerFilter(mockPulsarService);
    processHandlerFilter.doFilter(mockHttpServletRequest, mockHttpServletResponse, spyFilterChain);
    Mockito.verify(spyFilterChain).doFilter(mockHttpServletRequest, mockHttpServletResponse);
    Mockito.clearInvocations(spyFilterChain);
    // request has MULTIPART_FORM_DATA content-type
    Mockito.doReturn(Sets.newHashSet("Interceptor1", "Interceptor2")).when(mockConfig).getBrokerInterceptors();
    HttpServletRequest mockHttpServletRequest2 = Mockito.mock(HttpServletRequest.class);
    Mockito.doReturn(MediaType.MULTIPART_FORM_DATA).when(mockHttpServletRequest2).getContentType();
    ProcessHandlerFilter processHandlerFilter2 = new ProcessHandlerFilter(mockPulsarService);
    processHandlerFilter2.doFilter(mockHttpServletRequest2, mockHttpServletResponse, spyFilterChain);
    Mockito.verify(spyFilterChain).doFilter(mockHttpServletRequest2, mockHttpServletResponse);
    Mockito.clearInvocations(spyFilterChain);
    // request has APPLICATION_OCTET_STREAM content-type
    Mockito.doReturn(MediaType.APPLICATION_OCTET_STREAM).when(mockHttpServletRequest2).getContentType();
    processHandlerFilter2.doFilter(mockHttpServletRequest2, mockHttpServletResponse, spyFilterChain);
    Mockito.verify(spyFilterChain).doFilter(mockHttpServletRequest2, mockHttpServletResponse);
}
Also used : BrokerInterceptor(org.apache.pulsar.broker.intercept.BrokerInterceptor) HttpServletRequest(javax.servlet.http.HttpServletRequest) PulsarService(org.apache.pulsar.broker.PulsarService) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Example 2 with BrokerInterceptor

use of org.apache.pulsar.broker.intercept.BrokerInterceptor in project pulsar by yahoo.

the class ServerCnx method completeConnect.

// complete the connect and sent newConnected command
private void completeConnect(int clientProtoVersion, String clientVersion) {
    ctx.writeAndFlush(Commands.newConnected(clientProtoVersion, maxMessageSize));
    state = State.Connected;
    service.getPulsarStats().recordConnectionCreateSuccess();
    if (log.isDebugEnabled()) {
        log.debug("[{}] connect state change to : [{}]", remoteAddress, State.Connected.name());
    }
    setRemoteEndpointProtocolVersion(clientProtoVersion);
    if (isNotBlank(clientVersion) && !clientVersion.contains(" ")) /* ignore default version: pulsar client */
    {
        this.clientVersion = clientVersion.intern();
    }
    BrokerInterceptor brokerInterceptor = getBrokerService().getInterceptor();
    if (brokerInterceptor != null) {
        brokerInterceptor.onConnectionCreated(this);
    }
}
Also used : BrokerInterceptor(org.apache.pulsar.broker.intercept.BrokerInterceptor)

Example 3 with BrokerInterceptor

use of org.apache.pulsar.broker.intercept.BrokerInterceptor in project incubator-pulsar by apache.

the class ServerCnx method completeConnect.

// complete the connect and sent newConnected command
private void completeConnect(int clientProtoVersion, String clientVersion) {
    ctx.writeAndFlush(Commands.newConnected(clientProtoVersion, maxMessageSize));
    state = State.Connected;
    service.getPulsarStats().recordConnectionCreateSuccess();
    if (log.isDebugEnabled()) {
        log.debug("[{}] connect state change to : [{}]", remoteAddress, State.Connected.name());
    }
    setRemoteEndpointProtocolVersion(clientProtoVersion);
    if (isNotBlank(clientVersion) && !clientVersion.contains(" ")) /* ignore default version: pulsar client */
    {
        this.clientVersion = clientVersion.intern();
    }
    BrokerInterceptor brokerInterceptor = getBrokerService().getInterceptor();
    if (brokerInterceptor != null) {
        brokerInterceptor.onConnectionCreated(this);
    }
}
Also used : BrokerInterceptor(org.apache.pulsar.broker.intercept.BrokerInterceptor)

Example 4 with BrokerInterceptor

use of org.apache.pulsar.broker.intercept.BrokerInterceptor in project incubator-pulsar by apache.

the class TransactionTest method testEndTxnWhenCommittingOrAborting.

@Test
public void testEndTxnWhenCommittingOrAborting() throws Exception {
    Transaction commitTxn = pulsarClient.newTransaction().withTransactionTimeout(5, TimeUnit.SECONDS).build().get();
    Transaction abortTxn = pulsarClient.newTransaction().withTransactionTimeout(5, TimeUnit.SECONDS).build().get();
    Class<TransactionImpl> transactionClass = TransactionImpl.class;
    Field field = transactionClass.getDeclaredField("state");
    field.setAccessible(true);
    field.set(commitTxn, TransactionImpl.State.COMMITTING);
    field.set(abortTxn, TransactionImpl.State.ABORTING);
    BrokerInterceptor listener = getPulsarServiceList().get(0).getBrokerInterceptor();
    assertEquals(((CounterBrokerInterceptor) listener).getTxnCount(), 2);
    abortTxn.abort().get();
    assertEquals(((CounterBrokerInterceptor) listener).getAbortedTxnCount(), 1);
    commitTxn.commit().get();
    assertEquals(((CounterBrokerInterceptor) listener).getCommittedTxnCount(), 1);
}
Also used : BrokerInterceptor(org.apache.pulsar.broker.intercept.BrokerInterceptor) CounterBrokerInterceptor(org.apache.pulsar.broker.intercept.CounterBrokerInterceptor) Field(java.lang.reflect.Field) Transaction(org.apache.pulsar.client.api.transaction.Transaction) TransactionImpl(org.apache.pulsar.client.impl.transaction.TransactionImpl) Test(org.testng.annotations.Test)

Example 5 with BrokerInterceptor

use of org.apache.pulsar.broker.intercept.BrokerInterceptor in project incubator-pulsar by apache.

the class ProcessHandlerFilterTest method testChainDoFilter.

@Test
public void testChainDoFilter() throws ServletException, IOException {
    PulsarService mockPulsarService = Mockito.mock(PulsarService.class);
    BrokerInterceptor spyInterceptor = Mockito.mock(BrokerInterceptor.class);
    HttpServletResponse mockHttpServletResponse = Mockito.mock(HttpServletResponse.class);
    ServiceConfiguration mockConfig = Mockito.mock(ServiceConfiguration.class);
    FilterChain spyFilterChain = Mockito.spy(FilterChain.class);
    Mockito.doReturn(spyInterceptor).when(mockPulsarService).getBrokerInterceptor();
    Mockito.doReturn(mockConfig).when(mockPulsarService).getConfig();
    Mockito.doReturn(Sets.newHashSet()).when(mockConfig).getBrokerInterceptors();
    // empty interceptor list
    HttpServletRequest mockHttpServletRequest = Mockito.mock(HttpServletRequest.class);
    ProcessHandlerFilter processHandlerFilter = new ProcessHandlerFilter(mockPulsarService);
    processHandlerFilter.doFilter(mockHttpServletRequest, mockHttpServletResponse, spyFilterChain);
    Mockito.verify(spyFilterChain).doFilter(mockHttpServletRequest, mockHttpServletResponse);
    Mockito.clearInvocations(spyFilterChain);
    // request has MULTIPART_FORM_DATA content-type
    Mockito.doReturn(Sets.newHashSet("Interceptor1", "Interceptor2")).when(mockConfig).getBrokerInterceptors();
    HttpServletRequest mockHttpServletRequest2 = Mockito.mock(HttpServletRequest.class);
    Mockito.doReturn(MediaType.MULTIPART_FORM_DATA).when(mockHttpServletRequest2).getContentType();
    ProcessHandlerFilter processHandlerFilter2 = new ProcessHandlerFilter(mockPulsarService);
    processHandlerFilter2.doFilter(mockHttpServletRequest2, mockHttpServletResponse, spyFilterChain);
    Mockito.verify(spyFilterChain).doFilter(mockHttpServletRequest2, mockHttpServletResponse);
    Mockito.clearInvocations(spyFilterChain);
    // request has APPLICATION_OCTET_STREAM content-type
    Mockito.doReturn(MediaType.APPLICATION_OCTET_STREAM).when(mockHttpServletRequest2).getContentType();
    processHandlerFilter2.doFilter(mockHttpServletRequest2, mockHttpServletResponse, spyFilterChain);
    Mockito.verify(spyFilterChain).doFilter(mockHttpServletRequest2, mockHttpServletResponse);
}
Also used : BrokerInterceptor(org.apache.pulsar.broker.intercept.BrokerInterceptor) HttpServletRequest(javax.servlet.http.HttpServletRequest) PulsarService(org.apache.pulsar.broker.PulsarService) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Test(org.testng.annotations.Test)

Aggregations

BrokerInterceptor (org.apache.pulsar.broker.intercept.BrokerInterceptor)20 PulsarService (org.apache.pulsar.broker.PulsarService)9 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)9 Test (org.testng.annotations.Test)8 FilterChain (javax.servlet.FilterChain)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 ByteBuf (io.netty.buffer.ByteBuf)3 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)3 Entry (org.apache.bookkeeper.mledger.Entry)3 ManagedLedgerFactory (org.apache.bookkeeper.mledger.ManagedLedgerFactory)3 Position (org.apache.bookkeeper.mledger.Position)3 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)3 MockedPulsarServiceBaseTest.createMockZooKeeper (org.apache.pulsar.broker.auth.MockedPulsarServiceBaseTest.createMockZooKeeper)3 NamespaceService (org.apache.pulsar.broker.namespace.NamespaceService)3 NamespaceResources (org.apache.pulsar.broker.resources.NamespaceResources)3 PulsarResources (org.apache.pulsar.broker.resources.PulsarResources)3 DefaultSchemaRegistryService (org.apache.pulsar.broker.service.schema.DefaultSchemaRegistryService)3 ClientChannelHelper (org.apache.pulsar.broker.service.utils.ClientChannelHelper)3 TxnID (org.apache.pulsar.client.api.transaction.TxnID)3