Search in sources :

Example 21 with BrokerConfig

use of org.apache.rocketmq.common.BrokerConfig in project rocketmq by apache.

the class CommitLogDispatcherCalcBitMapTest method testDispatch.

@Test
public void testDispatch() {
    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);
    ConsumerFilterManager filterManager = ConsumerFilterManagerTest.gen(10, 10);
    CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager);
    for (int i = 0; i < 10; i++) {
        Map<String, String> properties = new HashMap<String, String>(4);
        properties.put("a", String.valueOf(i * 10 + 5));
        String topic = "topic" + i;
        DispatchRequest dispatchRequest = new DispatchRequest(topic, 0, i * 100 + 123, 100, (long) ("tags" + i).hashCode(), System.currentTimeMillis(), i, null, UUID.randomUUID().toString(), 0, 0, properties);
        calcBitMap.dispatch(dispatchRequest);
        assertThat(dispatchRequest.getBitMap()).isNotNull();
        BitsArray bits = BitsArray.create(dispatchRequest.getBitMap());
        Collection<ConsumerFilterData> filterDatas = filterManager.get(topic);
        for (ConsumerFilterData filterData : filterDatas) {
            if (filterManager.getBloomFilter().isHit(filterData.getBloomFilterData(), bits)) {
                try {
                    assertThat((Boolean) filterData.getCompiledExpression().evaluate(new MessageEvaluationContext(properties))).isTrue();
                } catch (Exception e) {
                    e.printStackTrace();
                    assertThat(true).isFalse();
                }
            } else {
                try {
                    assertThat((Boolean) filterData.getCompiledExpression().evaluate(new MessageEvaluationContext(properties))).isFalse();
                } catch (Exception e) {
                    e.printStackTrace();
                    assertThat(true).isFalse();
                }
            }
        }
    }
}
Also used : BrokerConfig(org.apache.rocketmq.common.BrokerConfig) HashMap(java.util.HashMap) BitsArray(org.apache.rocketmq.filter.util.BitsArray) DispatchRequest(org.apache.rocketmq.store.DispatchRequest) Test(org.junit.Test)

Example 22 with BrokerConfig

use of org.apache.rocketmq.common.BrokerConfig in project rocketmq by apache.

the class MessageStoreWithFilterTest method gen.

protected DefaultMessageStore gen(ConsumerFilterManager filterManager) throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(commitLogFileSize, cqFileSize, true, cqExtFileSize);
    BrokerConfig brokerConfig = new BrokerConfig();
    brokerConfig.setEnableCalcFilterBitMap(true);
    brokerConfig.setMaxErrorRateOfBloomFilter(20);
    brokerConfig.setExpectConsumerNumUseFilter(64);
    DefaultMessageStore master = new DefaultMessageStore(messageStoreConfig, new BrokerStatsManager(brokerConfig.getBrokerClusterName()), new MessageArrivingListener() {

        @Override
        public void arriving(String topic, int queueId, long logicOffset, long tagsCode, long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
        }
    }, brokerConfig);
    master.getDispatcherList().addFirst(new CommitLogDispatcher() {

        @Override
        public void dispatch(DispatchRequest request) {
            try {
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    });
    master.getDispatcherList().addFirst(new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager));
    assertThat(master.load()).isTrue();
    master.start();
    return master;
}
Also used : BrokerStatsManager(org.apache.rocketmq.store.stats.BrokerStatsManager) BrokerConfig(org.apache.rocketmq.common.BrokerConfig) DefaultMessageStore(org.apache.rocketmq.store.DefaultMessageStore) DispatchRequest(org.apache.rocketmq.store.DispatchRequest) MessageStoreConfig(org.apache.rocketmq.store.config.MessageStoreConfig) MessageArrivingListener(org.apache.rocketmq.store.MessageArrivingListener) CommitLogDispatcher(org.apache.rocketmq.store.CommitLogDispatcher)

Example 23 with BrokerConfig

use of org.apache.rocketmq.common.BrokerConfig in project rocketmq by apache.

the class BrokerControllerTest method testBrokerRestart.

/**
 * Tests if the controller can be properly stopped and started.
 *
 * @throws Exception If fails.
 */
@Test
public void testBrokerRestart() throws Exception {
    BrokerController brokerController = new BrokerController(new BrokerConfig(), new NettyServerConfig(), new NettyClientConfig(), new MessageStoreConfig());
    assertThat(brokerController.initialize());
    brokerController.start();
    brokerController.shutdown();
}
Also used : MessageStoreConfig(org.apache.rocketmq.store.config.MessageStoreConfig) BrokerConfig(org.apache.rocketmq.common.BrokerConfig) NettyClientConfig(org.apache.rocketmq.remoting.netty.NettyClientConfig) NettyServerConfig(org.apache.rocketmq.remoting.netty.NettyServerConfig) Test(org.junit.Test)

Example 24 with BrokerConfig

use of org.apache.rocketmq.common.BrokerConfig in project rocketmq by apache.

the class ConsumeQueueTest method gen.

protected DefaultMessageStore gen() throws Exception {
    MessageStoreConfig messageStoreConfig = buildStoreConfig(commitLogFileSize, cqFileSize, true, cqExtFileSize);
    BrokerConfig brokerConfig = new BrokerConfig();
    DefaultMessageStore master = new DefaultMessageStore(messageStoreConfig, new BrokerStatsManager(brokerConfig.getBrokerClusterName()), new MessageArrivingListener() {

        @Override
        public void arriving(String topic, int queueId, long logicOffset, long tagsCode, long msgStoreTime, byte[] filterBitMap, Map<String, String> properties) {
        }
    }, brokerConfig);
    assertThat(master.load()).isTrue();
    master.start();
    return master;
}
Also used : BrokerStatsManager(org.apache.rocketmq.store.stats.BrokerStatsManager) MessageStoreConfig(org.apache.rocketmq.store.config.MessageStoreConfig) BrokerConfig(org.apache.rocketmq.common.BrokerConfig)

Example 25 with BrokerConfig

use of org.apache.rocketmq.common.BrokerConfig in project rocketmq by apache.

the class DefaultMessageStoreShuwDownTest method buildMessageStore.

public DefaultMessageStore buildMessageStore() throws Exception {
    MessageStoreConfig messageStoreConfig = new MessageStoreConfig();
    messageStoreConfig.setMapedFileSizeCommitLog(1024 * 1024 * 10);
    messageStoreConfig.setMapedFileSizeConsumeQueue(1024 * 1024 * 10);
    messageStoreConfig.setMaxHashSlotNum(10000);
    messageStoreConfig.setMaxIndexNum(100 * 100);
    messageStoreConfig.setFlushDiskType(FlushDiskType.SYNC_FLUSH);
    return new DefaultMessageStore(messageStoreConfig, new BrokerStatsManager("simpleTest"), null, new BrokerConfig());
}
Also used : BrokerStatsManager(org.apache.rocketmq.store.stats.BrokerStatsManager) MessageStoreConfig(org.apache.rocketmq.store.config.MessageStoreConfig) BrokerConfig(org.apache.rocketmq.common.BrokerConfig)

Aggregations

BrokerConfig (org.apache.rocketmq.common.BrokerConfig)28 MessageStoreConfig (org.apache.rocketmq.store.config.MessageStoreConfig)22 NettyClientConfig (org.apache.rocketmq.remoting.netty.NettyClientConfig)13 NettyServerConfig (org.apache.rocketmq.remoting.netty.NettyServerConfig)13 Test (org.junit.Test)11 BrokerController (org.apache.rocketmq.broker.BrokerController)9 DispatchRequest (org.apache.rocketmq.store.DispatchRequest)8 HashMap (java.util.HashMap)6 BrokerStatsManager (org.apache.rocketmq.store.stats.BrokerStatsManager)6 MQClientException (org.apache.rocketmq.client.exception.MQClientException)5 BitsArray (org.apache.rocketmq.filter.util.BitsArray)4 LoggerContext (ch.qos.logback.classic.LoggerContext)2 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)2 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 Properties (java.util.Properties)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Options (org.apache.commons.cli.Options)2