kopia lustrzana https://github.com/onthegomap/planetiler
Run nested tests (#218)
rodzic
9062e6b79b
commit
a8bec7a56d
|
@ -1,5 +1,6 @@
|
|||
package com.onthegomap.planetiler.collection;
|
||||
|
||||
import static com.onthegomap.planetiler.util.Exceptions.throwFatalException;
|
||||
import static java.nio.file.StandardOpenOption.CREATE;
|
||||
import static java.nio.file.StandardOpenOption.READ;
|
||||
import static java.nio.file.StandardOpenOption.WRITE;
|
||||
|
@ -57,7 +58,7 @@ class ArrayLongLongMapMmap implements LongLongMap.ParallelWrites {
|
|||
private final ConcurrentHashMap<Integer, Segment> writeBuffers = new ConcurrentHashMap<>();
|
||||
private final Semaphore activeSegments;
|
||||
private final BitSet usedSegments = new BitSet();
|
||||
FileChannel writeChannel;
|
||||
private FileChannel writeChannel;
|
||||
private MappedByteBuffer[] segmentsArray;
|
||||
private FileChannel readChannel = null;
|
||||
private volatile int tail = 0;
|
||||
|
@ -161,11 +162,19 @@ class ArrayLongLongMapMmap implements LongLongMap.ParallelWrites {
|
|||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
if (segmentsArray != null) {
|
||||
ByteBufferUtil.free(segmentsArray);
|
||||
segmentsArray = null;
|
||||
}
|
||||
if (writeChannel != null) {
|
||||
writeChannel.close();
|
||||
writeChannel = null;
|
||||
}
|
||||
if (readChannel != null) {
|
||||
readChannel.close();
|
||||
readChannel = null;
|
||||
FileUtils.delete(path);
|
||||
}
|
||||
FileUtils.delete(path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -226,9 +235,9 @@ class ArrayLongLongMapMmap implements LongLongMap.ParallelWrites {
|
|||
return result.get();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException(e);
|
||||
return throwFatalException(e);
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
return throwFatalException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,7 +247,7 @@ class ArrayLongLongMapMmap implements LongLongMap.ParallelWrites {
|
|||
activeSegments.acquire();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException(e);
|
||||
throwFatalException(e);
|
||||
}
|
||||
synchronized (usedSegments) {
|
||||
usedSegments.set(id);
|
||||
|
@ -254,11 +263,11 @@ class ArrayLongLongMapMmap implements LongLongMap.ParallelWrites {
|
|||
activeSegments.release();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException(e);
|
||||
throwFatalException(e);
|
||||
} catch (IOException e) {
|
||||
throw new UncheckedIOException(e);
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
throwFatalException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||
import com.onthegomap.planetiler.reader.osm.OsmReader;
|
||||
import com.onthegomap.planetiler.util.Format;
|
||||
import com.onthegomap.planetiler.util.ResourceUsage;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
@ -23,6 +25,11 @@ public abstract class LongLongMapTest {
|
|||
this.sequential = createSequentialWriter(path);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void closeSequentialWriter() throws IOException {
|
||||
this.sequential.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingValue() {
|
||||
assertEquals(Long.MIN_VALUE, sequential.get(0));
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.IOException;
|
|||
import java.nio.file.Path;
|
||||
import java.util.concurrent.BrokenBarrierException;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Timeout;
|
||||
|
@ -19,7 +20,7 @@ public abstract class ParallelLongLongMapTest extends LongLongMapTest {
|
|||
|
||||
@Test
|
||||
@Timeout(10)
|
||||
void testWaitForBothWritersToClose() throws InterruptedException {
|
||||
void testWaitForBothWritersToClose() {
|
||||
var writer1 = parallel.newWriter();
|
||||
var writer2 = parallel.newWriter();
|
||||
writer1.put(0, 1);
|
||||
|
@ -107,6 +108,11 @@ public abstract class ParallelLongLongMapTest extends LongLongMapTest {
|
|||
this.parallel = create(path);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void closeParallelWriter() throws IOException {
|
||||
this.parallel.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected LongLongMap.SequentialWrites createSequentialWriter(Path path) {
|
||||
var sequentialMap = create(path);
|
||||
|
|
6
pom.xml
6
pom.xml
|
@ -201,6 +201,12 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M6</version>
|
||||
<!-- by default surefire excludes tests on nested classes https://github.com/junit-team/junit5/issues/1377 -->
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude/>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
Ładowanie…
Reference in New Issue