Search in sources :

Example 1 with BloomFilterData

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();
}
Also used : BloomFilterData(org.apache.rocketmq.filter.util.BloomFilterData) BloomFilter(org.apache.rocketmq.filter.util.BloomFilter) Test(org.junit.Test)

Example 2 with BloomFilterData

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);
}
Also used : BloomFilterData(org.apache.rocketmq.filter.util.BloomFilterData)

Example 3 with BloomFilterData

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);
}
Also used : BloomFilterData(org.apache.rocketmq.filter.util.BloomFilterData)

Example 4 with BloomFilterData

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();
}
Also used : BloomFilterData(org.apache.rocketmq.filter.util.BloomFilterData) BloomFilter(org.apache.rocketmq.filter.util.BloomFilter) Test(org.junit.Test)

Aggregations

BloomFilterData (org.apache.rocketmq.filter.util.BloomFilterData)4 BloomFilter (org.apache.rocketmq.filter.util.BloomFilter)2 Test (org.junit.Test)2