Skip to content

Commit c69e912

Browse files
committed
Redone changes
1 parent 77b6406 commit c69e912

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/test/java/com/mapcode/EncodeDecodeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ private static void doEncodeDecode(final long seed) throws InterruptedException
6060
final AtomicInteger errors = new AtomicInteger(0);
6161
final AtomicInteger tasks = new AtomicInteger(0);
6262

63-
final int threads = Runtime.getRuntime().availableProcessors();
63+
final int threads = Runtime.getRuntime().availableProcessors() * 2;
6464
LOG.info("encodeDecodeTest: Starting {} threads...", threads);
6565
final ExecutorService executor = Executors.newFixedThreadPool(threads);
6666

src/test/java/com/mapcode/ReferenceFileTest.java

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public class ReferenceFileTest {
5757
private static final String BOUNDARIES_REFERENCE_FILE = "/boundaries.txt";
5858
private static final String BOUNDARIES_REFERENCE_FILE_HP = "/boundaries_hp.txt";
5959

60-
private static final int LOG_LINE_EVERY = 25000;
60+
private static final int LOG_LINE_EVERY = 10000;
6161

6262
@SuppressWarnings("JUnitTestMethodWithNoAssertions")
6363
@Test
@@ -117,7 +117,7 @@ private static void checkFile(@Nonnull final String baseFileName) throws Excepti
117117
final AtomicInteger errors = new AtomicInteger(0);
118118
final AtomicInteger tasks = new AtomicInteger(0);
119119

120-
final int threads = Runtime.getRuntime().availableProcessors();
120+
final int threads = Runtime.getRuntime().availableProcessors() * 2;
121121
LOG.info("checkFile: Starting {} threads...", threads);
122122
final ExecutorService executor = Executors.newFixedThreadPool(threads);
123123

@@ -131,18 +131,16 @@ private static void checkFile(@Nonnull final String baseFileName) throws Excepti
131131
// Get next record.
132132
@Nonnull final ReferenceRec reference = getNextReferenceRecord(chunkedFile);
133133

134-
final int count = tasks.getAndIncrement();
135-
if (((count % LOG_LINE_EVERY) == 0)) {
136-
LOG.debug("checkFile: #{}, file={}", count, chunkedFile.fileName);
137-
LOG.debug("checkFile: lat/lon = {}", reference.point);
138-
LOG.debug("checkFile: expected = #{}: {}", reference.mapcodes.size(), GSON.toJson(reference.mapcodes));
139-
}
140-
141134
// Add task. This may throw an exception if the queue is full. Retry in that case.
142135
executor.execute(new Runnable() {
143136

144137
@Override
145138
public void run() {
139+
final int count = tasks.getAndIncrement();
140+
if (((count % LOG_LINE_EVERY) == 0)) {
141+
LOG.info("checkFile: #{}, file={}", count, chunkedFile.fileName);
142+
}
143+
146144
// Encode lat/lon to series of mapcodes and check the resulting mapcodes.
147145
final List<Mapcode> results = MapcodeCodec.encode(
148146
reference.point.getLatDeg(), reference.point.getLonDeg());
@@ -227,10 +225,10 @@ public void run() {
227225
}
228226
}
229227

230-
// Check distance of decoded point to reference point.
231-
for (final MapcodeRec mapcodeRec : reference.mapcodes) {
232-
//noinspection NestedTryStatement
233-
try {
228+
try {
229+
// Check distance of decoded point to reference point.
230+
for (final MapcodeRec mapcodeRec : reference.mapcodes) {
231+
//noinspection NestedTryStatement
234232
final Point result = MapcodeCodec.decode(mapcodeRec.mapcode, mapcodeRec.territory);
235233
final long distanceNm = (long) (Point.distanceInMeters(reference.point, result) * 1000000.0);
236234
synchronized (deltaNm) {
@@ -246,11 +244,11 @@ public void run() {
246244
((double) distanceNm) / 1000000.0, ((double) maxDeltaNm) / 1000000.0);
247245
errors.incrementAndGet();
248246
}
249-
} catch (final UnknownMapcodeException unknownMapcodeException) {
250-
LOG.error("Mapcode {} {} was generated for point {}, but cannot be decoded.",
251-
mapcodeRec.territory, mapcodeRec.mapcode, reference.point);
252-
errors.incrementAndGet();
253247
}
248+
} catch (final UnknownMapcodeException e) {
249+
LOG.error("Mapcode was generated for point {}, but cannot be decoded, msg={}",
250+
reference.point, e.getMessage());
251+
errors.incrementAndGet();
254252
}
255253
}
256254
});
@@ -264,7 +262,7 @@ public void run() {
264262
executor.awaitTermination(60, TimeUnit.SECONDS);
265263
assertEquals(0, errors.get());
266264
assertEquals("Found errors", 0, errors.get());
267-
LOG.debug("checkFile: Maximum delta for this testset = {}m, executed {} tasks", ((double) deltaNm.get()) / 1000000.0, tasks);
265+
LOG.info("checkFile: Maximum delta for this testset = {}m, executed {} tasks", ((double) deltaNm.get()) / 1000000.0, tasks);
268266
}
269267

270268
private static class MapcodeRec {

0 commit comments

Comments
 (0)