use of org.apache.rocketmq.filter.util.BloomFilterData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class BloomFilterTest method testBloomFilterData.
@Test
public void testBloomFilterData() {
BloomFilterData bloomFilterData = new BloomFilterData(new int[] { 1, 2, 3 }, 128);
BloomFilterData bloomFilterData1 = new BloomFilterData(new int[] { 1, 2, 3 }, 128);
BloomFilterData bloomFilterData2 = new BloomFilterData(new int[] { 1, 2, 3 }, 129);
assertThat(bloomFilterData).isEqualTo(bloomFilterData1);
assertThat(bloomFilterData2).isNotEqualTo(bloomFilterData);
assertThat(bloomFilterData2).isNotEqualTo(bloomFilterData1);
assertThat(bloomFilterData.hashCode()).isEqualTo(bloomFilterData1.hashCode());
assertThat(bloomFilterData2.hashCode()).isNotEqualTo(bloomFilterData.hashCode());
assertThat(bloomFilterData2.hashCode()).isNotEqualTo(bloomFilterData1.hashCode());
assertThat(bloomFilterData.getBitPos()).isEqualTo(bloomFilterData2.getBitPos());
assertThat(bloomFilterData.getBitNum()).isEqualTo(bloomFilterData1.getBitNum());
assertThat(bloomFilterData.getBitNum()).isNotEqualTo(bloomFilterData2.getBitNum());
bloomFilterData2.setBitNum(128);
assertThat(bloomFilterData).isEqualTo(bloomFilterData2);
bloomFilterData2.setBitPos(new int[] { 1, 2, 3, 4 });
assertThat(bloomFilterData).isNotEqualTo(bloomFilterData2);
BloomFilterData nullData = new BloomFilterData();
assertThat(nullData.getBitNum()).isEqualTo(0);
assertThat(nullData.getBitPos()).isNull();
BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
assertThat(bloomFilter).isNotNull();
assertThat(bloomFilter.isValid(bloomFilterData)).isFalse();
}
use of org.apache.rocketmq.filter.util.BloomFilterData in project rocketmq by apache.
the class ConsumerFilterManager method register.
public boolean register(final String topic, final String consumerGroup, final String expression, final String type, final long clientVersion) {
if (ExpressionType.isTagType(type)) {
return false;
}
if (expression == null || expression.length() == 0) {
return false;
}
FilterDataMapByTopic filterDataMapByTopic = this.filterDataByTopic.get(topic);
if (filterDataMapByTopic == null) {
FilterDataMapByTopic temp = new FilterDataMapByTopic(topic);
FilterDataMapByTopic prev = this.filterDataByTopic.putIfAbsent(topic, temp);
filterDataMapByTopic = prev != null ? prev : temp;
}
BloomFilterData bloomFilterData = bloomFilter.generate(consumerGroup + "#" + topic);
return filterDataMapByTopic.register(consumerGroup, expression, type, bloomFilterData, clientVersion);
}
use of org.apache.rocketmq.filter.util.BloomFilterData in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class ConsumerFilterManager method register.
public boolean register(final String topic, final String consumerGroup, final String expression, final String type, final long clientVersion) {
if (ExpressionType.isTagType(type)) {
return false;
}
if (expression == null || expression.length() == 0) {
return false;
}
FilterDataMapByTopic filterDataMapByTopic = this.filterDataByTopic.get(topic);
if (filterDataMapByTopic == null) {
FilterDataMapByTopic temp = new FilterDataMapByTopic(topic);
FilterDataMapByTopic prev = this.filterDataByTopic.putIfAbsent(topic, temp);
filterDataMapByTopic = prev != null ? prev : temp;
}
BloomFilterData bloomFilterData = bloomFilter.generate(consumerGroup + "#" + topic);
return filterDataMapByTopic.register(consumerGroup, expression, type, bloomFilterData, clientVersion);
}
use of org.apache.rocketmq.filter.util.BloomFilterData in project rocketmq by apache.
the class BloomFilterTest method testBloomFilterData.
@Test
public void testBloomFilterData() {
BloomFilterData bloomFilterData = new BloomFilterData(new int[] { 1, 2, 3 }, 128);
BloomFilterData bloomFilterData1 = new BloomFilterData(new int[] { 1, 2, 3 }, 128);
BloomFilterData bloomFilterData2 = new BloomFilterData(new int[] { 1, 2, 3 }, 129);
assertThat(bloomFilterData).isEqualTo(bloomFilterData1);
assertThat(bloomFilterData2).isNotEqualTo(bloomFilterData);
assertThat(bloomFilterData2).isNotEqualTo(bloomFilterData1);
assertThat(bloomFilterData.hashCode()).isEqualTo(bloomFilterData1.hashCode());
assertThat(bloomFilterData2.hashCode()).isNotEqualTo(bloomFilterData.hashCode());
assertThat(bloomFilterData2.hashCode()).isNotEqualTo(bloomFilterData1.hashCode());
assertThat(bloomFilterData.getBitPos()).isEqualTo(bloomFilterData2.getBitPos());
assertThat(bloomFilterData.getBitNum()).isEqualTo(bloomFilterData1.getBitNum());
assertThat(bloomFilterData.getBitNum()).isNotEqualTo(bloomFilterData2.getBitNum());
bloomFilterData2.setBitNum(128);
assertThat(bloomFilterData).isEqualTo(bloomFilterData2);
bloomFilterData2.setBitPos(new int[] { 1, 2, 3, 4 });
assertThat(bloomFilterData).isNotEqualTo(bloomFilterData2);
BloomFilterData nullData = new BloomFilterData();
assertThat(nullData.getBitNum()).isEqualTo(0);
assertThat(nullData.getBitPos()).isNull();
BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
assertThat(bloomFilter).isNotNull();
assertThat(bloomFilter.isValid(bloomFilterData)).isFalse();
}
Aggregations