|
| 1 | +package com.twitter.chill.java; |
| 2 | + |
| 3 | +import com.esotericsoftware.kryo.Kryo; |
| 4 | +import com.esotericsoftware.kryo.io.Input; |
| 5 | +import com.esotericsoftware.kryo.io.Output; |
| 6 | + |
| 7 | +import java.util.Comparator; |
| 8 | +import java.util.PriorityQueue; |
| 9 | + |
| 10 | +public class TestPriorityQueue { |
| 11 | + |
| 12 | + private static final Kryo kryo = new Kryo(); |
| 13 | + |
| 14 | + private static final PriorityQueue<String> test_priority_queue1 = |
| 15 | + new PriorityQueue<>((o1, o2) -> o1.length() - o2.length() - 1); |
| 16 | + |
| 17 | + private static final PriorityQueue<String> test_priority_queue2 = |
| 18 | + new PriorityQueue<>(new Comparator<String>() { |
| 19 | + @Override |
| 20 | + public int compare(String o1, String o2) { |
| 21 | + return o1.length() - o2.length() - 1; |
| 22 | + } |
| 23 | + }); |
| 24 | + |
| 25 | + static { |
| 26 | + test_priority_queue1.add("12345"); |
| 27 | + test_priority_queue1.add("123"); |
| 28 | + test_priority_queue1.add("12456789"); |
| 29 | + |
| 30 | + test_priority_queue2.add("12345"); |
| 31 | + test_priority_queue2.add("123"); |
| 32 | + test_priority_queue2.add("12456789"); |
| 33 | + } |
| 34 | + |
| 35 | + public static PriorityQueue<String> serializeAndDeserializeQueue1() { |
| 36 | + Output output = new Output(1000, -1); |
| 37 | + kryo.writeClassAndObject(output, test_priority_queue1); |
| 38 | + Input input = new Input(output.toBytes()); |
| 39 | + return (PriorityQueue<String>) kryo.readClassAndObject(input); |
| 40 | + } |
| 41 | + |
| 42 | + public static PriorityQueue<String> serializeAndDeserializeQueue1(Kryo kryo) { |
| 43 | + Output output = new Output(1000, -1); |
| 44 | + kryo.writeClassAndObject(output, test_priority_queue1); |
| 45 | + Input input = new Input(output.toBytes()); |
| 46 | + return (PriorityQueue<String>) kryo.readClassAndObject(input); |
| 47 | + } |
| 48 | + |
| 49 | + public static PriorityQueue<String> serializeAndDeserializeQueue2(Kryo kryo) { |
| 50 | + Output output = new Output(1000, -1); |
| 51 | + kryo.writeClassAndObject(output, test_priority_queue2); |
| 52 | + Input input = new Input(output.toBytes()); |
| 53 | + return (PriorityQueue<String>) kryo.readClassAndObject(input); |
| 54 | + } |
| 55 | +} |
0 commit comments