|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.arrow.vector; |
| 19 | + |
| 20 | +import org.apache.arrow.memory.BufferAllocator; |
| 21 | +import org.apache.arrow.memory.OutOfMemoryException; |
| 22 | +import org.apache.arrow.memory.RootAllocator; |
| 23 | +import org.junit.After; |
| 24 | +import org.junit.Before; |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +/** |
| 28 | + * This class tests cases where we expect to receive {@link OutOfMemoryException}. |
| 29 | + */ |
| 30 | +public class TestOutOfMemoryForValueVector { |
| 31 | + |
| 32 | + private final static String EMPTY_SCHEMA_PATH = ""; |
| 33 | + |
| 34 | + private BufferAllocator allocator; |
| 35 | + |
| 36 | + @Before |
| 37 | + public void init() { |
| 38 | + allocator = new RootAllocator(200); // Start with low memory limit |
| 39 | + } |
| 40 | + |
| 41 | + @Test(expected = OutOfMemoryException.class) |
| 42 | + public void variableWidthVectorAllocateNew() { |
| 43 | + try (VarCharVector vector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator)) { |
| 44 | + vector.allocateNew(); |
| 45 | + } |
| 46 | + } |
| 47 | + |
| 48 | + @Test(expected = OutOfMemoryException.class) |
| 49 | + public void variableWidthVectorAllocateNewCustom() { |
| 50 | + try (VarCharVector vector = new VarCharVector(EMPTY_SCHEMA_PATH, allocator)) { |
| 51 | + vector.allocateNew(2342, 234); |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + @Test(expected = OutOfMemoryException.class) |
| 56 | + public void fixedWidthVectorAllocateNew() { |
| 57 | + try (IntVector vector = new IntVector(EMPTY_SCHEMA_PATH, allocator)) { |
| 58 | + vector.allocateNew(); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + @Test(expected = OutOfMemoryException.class) |
| 63 | + public void fixedWidthVectorAllocateNewCustom() { |
| 64 | + try (IntVector vector = new IntVector(EMPTY_SCHEMA_PATH, allocator)) { |
| 65 | + vector.allocateNew(2342); |
| 66 | + } |
| 67 | + } |
| 68 | + |
| 69 | + @After |
| 70 | + public void terminate() { |
| 71 | + allocator.close(); |
| 72 | + } |
| 73 | +} |
0 commit comments