org.apache.rocketmq.filter.util.BloomFilter Java Examples

The following examples show how to use org.apache.rocketmq.filter.util.BloomFilter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BloomFilterTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
    BloomFilter a = BloomFilter.createByFn(10, 20);

    BloomFilter b = BloomFilter.createByFn(10, 20);

    BloomFilter c = BloomFilter.createByFn(12, 20);

    BloomFilter d = BloomFilter.createByFn(10, 30);

    assertThat(a).isEqualTo(b);
    assertThat(a).isNotEqualTo(c);
    assertThat(a).isNotEqualTo(d);
    assertThat(d).isNotEqualTo(c);

    assertThat(a.hashCode()).isEqualTo(b.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(c.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(d.hashCode());
    assertThat(c.hashCode()).isNotEqualTo(d.hashCode());
}
 
Example #2
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example #3
Source File: ExpressionMessageFilter.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
public ExpressionMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData,
    ConsumerFilterManager consumerFilterManager) {
    this.subscriptionData = subscriptionData;
    this.consumerFilterData = consumerFilterData;
    this.consumerFilterManager = consumerFilterManager;
    if (consumerFilterData == null) {
        bloomDataValid = false;
        return;
    }
    BloomFilter bloomFilter = this.consumerFilterManager.getBloomFilter();
    if (bloomFilter != null && bloomFilter.isValid(consumerFilterData.getBloomFilterData())) {
        bloomDataValid = true;
    } else {
        bloomDataValid = false;
    }
}
 
Example #4
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
    BloomFilter a = BloomFilter.createByFn(10, 20);

    BloomFilter b = BloomFilter.createByFn(10, 20);

    BloomFilter c = BloomFilter.createByFn(12, 20);

    BloomFilter d = BloomFilter.createByFn(10, 30);

    assertThat(a).isEqualTo(b);
    assertThat(a).isNotEqualTo(c);
    assertThat(a).isNotEqualTo(d);
    assertThat(d).isNotEqualTo(c);

    assertThat(a.hashCode()).isEqualTo(b.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(c.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(d.hashCode());
    assertThat(c.hashCode()).isNotEqualTo(d.hashCode());
}
 
Example #5
Source File: ExpressionMessageFilter.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public ExpressionMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData,
    ConsumerFilterManager consumerFilterManager) {
    this.subscriptionData = subscriptionData;
    this.consumerFilterData = consumerFilterData;
    this.consumerFilterManager = consumerFilterManager;
    if (consumerFilterData == null) {
        bloomDataValid = false;
        return;
    }
    BloomFilter bloomFilter = this.consumerFilterManager.getBloomFilter();
    if (bloomFilter != null && bloomFilter.isValid(consumerFilterData.getBloomFilterData())) {
        bloomDataValid = true;
    } else {
        bloomDataValid = false;
    }
}
 
Example #6
Source File: BloomFilterTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
    BloomFilter a = BloomFilter.createByFn(10, 20);

    BloomFilter b = BloomFilter.createByFn(10, 20);

    BloomFilter c = BloomFilter.createByFn(12, 20);

    BloomFilter d = BloomFilter.createByFn(10, 30);

    assertThat(a).isEqualTo(b);
    assertThat(a).isNotEqualTo(c);
    assertThat(a).isNotEqualTo(d);
    assertThat(d).isNotEqualTo(c);

    assertThat(a.hashCode()).isEqualTo(b.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(c.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(d.hashCode());
    assertThat(c.hashCode()).isNotEqualTo(d.hashCode());
}
 
Example #7
Source File: BloomFilterTest.java    From rocketmq-4.3.0 with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example #8
Source File: ExpressionMessageFilter.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
public ExpressionMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData,
    ConsumerFilterManager consumerFilterManager) {
    this.subscriptionData = subscriptionData;
    this.consumerFilterData = consumerFilterData;
    this.consumerFilterManager = consumerFilterManager;
    if (consumerFilterData == null) {
        bloomDataValid = false;
        return;
    }
    BloomFilter bloomFilter = this.consumerFilterManager.getBloomFilter();
    if (bloomFilter != null && bloomFilter.isValid(consumerFilterData.getBloomFilterData())) {
        bloomDataValid = true;
    } else {
        bloomDataValid = false;
    }
}
 
Example #9
Source File: BloomFilterTest.java    From rocketmq-read with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example #10
Source File: ExpressionMessageFilter.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
public ExpressionMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData,
    ConsumerFilterManager consumerFilterManager) {
    this.subscriptionData = subscriptionData;
    this.consumerFilterData = consumerFilterData;
    this.consumerFilterManager = consumerFilterManager;
    if (consumerFilterData == null) {
        bloomDataValid = false;
        return;
    }
    BloomFilter bloomFilter = this.consumerFilterManager.getBloomFilter();
    if (bloomFilter != null && bloomFilter.isValid(consumerFilterData.getBloomFilterData())) {
        bloomDataValid = true;
    } else {
        bloomDataValid = false;
    }
}
 
Example #11
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
    BloomFilter a = BloomFilter.createByFn(10, 20);

    BloomFilter b = BloomFilter.createByFn(10, 20);

    BloomFilter c = BloomFilter.createByFn(12, 20);

    BloomFilter d = BloomFilter.createByFn(10, 30);

    assertThat(a).isEqualTo(b);
    assertThat(a).isNotEqualTo(c);
    assertThat(a).isNotEqualTo(d);
    assertThat(d).isNotEqualTo(c);

    assertThat(a.hashCode()).isEqualTo(b.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(c.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(d.hashCode());
    assertThat(c.hashCode()).isNotEqualTo(d.hashCode());
}
 
Example #12
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example #13
Source File: ExpressionMessageFilter.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
public ExpressionMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData,
                               ConsumerFilterManager consumerFilterManager) {
    this.subscriptionData = subscriptionData;
    this.consumerFilterData = consumerFilterData;
    this.consumerFilterManager = consumerFilterManager;
    if (consumerFilterData == null) {
        bloomDataValid = false;
        return;
    }
    BloomFilter bloomFilter = this.consumerFilterManager.getBloomFilter();
    if (bloomFilter != null && bloomFilter.isValid(consumerFilterData.getBloomFilterData())) {
        bloomDataValid = true;
    } else {
        bloomDataValid = false;
    }
}
 
Example #14
Source File: BloomFilterTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
    BloomFilter a = BloomFilter.createByFn(10, 20);

    BloomFilter b = BloomFilter.createByFn(10, 20);

    BloomFilter c = BloomFilter.createByFn(12, 20);

    BloomFilter d = BloomFilter.createByFn(10, 30);

    assertThat(a).isEqualTo(b);
    assertThat(a).isNotEqualTo(c);
    assertThat(a).isNotEqualTo(d);
    assertThat(d).isNotEqualTo(c);

    assertThat(a.hashCode()).isEqualTo(b.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(c.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(d.hashCode());
    assertThat(c.hashCode()).isNotEqualTo(d.hashCode());
}
 
Example #15
Source File: BloomFilterTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example #16
Source File: ExpressionMessageFilter.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
public ExpressionMessageFilter(SubscriptionData subscriptionData, ConsumerFilterData consumerFilterData,
    ConsumerFilterManager consumerFilterManager) {
    this.subscriptionData = subscriptionData;
    this.consumerFilterData = consumerFilterData;
    this.consumerFilterManager = consumerFilterManager;
    if (consumerFilterData == null) {
        bloomDataValid = false;
        return;
    }
    BloomFilter bloomFilter = this.consumerFilterManager.getBloomFilter();
    if (bloomFilter != null && bloomFilter.isValid(consumerFilterData.getBloomFilterData())) {
        bloomDataValid = true;
    } else {
        bloomDataValid = false;
    }
}
 
Example #17
Source File: BloomFilterTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testEquals() {
    BloomFilter a = BloomFilter.createByFn(10, 20);

    BloomFilter b = BloomFilter.createByFn(10, 20);

    BloomFilter c = BloomFilter.createByFn(12, 20);

    BloomFilter d = BloomFilter.createByFn(10, 30);

    assertThat(a).isEqualTo(b);
    assertThat(a).isNotEqualTo(c);
    assertThat(a).isNotEqualTo(d);
    assertThat(d).isNotEqualTo(c);

    assertThat(a.hashCode()).isEqualTo(b.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(c.hashCode());
    assertThat(a.hashCode()).isNotEqualTo(d.hashCode());
    assertThat(c.hashCode()).isNotEqualTo(d.hashCode());
}
 
Example #18
Source File: BloomFilterTest.java    From rocketmq with Apache License 2.0 6 votes vote down vote up
@Test
public void testCheckFalseHit() {
    BloomFilter bloomFilter = BloomFilter.createByFn(1, 300);
    BitsArray bits = BitsArray.create(bloomFilter.getM());
    int falseHit = 0;
    for (int i = 0; i < bloomFilter.getN(); i++) {
        String str = randomString((new Random(System.nanoTime())).nextInt(127) + 10);
        int[] bitPos = bloomFilter.calcBitPositions(str);

        if (bloomFilter.checkFalseHit(bitPos, bits)) {
            falseHit++;
        }

        bloomFilter.hashTo(bitPos, bits);
    }

    assertThat(falseHit).isLessThanOrEqualTo(bloomFilter.getF() * bloomFilter.getN() / 100);
}
 
Example #19
Source File: ConsumerFilterManager.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
public ConsumerFilterManager(BrokerController brokerController) {
    this.brokerController = brokerController;
    this.bloomFilter = BloomFilter.createByFn(
        brokerController.getBrokerConfig().getMaxErrorRateOfBloomFilter(),
        brokerController.getBrokerConfig().getExpectConsumerNumUseFilter()
    );
    // then set bit map length of store config.
    brokerController.getMessageStoreConfig().setBitMapLengthConsumeQueueExt(
        this.bloomFilter.getM()
    );
}
 
Example #20
Source File: BloomFilterTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #21
Source File: BloomFilterTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #22
Source File: ConsumerFilterManager.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
public ConsumerFilterManager(BrokerController brokerController) {
    this.brokerController = brokerController;
    this.bloomFilter = BloomFilter.createByFn(
        brokerController.getBrokerConfig().getMaxErrorRateOfBloomFilter(),
        brokerController.getBrokerConfig().getExpectConsumerNumUseFilter()
    );
    // then set bit map length of store config.
    brokerController.getMessageStoreConfig().setBitMapLengthConsumeQueueExt(
        this.bloomFilter.getM()
    );
}
 
Example #23
Source File: ConsumerFilterManager.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public ConsumerFilterManager(BrokerController brokerController) {
    this.brokerController = brokerController;
    this.bloomFilter = BloomFilter.createByFn(
        brokerController.getBrokerConfig().getMaxErrorRateOfBloomFilter(),
        brokerController.getBrokerConfig().getExpectConsumerNumUseFilter()
    );
    // then set bit map length of store config.
    brokerController.getMessageStoreConfig().setBitMapLengthConsumeQueueExt(
        this.bloomFilter.getM()
    );
}
 
Example #24
Source File: BloomFilterTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #25
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #26
Source File: BloomFilterTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #27
Source File: ConsumerFilterManager.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
public ConsumerFilterManager(BrokerController brokerController) {
    this.brokerController = brokerController;
    this.bloomFilter = BloomFilter.createByFn(
        brokerController.getBrokerConfig().getMaxErrorRateOfBloomFilter(),
        brokerController.getBrokerConfig().getExpectConsumerNumUseFilter()
    );
    // then set bit map length of store config.
    brokerController.getMessageStoreConfig().setBitMapLengthConsumeQueueExt(
        this.bloomFilter.getM()
    );
}
 
Example #28
Source File: BloomFilterTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example #29
Source File: ConsumerFilterManager.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
public ConsumerFilterManager(BrokerController brokerController) {
    this.brokerController = brokerController;
    this.bloomFilter = BloomFilter.createByFn(
        brokerController.getBrokerConfig().getMaxErrorRateOfBloomFilter(),
        brokerController.getBrokerConfig().getExpectConsumerNumUseFilter()
    );
    // then set bit map length of store config.
    brokerController.getMessageStoreConfig().setBitMapLengthConsumeQueueExt(
        this.bloomFilter.getM()
    );
}
 
Example #30
Source File: ConsumerFilterManager.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
public ConsumerFilterManager(BrokerController brokerController) {
    this.brokerController = brokerController;
    this.bloomFilter = BloomFilter.createByFn(
        brokerController.getBrokerConfig().getMaxErrorRateOfBloomFilter(),
        brokerController.getBrokerConfig().getExpectConsumerNumUseFilter()
    );
    // then set bit map length of store config.
    brokerController.getMessageStoreConfig().setBitMapLengthConsumeQueueExt(
        this.bloomFilter.getM()
    );
}