use of org.apache.rocketmq.store.DispatchRequest in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
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();
}
}
}
}
}
use of org.apache.rocketmq.store.DispatchRequest in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
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) {
// System.out.println(String.format("Msg coming: %s, %d, %d, %d",
// topic, queueId, logicOffset, tagsCode));
}
}, brokerConfig);
master.getDispatcherList().addFirst(new CommitLogDispatcher() {
@Override
public void dispatch(DispatchRequest request) {
try {
// System.out.println(String.format("offset:%d, bitMap:%s", request.getCommitLogOffset(),
// BitsArray.create(request.getBitMap()).toString()));
} catch (Throwable e) {
e.printStackTrace();
}
}
});
master.getDispatcherList().addFirst(new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager));
assertThat(master.load()).isTrue();
master.start();
return master;
}
use of org.apache.rocketmq.store.DispatchRequest in project rocketmq by apache.
the class CommitLogDispatcherCalcBitMapTest method testDispatch_blankFilterData.
@Test
public void testDispatch_blankFilterData() {
BrokerConfig brokerConfig = new BrokerConfig();
brokerConfig.setEnableCalcFilterBitMap(true);
ConsumerFilterManager filterManager = new ConsumerFilterManager();
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()).isNull();
}
}
use of org.apache.rocketmq.store.DispatchRequest 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();
}
}
}
}
}
use of org.apache.rocketmq.store.DispatchRequest 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;
}
Aggregations