2 * Copyright 2017-present Open Networking Foundation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package io.atomix.utils.serializer;
18 import com.esotericsoftware.kryo.io.Output;
19 import org.junit.Before;
20 import org.junit.Test;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertTrue;
25 public class KryoOutputPoolTest {
27 private KryoOutputPool kryoOutputPool;
30 public void setUp() throws Exception {
31 kryoOutputPool = new KryoOutputPool();
35 public void discardOutput() {
36 final Output[] result = new Output[2];
37 kryoOutputPool.run(output -> {
40 }, KryoOutputPool.MAX_POOLED_BUFFER_SIZE + 1);
41 kryoOutputPool.run(output -> {
45 assertTrue(result[0] != result[1]);
49 public void recycleOutput() {
50 final ByteArrayOutput[] result = new ByteArrayOutput[2];
51 kryoOutputPool.run(output -> {
53 assertEquals(Integer.BYTES, output.position());
57 assertEquals(0, result[0].position());
58 assertEquals(0, result[0].getByteArrayOutputStream().size());
59 kryoOutputPool.run(output -> {
60 assertEquals(0, output.position());
64 assertTrue(result[0] == result[1]);