Skip to content

Commit

Permalink
GH-42165:[Java] Update Unit Tests for Memory Module (#42161)
Browse files Browse the repository at this point in the history
### Rationale for this change

### What changes are included in this PR?

I followed the format for the other sub-issues of GH-41680 (flight, etc.) 

### Are these changes tested?
Yes. This is actually migration of tests from JUnit 4 to JUnit 5. They  pass. 

### Are there any user-facing changes?

* GitHub Issue: #41680
* GitHub Issue: #42165

Authored-by: Ed and Gravy <me@emangini.com>
Signed-off-by: David Li <li.davidm96@gmail.com>
  • Loading branch information
edtbl76 authored Jun 17, 2024
1 parent 4170a19 commit ad4ff47
Show file tree
Hide file tree
Showing 24 changed files with 398 additions and 394 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
*/
package org.apache.arrow.memory;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.fail;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

public class TestAccountant {

Expand Down Expand Up @@ -56,7 +57,7 @@ public void run() {
}
} catch (Exception ex) {
ex.printStackTrace();
Assert.fail(ex.getMessage());
fail(ex.getMessage());
}
}
};
Expand Down Expand Up @@ -151,7 +152,7 @@ private void ensureAccurateReservations(Accountant outsideParent) {
assertEquals(2, parent.getAllocatedMemory());

boolean withinLimit = child.forceAllocate(10);
assertEquals(false, withinLimit);
assertFalse(withinLimit);

// at new limit
assertEquals(child.getAllocatedMemory(), 11);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package org.apache.arrow.memory;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Test;
import org.junit.jupiter.api.Test;

/** Test cases for {@link AllocationManager}. */
public class TestAllocationManager {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
*/
package org.apache.arrow.memory;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
Expand All @@ -30,35 +30,35 @@
import java.nio.ByteOrder;
import java.util.Arrays;
import org.apache.arrow.memory.util.Float16;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.LoggerFactory;

public class TestArrowBuf {

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testSliceOutOfBoundsLength_RaisesIndexOutOfBoundsException() {
try (BufferAllocator allocator = new RootAllocator(128);
ArrowBuf buf = allocator.buffer(2)) {
assertEquals(2, buf.capacity());
buf.slice(0, 3);
assertThrows(IndexOutOfBoundsException.class, () -> buf.slice(0, 3));
}
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testSliceOutOfBoundsIndexPlusLength_RaisesIndexOutOfBoundsException() {
try (BufferAllocator allocator = new RootAllocator(128);
ArrowBuf buf = allocator.buffer(2)) {
assertEquals(2, buf.capacity());
buf.slice(1, 2);
assertThrows(IndexOutOfBoundsException.class, () -> buf.slice(1, 2));
}
}

@Test(expected = IndexOutOfBoundsException.class)
@Test
public void testSliceOutOfBoundsIndex_RaisesIndexOutOfBoundsException() {
try (BufferAllocator allocator = new RootAllocator(128);
ArrowBuf buf = allocator.buffer(2)) {
assertEquals(2, buf.capacity());
buf.slice(3, 0);
assertThrows(IndexOutOfBoundsException.class, () -> buf.slice(3, 0));
}
}

Expand Down Expand Up @@ -143,7 +143,7 @@ public void testEnabledAssertion() {
((Logger) LoggerFactory.getLogger("org.apache.arrow")).setLevel(Level.TRACE);
try (BufferAllocator allocator = new RootAllocator(128)) {
allocator.buffer(2);
Exception e = assertThrows(IllegalStateException.class, () -> allocator.close());
Exception e = assertThrows(IllegalStateException.class, allocator::close);
assertFalse(e.getMessage().contains("event log for:"));
} finally {
((Logger) LoggerFactory.getLogger("org.apache.arrow")).setLevel(null);
Expand All @@ -164,15 +164,15 @@ public void testEnabledHistoricalLog() {
allocator.buffer(2);
Exception e = assertThrows(IllegalStateException.class, allocator::close);
assertTrue(
"Exception had the following message: " + e.getMessage(),
e.getMessage().contains("event log for:")); // JDK8, JDK11
e.getMessage().contains("event log for:"), // JDK8, JDK11
"Exception had the following message: " + e.getMessage());
} finally {
fieldDebug.set(null, false);
}
} catch (Exception e) {
assertTrue(
"Exception had the following toString(): " + e.toString(),
e.toString().contains("java.lang.NoSuchFieldException: modifiers")); // JDK17+
e.toString().contains("java.lang.NoSuchFieldException: modifiers"),
"Exception had the following toString(): " + e); // JDK17+
} finally {
((Logger) LoggerFactory.getLogger("org.apache.arrow")).setLevel(null);
}
Expand Down
Loading

0 comments on commit ad4ff47

Please sign in to comment.