Skip to content

Commit

Permalink
Merge 003ac4c into 9062e6b
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry authored May 9, 2022
2 parents 9062e6b + 003ac4c commit 965fb76
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -161,11 +162,19 @@ public long estimateMemoryUsageBytes() {

@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);
}

/**
Expand Down Expand Up @@ -226,9 +235,9 @@ ByteBuffer await() {
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);
}
}

Expand All @@ -238,7 +247,7 @@ void allocate() {
activeSegments.acquire();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new RuntimeException(e);
throwFatalException(e);
}
synchronized (usedSegments) {
usedSegments.set(id);
Expand All @@ -254,11 +263,11 @@ void flushToDisk() {
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);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
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;
Expand All @@ -23,6 +25,11 @@ public void setupSequentialWriter(@TempDir Path path) {
this.sequential = createSequentialWriter(path);
}

@AfterEach
public void closeSequentialWriter() throws IOException {
this.sequential.close();
}

@Test
public void missingValue() {
assertEquals(Long.MIN_VALUE, sequential.get(0));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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;
Expand All @@ -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);
Expand Down Expand Up @@ -107,6 +108,11 @@ public void setupParallelWriter(@TempDir Path path) {
this.parallel = create(path);
}

@AfterEach
public void closeParallelWriter() throws IOException {
this.parallel.close();
}

@Override
protected LongLongMap.SequentialWrites createSequentialWriter(Path path) {
var sequentialMap = create(path);
Expand Down
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit 965fb76

Please sign in to comment.