Skip to content

Commit efdd9da

Browse files
tzaeschkeTilmann Zäschke
andauthored
Add CI script (#16)
* CI script --------- Co-authored-by: Tilmann Zäschke <[email protected]>
1 parent b725694 commit efdd9da

File tree

5 files changed

+161
-23
lines changed

5 files changed

+161
-23
lines changed

.github/workflows/build.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: Java
2+
3+
on: [push]
4+
5+
env:
6+
time: 3
7+
time_windows: 5
8+
9+
jobs:
10+
format-check:
11+
name: Check Code Formatting
12+
continue-on-error: true
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 1
19+
- name: Check Format
20+
run: |
21+
mvn --batch-mode -Pverify-format clean compile
22+
shell: 'bash'
23+
24+
codecov:
25+
name: Codecov
26+
continue-on-error: true
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
- name: Set up JDK
32+
uses: actions/setup-java@v4
33+
with:
34+
java-version: 21
35+
distribution: 'temurin'
36+
# - name: Install dependencies
37+
# run: mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V
38+
- name: Run tests and collect coverage
39+
timeout-minutes: ${{ fromJSON(env.time) }}
40+
run: mvn -B test
41+
- name: Upload coverage reports to Codecov
42+
uses: codecov/codecov-action@v4
43+
env:
44+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
45+
46+
build:
47+
runs-on: ubuntu-latest
48+
strategy:
49+
matrix:
50+
# run different builds with the listed java versions
51+
java: [ 8, 21 ]
52+
name: "build-ubuntu Java ${{ matrix.java }}"
53+
steps:
54+
- uses: actions/checkout@v4
55+
- name: Set up JDK
56+
uses: actions/setup-java@v4
57+
with:
58+
java-version: ${{ matrix.java }}
59+
distribution: 'temurin'
60+
- name: Build with Maven
61+
timeout-minutes: ${{ fromJSON(env.time) }}
62+
run: mvn --batch-mode --update-snapshots install
63+
64+
65+
build-windows:
66+
runs-on: windows-latest
67+
steps:
68+
- uses: actions/checkout@v4
69+
- name: Set up JDK
70+
uses: actions/setup-java@v4
71+
with:
72+
java-version: 8
73+
distribution: 'temurin'
74+
- name: Build with Maven
75+
timeout-minutes: ${{ fromJSON(env.time_windows) }}
76+
run: mvn --batch-mode --update-snapshots install
77+
78+
79+
build-macos:
80+
runs-on: macos-latest
81+
steps:
82+
- uses: actions/checkout@v4
83+
- name: Set up JDK
84+
uses: actions/setup-java@v4
85+
with:
86+
java-version: 17
87+
distribution: 'temurin'
88+
- name: Build with Maven
89+
timeout-minutes: ${{ fromJSON(env.time) }}
90+
run: mvn --batch-mode --update-snapshots install

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1313
[#14](https://github.com/netsec-ethz/scion-java-multiping/pull/14)
1414
- Added output of median and average values
1515
[#15](https://github.com/netsec-ethz/scion-java-multiping/pull/15)
16+
- Simple CI script to test formatting and JUnit
17+
[#15](https://github.com/netsec-ethz/scion-java-multiping/pull/15)
1618

1719
### Fixed
1820

src/main/java/org/scion/multiping/PingAll.java

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
import java.util.concurrent.ConcurrentHashMap;
2525
import java.util.concurrent.CountDownLatch;
2626
import java.util.concurrent.TimeUnit;
27+
import java.util.function.Function;
28+
import java.util.function.Predicate;
29+
import java.util.function.ToDoubleFunction;
2730
import java.util.stream.Collectors;
28-
2931
import org.scion.jpan.*;
3032
import org.scion.jpan.internal.PathRawParser;
3133
import org.scion.multiping.util.*;
@@ -89,7 +91,7 @@ private enum Policy {
8991
}
9092

9193
private static final Policy POLICY = Policy.FASTEST_TR_ASYNC;
92-
private static final boolean SHOW_PATH = !true;
94+
private static final boolean SHOW_PATH = false;
9395

9496
public static void main(String[] args) throws IOException {
9597
PRINT = true;
@@ -124,18 +126,12 @@ public static void main(String[] args) throws IOException {
124126
Result maxPaths = results.stream().max(Comparator.comparingInt(Result::getPathCount)).get();
125127

126128
// avg/median:
127-
double avgPing =
128-
results.stream().filter(Result::isSuccess).mapToDouble(Result::getPingMs).average().orElse(-1);
129-
double avgHops =
130-
results.stream().filter(r -> r.getHopCount() > 0).mapToInt(Result::getHopCount).average().orElse(-1);
131-
double avgPaths =
132-
results.stream().filter(r -> r.getPathCount() > 0).mapToInt(Result::getPathCount).average().orElse(-1);
133-
List<Double> pings = results.stream().filter(Result::isSuccess).map(Result::getPingMs).sorted().collect(Collectors.toList());
134-
double medianPing = pings.isEmpty() ? -1 : pings.get(pings.size() / 2);
135-
List<Integer> hops = results.stream().map(Result::getHopCount).filter(hopCount -> hopCount > 0).sorted().collect(Collectors.toList());
136-
int medianHops = hops.isEmpty() ? -1 : hops.get(hops.size() / 2);
137-
List<Integer> paths = results.stream().map(Result::getPathCount).filter(pathCount -> pathCount > 0).sorted().collect(Collectors.toList());
138-
int medianPaths = paths.isEmpty() ? -1 : paths.get(paths.size() / 2);
129+
double avgPing = avg(results, Result::isSuccess, Result::getPingMs);
130+
double avgHops = avg(results, r -> r.getHopCount() > 0, Result::getHopCount);
131+
double avgPaths = avg(results, r -> r.getPathCount() > 0, Result::getPathCount);
132+
double medianPing = median(results, Result::isSuccess, Result::getPingMs).orElse(-1.0);
133+
int medianHops = median(results, r -> r.getHopCount() > 0, Result::getHopCount).orElse(-1);
134+
int medianPaths = median(results, r -> r.getPathCount() > 0, Result::getPathCount).orElse(-1);
139135

140136
println("");
141137
println("Max hops = " + maxHops.getHopCount() + ": " + maxHops);
@@ -404,15 +400,16 @@ public void onException(Throwable t) {
404400
}
405401
}
406402

407-
// Wait for all messages to be received
408-
try {
409-
if (!barrier.await(1100, TimeUnit.MILLISECONDS)) {
410-
throw new IllegalStateException("Missing messages: " + barrier.getCount() + "/" + paths.size());
411-
}
412-
} catch (InterruptedException e) {
403+
// Wait for all messages to be received
404+
try {
405+
if (!barrier.await(1100, TimeUnit.MILLISECONDS)) {
406+
throw new IllegalStateException(
407+
"Missing messages: " + barrier.getCount() + "/" + paths.size());
408+
}
409+
} catch (InterruptedException e) {
413410
Thread.currentThread().interrupt();
414411
throw new IllegalStateException(e);
415-
}
412+
}
416413

417414
} catch (IOException e) {
418415
println("ERROR: " + e.getMessage());
@@ -441,4 +438,15 @@ public void onException(Throwable t) {
441438
}
442439
return best;
443440
}
441+
442+
private static double avg(
443+
List<Result> list, Predicate<Result> filter, ToDoubleFunction<Result> mapper) {
444+
return list.stream().filter(filter).mapToDouble(mapper).average().orElse(-1);
445+
}
446+
447+
private static <T> Optional<T> median(
448+
List<Result> list, Predicate<Result> filter, Function<Result, T> mapper) {
449+
List<T> list2 = list.stream().filter(filter).map(mapper).sorted().collect(Collectors.toList());
450+
return list2.isEmpty() ? Optional.empty() : Optional.of(list2.get(list2.size() / 2));
451+
}
444452
}

src/main/java/org/scion/multiping/util/DownloadAssignmentsFromWeb.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
import java.io.IOException;
1818
import java.util.ArrayList;
1919
import java.util.List;
20-
2120
import org.jsoup.Jsoup;
2221
import org.jsoup.nodes.Document;
2322
import org.jsoup.nodes.Element;
2423
import org.scion.jpan.ScionUtil;
2524

2625
public class DownloadAssignmentsFromWeb {
2726
private static final String HTTPS_URL =
28-
"https://docs.anapaya.net/en/latest/resources/isd-as-assignments/";
27+
"https://docs.anapaya.net/en/latest/resources/isd-as-assignments/";
2928

3029
public static void main(String[] args) throws IOException {
3130
new DownloadAssignmentsFromWeb().jsoup();
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2025 ETH Zurich
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package org.scion.multiping.util;
16+
17+
import static org.junit.jupiter.api.Assertions.*;
18+
19+
import java.util.List;
20+
import org.junit.jupiter.api.Test;
21+
import org.scion.jpan.ScionUtil;
22+
23+
class DonwloaderTest {
24+
25+
@Test
26+
void findAssignments() {
27+
List<ParseAssignments.HostEntry> list = DownloadAssignmentsFromWeb.getList();
28+
assertFalse(list.isEmpty());
29+
30+
boolean found = false;
31+
for (ParseAssignments.HostEntry e : list) {
32+
if (e.getIsdAs() == ScionUtil.parseIA("64-2:0:9")) {
33+
found = true;
34+
break;
35+
}
36+
}
37+
assertTrue(found);
38+
}
39+
}

0 commit comments

Comments
 (0)