use of org.apache.rocketmq.filter.util.BitsArray in project rocketmq by apache.
the class BitsArrayTest method testSet.
@Test
public void testSet() {
BitsArray bitsArray = gen(bitLength);
BitsArray backUp = bitsArray.clone();
boolean val = bitsArray.getBit(2);
bitsArray.setBit(2, !val);
bitsArray.xor(backUp);
assertThat(bitsArray.getBit(2)).isTrue();
}
use of org.apache.rocketmq.filter.util.BitsArray in project rocketmq by apache.
the class BloomFilterTest method testHashTo.
@Test
public void testHashTo() {
String cid = "CID_abc_efg";
BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);
BitsArray bits = BitsArray.create(bloomFilter.getM());
int[] bitPos = bloomFilter.calcBitPositions(cid);
bloomFilter.hashTo(cid, bits);
for (int bit : bitPos) {
assertThat(bits.getBit(bit)).isTrue();
}
}
use of org.apache.rocketmq.filter.util.BitsArray in project rocketmq by apache.
the class BloomFilterTest method testIsHit.
@Test
public void testIsHit() {
String cid = "CID_abc_efg";
String cid2 = "CID_abc_123";
BloomFilter bloomFilter = BloomFilter.createByFn(10, 20);
BitsArray bits = BitsArray.create(bloomFilter.getM());
bloomFilter.hashTo(cid, bits);
assertThat(bloomFilter.isHit(cid, bits)).isTrue();
assertThat(!bloomFilter.isHit(cid2, bits)).isTrue();
bloomFilter.hashTo(cid2, bits);
assertThat(bloomFilter.isHit(cid, bits)).isTrue();
assertThat(bloomFilter.isHit(cid2, bits)).isTrue();
}
use of org.apache.rocketmq.filter.util.BitsArray in project rocketmq by apache.
the class CommitLogDispatcherCalcBitMapTest method testDispatch_filterDataIllegal.
@Test
public void testDispatch_filterDataIllegal() {
BrokerConfig brokerConfig = new BrokerConfig();
brokerConfig.setEnableCalcFilterBitMap(true);
ConsumerFilterManager filterManager = new ConsumerFilterManager();
filterManager.register("topic0", "CID_0", "a is not null and a >= 5", ExpressionType.SQL92, System.currentTimeMillis());
filterManager.register("topic0", "CID_1", "a is not null and a >= 15", ExpressionType.SQL92, System.currentTimeMillis());
ConsumerFilterData nullExpression = filterManager.get("topic0", "CID_0");
nullExpression.setExpression(null);
nullExpression.setCompiledExpression(null);
ConsumerFilterData nullBloomData = filterManager.get("topic0", "CID_1");
nullBloomData.setBloomFilterData(null);
CommitLogDispatcherCalcBitMap calcBitMap = new CommitLogDispatcherCalcBitMap(brokerConfig, filterManager);
for (int i = 0; i < 1; 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 bitsArray = BitsArray.create(dispatchRequest.getBitMap(), filterManager.getBloomFilter().getM());
for (int j = 0; j < bitsArray.bitLength(); j++) {
assertThat(bitsArray.getBit(j)).isFalse();
}
}
}
use of org.apache.rocketmq.filter.util.BitsArray in project rocketmq-rocketmq-all-4.1.0-incubating by lirenzuo.
the class BitsArrayTest method testSet.
@Test
public void testSet() {
BitsArray bitsArray = gen(bitLength);
BitsArray backUp = bitsArray.clone();
boolean val = bitsArray.getBit(2);
bitsArray.setBit(2, !val);
bitsArray.xor(backUp);
assertThat(bitsArray.getBit(2)).isTrue();
}
Aggregations