|
26 | 26 | import com.esotericsoftware.kryo.io.Input;
|
27 | 27 | import com.esotericsoftware.kryo.io.Output;
|
28 | 28 | import com.esotericsoftware.kryo.util.DefaultInstantiatorStrategy;
|
| 29 | +import com.esotericsoftware.kryo.serializers.DefaultSerializers.KeySetViewSerializer; |
29 | 30 |
|
30 | 31 | import java.math.BigDecimal;
|
31 | 32 | import java.math.BigInteger;
|
|
45 | 46 | import java.util.PriorityQueue;
|
46 | 47 | import java.util.TimeZone;
|
47 | 48 | import java.util.UUID;
|
| 49 | +import java.util.concurrent.ConcurrentHashMap; |
48 | 50 | import java.util.concurrent.atomic.AtomicBoolean;
|
49 | 51 | import java.util.concurrent.atomic.AtomicInteger;
|
50 | 52 | import java.util.concurrent.atomic.AtomicLong;
|
@@ -246,7 +248,7 @@ void testTimestampSerializer () {
|
246 | 248 | roundTrip(11, newTimestamp(-1234567, 1));
|
247 | 249 | roundTrip(14, newTimestamp(-1234567, 123_456_789));
|
248 | 250 | }
|
249 |
| - |
| 251 | + |
250 | 252 | private java.sql.Timestamp newTimestamp(long time, int nanos) {
|
251 | 253 | java.sql.Timestamp t = new java.sql.Timestamp(time);
|
252 | 254 | t.setNanos(nanos);
|
@@ -452,6 +454,53 @@ void testEmptyPriorityQueueSubclass () {
|
452 | 454 | roundTrip(3, queue);
|
453 | 455 | }
|
454 | 456 |
|
| 457 | + @Test |
| 458 | + void testConcurrentHashMapKeySetView () { |
| 459 | + ConcurrentHashMap.KeySetView<Integer, Boolean> set = ConcurrentHashMap.newKeySet(); |
| 460 | + set.add(12); |
| 461 | + kryo.register(ConcurrentHashMap.KeySetView.class, new KeySetViewSerializer()); |
| 462 | + kryo.register(ConcurrentHashMap.class); |
| 463 | + roundTrip(9, set); |
| 464 | + } |
| 465 | + |
| 466 | + @Test |
| 467 | + void testConcurrentHashMapKeySetViewFromExistingMap () { |
| 468 | + ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>(); |
| 469 | + |
| 470 | + map.put("1", 1); |
| 471 | + map.put("2", 2); |
| 472 | + |
| 473 | + ConcurrentHashMap.KeySetView<String, Integer> set = map.keySet(4); |
| 474 | + |
| 475 | + kryo.register(ConcurrentHashMap.KeySetView.class, new KeySetViewSerializer()); |
| 476 | + kryo.register(ConcurrentHashMap.class); |
| 477 | + roundTrip(15, set); |
| 478 | + } |
| 479 | + |
| 480 | + @Test |
| 481 | + void testEmptyConcurrentHashMapKeySetView () { |
| 482 | + ConcurrentHashMap.KeySetView set = ConcurrentHashMap.newKeySet(); |
| 483 | + kryo.register(ConcurrentHashMap.KeySetView.class, new KeySetViewSerializer()); |
| 484 | + kryo.register(ConcurrentHashMap.class); |
| 485 | + roundTrip(5, set); |
| 486 | + } |
| 487 | + |
| 488 | + @Test |
| 489 | + void testConcurrentHashMapKeySetViewCopy () { |
| 490 | + ConcurrentHashMap<String, Integer> map = new ConcurrentHashMap<>(); |
| 491 | + |
| 492 | + map.put("1", 1); |
| 493 | + map.put("2", 2); |
| 494 | + |
| 495 | + ConcurrentHashMap.KeySetView<String, Integer> set = map.keySet(4); |
| 496 | + |
| 497 | + kryo.register(ConcurrentHashMap.KeySetView.class, new KeySetViewSerializer()); |
| 498 | + kryo.register(ConcurrentHashMap.class); |
| 499 | + ConcurrentHashMap.KeySetView<String, Integer> copy = kryo.copy(set); |
| 500 | + assertEquals(set.iterator().next(), copy.iterator().next()); |
| 501 | + assertEquals(set.getMappedValue(), copy.getMappedValue()); |
| 502 | + } |
| 503 | + |
455 | 504 | @Test
|
456 | 505 | void testCalendar () {
|
457 | 506 | kryo.setRegistrationRequired(false);
|
@@ -589,7 +638,7 @@ void testURISerializer () throws Exception {
|
589 | 638 | @Test
|
590 | 639 | void testUUIDSerializer () {
|
591 | 640 | kryo.register(UUID.class, new DefaultSerializers.UUIDSerializer());
|
592 |
| - |
| 641 | + |
593 | 642 | roundTrip(17, UUID.fromString("e58ed763-928c-4155-bee9-fdbaaadc15f3"));
|
594 | 643 | }
|
595 | 644 |
|
|
0 commit comments