Search in sources :

Example 16 with BitsArray

use of org.apache.rocketmq.filter.util.BitsArray in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BitsArrayTest method testXor.

@Test
public void testXor() {
    BitsArray bitsArray = gen(bitLength);
    boolean val = bitsArray.getBit(2);
    bitsArray.xor(2, !val);
    assertThat(bitsArray.getBit(2)).isTrue();
}
Also used : BitsArray(org.apache.rocketmq.filter.util.BitsArray) Test(org.junit.Test)

Example 17 with BitsArray

use of org.apache.rocketmq.filter.util.BitsArray in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BitsArrayTest method testAndOr.

@Test
public void testAndOr() {
    BitsArray bitsArray = gen(bitLength);
    boolean val = bitsArray.getBit(2);
    if (val) {
        bitsArray.and(2, false);
        assertThat(!bitsArray.getBit(2)).isTrue();
    } else {
        bitsArray.or(2, true);
        assertThat(bitsArray.getBit(2)).isTrue();
    }
}
Also used : BitsArray(org.apache.rocketmq.filter.util.BitsArray) Test(org.junit.Test)

Example 18 with BitsArray

use of org.apache.rocketmq.filter.util.BitsArray in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.

the class BitsArrayTest method testNot.

@Test
public void testNot() {
    BitsArray bitsArray = gen(bitLength);
    BitsArray backUp = bitsArray.clone();
    bitsArray.not(2);
    bitsArray.xor(backUp);
    assertThat(bitsArray.getBit(2)).isTrue();
}
Also used : BitsArray(org.apache.rocketmq.filter.util.BitsArray) Test(org.junit.Test)

Example 19 with BitsArray

use of org.apache.rocketmq.filter.util.BitsArray 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();
                }
            }
        }
    }
}
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 20 with BitsArray

use of org.apache.rocketmq.filter.util.BitsArray in project rocketmq by apache.

the class BitsArrayTest method testAndOr.

@Test
public void testAndOr() {
    BitsArray bitsArray = gen(bitLength);
    boolean val = bitsArray.getBit(2);
    if (val) {
        bitsArray.and(2, false);
        assertThat(!bitsArray.getBit(2)).isTrue();
    } else {
        bitsArray.or(2, true);
        assertThat(bitsArray.getBit(2)).isTrue();
    }
}
Also used : BitsArray(org.apache.rocketmq.filter.util.BitsArray) Test(org.junit.Test)

Aggregations

BitsArray (org.apache.rocketmq.filter.util.BitsArray)26 Test (org.junit.Test)22 BloomFilter (org.apache.rocketmq.filter.util.BloomFilter)8 HashMap (java.util.HashMap)4 BrokerConfig (org.apache.rocketmq.common.BrokerConfig)4 DispatchRequest (org.apache.rocketmq.store.DispatchRequest)4 Random (java.util.Random)2