2 * Copyright 2017-2022 Open Networking Foundation and others. All rights reserved.
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 static org.junit.jupiter.api.Assertions.assertEquals;
19 import static org.junit.jupiter.api.Assertions.assertNotSame;
20 import static org.junit.jupiter.api.Assertions.assertSame;
22 import com.esotericsoftware.kryo.io.Output;
23 import org.junit.jupiter.api.Test;
25 class KryoOutputPoolTest {
26 private final KryoOutputPool kryoOutputPool = new KryoOutputPool();
29 void discardOutput() {
30 final var result = new Output[2];
31 kryoOutputPool.run(output -> {
34 }, KryoOutputPool.MAX_POOLED_BUFFER_SIZE + 1);
35 kryoOutputPool.run(output -> {
39 assertNotSame(result[0], result[1]);
43 void recycleOutput() {
44 final var result = new ByteArrayOutput[2];
45 kryoOutputPool.run(output -> {
47 assertEquals(Integer.BYTES, output.position());
51 assertEquals(0, result[0].position());
52 assertEquals(0, result[0].getByteArrayOutputStream().size());
53 kryoOutputPool.run(output -> {
54 assertEquals(0, output.position());
58 assertSame(result[0], result[1]);