|
1 | 1 | package org.apache.solr.search.facet;
|
2 | 2 |
|
| 3 | +import java.io.ByteArrayInputStream; |
| 4 | +import java.io.ByteArrayOutputStream; |
| 5 | +import java.io.IOException; |
| 6 | +import java.io.InputStream; |
| 7 | + |
3 | 8 | import org.apache.lucene.util.LuceneTestCase;
|
| 9 | +import org.apache.solr.common.util.JavaBinCodec; |
| 10 | +import org.apache.solr.common.util.SimpleOrderedMap; |
4 | 11 | import org.junit.Test;
|
5 | 12 |
|
6 | 13 | public class BitmapFrequencyCounterTest extends LuceneTestCase {
|
@@ -293,4 +300,54 @@ public void givenSize4_whenMergingValues() {
|
293 | 300 | assertEquals(decoded[14], 0);
|
294 | 301 | assertEquals(decoded[15], 1);
|
295 | 302 | }
|
| 303 | + |
| 304 | + @Test |
| 305 | + public void testSerialization() throws IOException { |
| 306 | + BitmapFrequencyCounter x = new BitmapFrequencyCounter(2); |
| 307 | + |
| 308 | + x.add(101); |
| 309 | + |
| 310 | + x.add(102); |
| 311 | + x.add(102); |
| 312 | + x.add(202); |
| 313 | + x.add(202); |
| 314 | + |
| 315 | + x.add(103); |
| 316 | + x.add(103); |
| 317 | + x.add(103); |
| 318 | + x.add(203); |
| 319 | + x.add(203); |
| 320 | + x.add(203); |
| 321 | + x.add(303); |
| 322 | + x.add(303); |
| 323 | + x.add(303); |
| 324 | + |
| 325 | + JavaBinCodec codec = new JavaBinCodec(); |
| 326 | + |
| 327 | + ByteArrayOutputStream out = new ByteArrayOutputStream(); |
| 328 | + codec.marshal(x.serialize(), out); |
| 329 | + |
| 330 | + InputStream in = new ByteArrayInputStream(out.toByteArray()); |
| 331 | + BitmapFrequencyCounter y = new BitmapFrequencyCounter(2); |
| 332 | + y.deserialize((SimpleOrderedMap<Object>) codec.unmarshal(in)); |
| 333 | + |
| 334 | + assertEquals(y.getBitmaps().length, 2); |
| 335 | + |
| 336 | + assertTrue(y.getBitmaps()[0].contains(101)); |
| 337 | + assertFalse(y.getBitmaps()[1].contains(101)); |
| 338 | + |
| 339 | + assertFalse(y.getBitmaps()[0].contains(102)); |
| 340 | + assertTrue(y.getBitmaps()[1].contains(102)); |
| 341 | + assertFalse(y.getBitmaps()[0].contains(202)); |
| 342 | + assertTrue(y.getBitmaps()[1].contains(202)); |
| 343 | + |
| 344 | + assertTrue(y.getBitmaps()[0].contains(103)); |
| 345 | + assertTrue(y.getBitmaps()[1].contains(103)); |
| 346 | + assertTrue(y.getBitmaps()[0].contains(203)); |
| 347 | + assertTrue(y.getBitmaps()[1].contains(203)); |
| 348 | + assertTrue(y.getBitmaps()[0].contains(303)); |
| 349 | + assertTrue(y.getBitmaps()[1].contains(303)); |
| 350 | + |
| 351 | + assertTrue(y.getOverflow().isEmpty()); |
| 352 | + } |
296 | 353 | }
|
0 commit comments