Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Java 19 build #2478

Merged
merged 10 commits into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 19 # FIXME to revert

- name: Build with Maven
if: matrix.os == 'ubuntu-latest'
Expand Down
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<findbugs-jsr305.version>3.0.2</findbugs-jsr305.version>
<gdata.version>1.41.1_1</gdata.version>
<graphviz-builder.version>1.0.12</graphviz-builder.version>
<groovy.version>3.0.9</groovy.version>
<groovy.version>3.0.15</groovy.version>
<guava.version>31.1-jre</guava.version>
<jackson.version>2.14.1</jackson.version>
<jackson-databind.version>2.14.1</jackson-databind.version>
Expand All @@ -119,7 +119,7 @@
<maven.core.version>3.8.5</maven.core.version>
<maven.plugin.annotations.version>3.6.0</maven.plugin.annotations.version>
<mfl.version>0.5.9</mfl.version>
<mockito.version>4.4.0</mockito.version>
<mockito.version>5.1.1</mockito.version>
<nativelibloader.version>2.4.0</nativelibloader.version>
<poi.version>5.2.3</poi.version>
<rdf4j.version>4.2.2</rdf4j.version>
Expand All @@ -137,6 +137,9 @@
<zstdjni.version>1.5.2-5</zstdjni.version>

<powsyblmathnative.version>1.2.1</powsyblmathnative.version>

<!-- FIXME to remove when updating to parent v9 -->
<maven.jacoco.version>0.8.8</maven.jacoco.version>
</properties>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* Copyright (c) 2023, RTE (http://www.rte-france.com)
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package com.powsybl.timeseries;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.AfterEach;

import java.nio.file.StandardOpenOption;
import java.nio.channels.FileChannel;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Path;

import java.util.List;
import java.util.ArrayList;

/**
* @author Jon Harper <jon.harper at rte-france.com>
*/
abstract class AbstractBigBufferTest {

private Path tempdir;
protected List<FileChannel> channels;

protected ByteBuffer testAllocator(int capacity) {
try {
FileChannel channel = FileChannel.open(
tempdir.resolve(Integer.toString(channels.size())),
StandardOpenOption.READ, StandardOpenOption.WRITE,
StandardOpenOption.CREATE_NEW, StandardOpenOption.SPARSE,
StandardOpenOption.DELETE_ON_CLOSE);
channels.add(channel);
ByteBuffer bytebuffer = channel.map(FileChannel.MapMode.PRIVATE, 0, capacity);
return bytebuffer;
} catch (Exception e) {
throw new RuntimeException("error in allocator test", e);
}
}

@BeforeEach
void before() throws Exception {
tempdir = Files.createTempDirectory("powsybltimeseriestest");
channels = new ArrayList<>();
}

@AfterEach
void after() throws Exception {
for (FileChannel channel : channels) {
channel.close();
}
Files.delete(tempdir);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jonenst On Windows test failed because directory is not empty. So a real file has been created on the file system even in private map mode.

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,19 @@
*/
package com.powsybl.timeseries;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.nio.ByteBuffer;
import java.nio.DoubleBuffer;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;

/**
* @author Jon Harper <jon.harper at rte-france.com>
*/
class BigDoubleBufferTest {
class BigDoubleBufferTest extends AbstractBigBufferTest {

private static final int BUFFER_SIZE_DOUBLES = 1 << 27;

private int allocatorCount;

private ByteBuffer testDoubleAllocator(int capacity) {
allocatorCount++;
ByteBuffer mockbyte = Mockito.mock(ByteBuffer.class);
DoubleBuffer mockdouble = Mockito.mock(DoubleBuffer.class);
when(mockbyte.asDoubleBuffer()).thenReturn(mockdouble);
Map<Integer, Double> map = new HashMap<>();
when(mockdouble.put(anyInt(), anyDouble())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
DoubleBuffer mock = (DoubleBuffer) invocation.getMock();
map.put((int) args[0], (double) args[1]);
return mock;
});
when(mockdouble.get(anyInt())).thenAnswer(invocation -> {
return map.get(invocation.getArguments()[0]);
});
return mockbyte;
}

@BeforeEach
void before() {
allocatorCount = 0;
}

private void bufferTester(long size) {
BigDoubleBuffer buffer = new BigDoubleBuffer(this::testDoubleAllocator, size);
BigDoubleBuffer buffer = new BigDoubleBuffer(this::testAllocator, size);
//Simple writes at the begining
for (int i = 0; i < 10; i++) {
buffer.put(i, i);
Expand Down Expand Up @@ -83,36 +50,36 @@ private void bufferTester(long size) {
@Test
void testSimple() {
bufferTester(10);
assertEquals(1, allocatorCount);
assertEquals(1, channels.size());
}

@Test
void testMultipleBuffers() {
bufferTester(200000000);
assertEquals(2, allocatorCount);
assertEquals(2, channels.size());
}

@Test
void testHuge() {
bufferTester(10000000000L);
assertEquals(75, allocatorCount);
assertEquals(75, channels.size());
}

@Test
void testSizeBufferMinus1() {
bufferTester(BUFFER_SIZE_DOUBLES - 1);
assertEquals(1, allocatorCount);
assertEquals(1, channels.size());
}

@Test
void testSizeBufferExact() {
bufferTester(BUFFER_SIZE_DOUBLES);
assertEquals(1, allocatorCount);
assertEquals(1, channels.size());
}

@Test
void testSizeBufferPlus1() {
bufferTester(BUFFER_SIZE_DOUBLES + 1);
assertEquals(2, allocatorCount);
assertEquals(2, channels.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,53 +6,19 @@
*/
package com.powsybl.timeseries;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.util.HashMap;
import java.util.Map;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.when;

/**
* @author Jon Harper <jon.harper at rte-france.com>
*/
class BigStringBufferTest {
class BigStringBufferTest extends AbstractBigBufferTest {

private static final int BUFFER_SIZE_INTS = 1 << 28;

private int allocatorCount;

private ByteBuffer testStringAllocator(int capacity) {
allocatorCount++;
ByteBuffer mockbyte = Mockito.mock(ByteBuffer.class);
IntBuffer mockint = Mockito.mock(IntBuffer.class);
when(mockbyte.asIntBuffer()).thenReturn(mockint);
Map<Integer, Integer> map = new HashMap<>();
when(mockint.put(anyInt(), anyInt())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
IntBuffer mock = (IntBuffer) invocation.getMock();
map.put((int) args[0], (int) args[1]);
return mock;
});
when(mockint.get(anyInt())).thenAnswer(invocation -> {
return map.get(invocation.getArguments()[0]);
});
return mockbyte;
}

@BeforeEach
void before() {
allocatorCount = 0;
}

private void bufferTester(long size) {
BigStringBuffer buffer = new BigStringBuffer(this::testStringAllocator, size);
BigStringBuffer buffer = new BigStringBuffer(this::testAllocator, size);
//Simple writes at the begining
for (int i = 0; i < 10; i++) {
buffer.putString(i, Integer.toString(i));
Expand Down Expand Up @@ -84,36 +50,36 @@ private void bufferTester(long size) {
@Test
void testSimple() {
bufferTester(10);
assertEquals(1, allocatorCount);
assertEquals(1, channels.size());
}

@Test
void testMultipleBuffers() {
bufferTester(400000000);
assertEquals(2, allocatorCount);
assertEquals(2, channels.size());
}

@Test
void testHuge() {
bufferTester(10000000000L);
assertEquals(38, allocatorCount);
assertEquals(38, channels.size());
}

@Test
void testSizeBufferMinus1() {
bufferTester(BUFFER_SIZE_INTS - 1);
assertEquals(1, allocatorCount);
assertEquals(1, channels.size());
}

@Test
void testSizeBufferExact() {
bufferTester(BUFFER_SIZE_INTS);
assertEquals(1, allocatorCount);
assertEquals(1, channels.size());
}

@Test
void testSizeBufferPlus1() {
bufferTester(BUFFER_SIZE_INTS + 1);
assertEquals(2, allocatorCount);
assertEquals(2, channels.size());
}
}