]> git.proxmox.com Git - ceph.git/blame - ceph/src/arrow/java/memory/memory-netty/src/test/java/org/apache/arrow/memory/TestEmptyArrowBuf.java
import quincy 17.2.0
[ceph.git] / ceph / src / arrow / java / memory / memory-netty / src / test / java / org / apache / arrow / memory / TestEmptyArrowBuf.java
CommitLineData
1d09f67e
TL
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package org.apache.arrow.memory;
19
20import static org.junit.Assert.assertEquals;
21
22import org.junit.AfterClass;
23import org.junit.BeforeClass;
24import org.junit.Test;
25
26import io.netty.buffer.PooledByteBufAllocatorL;
27
28public class TestEmptyArrowBuf {
29
30 private static final int MAX_ALLOCATION = 8 * 1024;
31 private static RootAllocator allocator;
32
33 @BeforeClass
34 public static void beforeClass() {
35 allocator = new RootAllocator(MAX_ALLOCATION);
36 }
37
38 /** Ensure the allocator is closed. */
39 @AfterClass
40 public static void afterClass() {
41 if (allocator != null) {
42 allocator.close();
43 }
44 }
45
46 @Test
47 public void testZeroBuf() {
48 // Exercise the historical log inside the empty ArrowBuf. This is initialized statically, and there is a circular
49 // dependency between ArrowBuf and BaseAllocator, so if the initialization happens in the wrong order, the
50 // historical log will be null even though BaseAllocator.DEBUG is true.
51 allocator.getEmpty().print(new StringBuilder(), 0, BaseAllocator.Verbosity.LOG_WITH_STACKTRACE);
52 }
53
54 @Test
55 public void testEmptyArrowBuf() {
56 ArrowBuf buf = new ArrowBuf(ReferenceManager.NO_OP, null,
57 1024, new PooledByteBufAllocatorL().empty.memoryAddress());
58
59 buf.getReferenceManager().retain();
60 buf.getReferenceManager().retain(8);
61 assertEquals(1024, buf.capacity());
62 assertEquals(1, buf.getReferenceManager().getRefCount());
63 assertEquals(0, buf.getActualMemoryConsumed());
64
65 for (int i = 0; i < 10; i++) {
66 buf.setByte(i, i);
67 }
68 assertEquals(0, buf.getActualMemoryConsumed());
69 assertEquals(0, buf.getReferenceManager().getSize());
70 assertEquals(0, buf.getReferenceManager().getAccountedSize());
71 assertEquals(false, buf.getReferenceManager().release());
72 assertEquals(false, buf.getReferenceManager().release(2));
73 assertEquals(0, buf.getReferenceManager().getAllocator().getLimit());
74 assertEquals(buf, buf.getReferenceManager().transferOwnership(buf, allocator).getTransferredBuffer());
75 assertEquals(0, buf.readerIndex());
76 assertEquals(0, buf.writerIndex());
77 assertEquals(1, buf.refCnt());
78
79 ArrowBuf derive = buf.getReferenceManager().deriveBuffer(buf, 0, 100);
80 assertEquals(derive, buf);
81 assertEquals(1, buf.refCnt());
82 assertEquals(1, derive.refCnt());
83
84 buf.close();
85
86 }
87
88}