Skip to content

Commit 954a4df

Browse files
committed
Add assertion to verify base affinity in BaseAffinityTest
1 parent 6754034 commit 954a4df

17 files changed

Lines changed: 55 additions & 45 deletions

affinity/src/test/java/net/openhft/affinity/AffinityLockDumpLocksTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
public class AffinityLockDumpLocksTest extends BaseAffinityTest {
1616

17+
static void supressUnusedWarning(AutoCloseable c) {
18+
// do nothing
19+
}
20+
1721
@Test
1822
public void dumpLocksListsThreadsHoldingLocks() throws Exception {
1923
Assume.assumeTrue(new File("/proc/cpuinfo").exists());
@@ -51,8 +55,4 @@ public void dumpLocksListsThreadsHoldingLocks() throws Exception {
5155
t.join();
5256
}
5357
}
54-
55-
static void supressUnusedWarning(AutoCloseable c) {
56-
// do nothing
57-
}
5858
}

affinity/src/test/java/net/openhft/affinity/AffinityLockTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,14 @@
4545
public class AffinityLockTest extends BaseAffinityTest {
4646
private static final Logger logger = LoggerFactory.getLogger(AffinityLockTest.class);
4747

48+
/**
49+
* In Java 21 the toString contents of Thread changed to include an ID. This breaks the tests here in Java 21.
50+
* Strip out the thread ID here so that existing tests continue to pass.
51+
*/
52+
private static String dumpLocks(AffinityLock[] locks) {
53+
String value = LockInventory.dumpLocks(locks);
54+
return value.replaceAll("#[0-9]+(,)?", "");
55+
}
4856

4957
@Test
5058
public void dumpLocksI7() throws IOException {
@@ -373,13 +381,4 @@ public void bindingTwoThreadsToSameCpuThrows() throws InterruptedException {
373381
lock.release();
374382
}
375383
}
376-
377-
/**
378-
* In Java 21 the toString contents of Thread changed to include an ID. This breaks the tests here in Java 21.
379-
* Strip out the thread ID here so that existing tests continue to pass.
380-
*/
381-
private static String dumpLocks(AffinityLock[] locks) {
382-
String value = LockInventory.dumpLocks(locks);
383-
return value.replaceAll("#[0-9]+(,)?", "");
384-
}
385384
}

affinity/src/test/java/net/openhft/affinity/AffinityThreadFactoryTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@
55
import org.junit.Test;
66

77
import java.util.Set;
8-
import java.util.concurrent.ConcurrentHashMap;
9-
import java.util.concurrent.CountDownLatch;
10-
import java.util.concurrent.ExecutorService;
11-
import java.util.concurrent.Executors;
12-
import java.util.concurrent.TimeUnit;
8+
import java.util.concurrent.*;
139

1410
import static org.junit.Assert.*;
1511

affinity/src/test/java/net/openhft/affinity/BaseAffinityTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import org.junit.Rule;
2222
import org.junit.rules.TemporaryFolder;
2323

24+
import java.util.BitSet;
25+
2426
import static org.junit.Assert.assertEquals;
2527

2628
public class BaseAffinityTest {
@@ -46,6 +48,8 @@ public void restoreTmpDirectoryAndReleaseAllLocks() {
4648

4749
@After
4850
public void baseAffinity() {
49-
assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity());
51+
BitSet affinity = Affinity.getAffinity();
52+
Affinity.resetToBaseAffinity();
53+
assertEquals(AffinityLock.BASE_AFFINITY, affinity);
5054
}
5155
}

affinity/src/test/java/net/openhft/affinity/BootClassPathTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import static org.junit.Assert.assertTrue;
2222

23-
public class BootClassPathTest {
23+
public class BootClassPathTest extends BaseAffinityTest {
2424
@Test
2525
public void shouldDetectClassesOnClassPath() {
2626
assertTrue(BootClassPath.INSTANCE.has("java.lang.Thread"));

affinity/src/test/java/net/openhft/affinity/MultiProcessAffinityTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ static class RepeatedAffinityLocker implements Callable<Void> {
155155
private final int iterations;
156156
private final String cpuIdToLock;
157157

158+
public RepeatedAffinityLocker(String cpuIdToLock, int iterations) {
159+
this.iterations = iterations;
160+
this.cpuIdToLock = cpuIdToLock;
161+
}
162+
158163
public static void main(String[] args) throws InterruptedException, ExecutionException {
159164
String cpuIdToLock = args[0];
160165
int iterations = Integer.parseInt(args[1]);
@@ -174,11 +179,6 @@ public static void main(String[] args) throws InterruptedException, ExecutionExc
174179
}
175180
}
176181

177-
public RepeatedAffinityLocker(String cpuIdToLock, int iterations) {
178-
this.iterations = iterations;
179-
this.cpuIdToLock = cpuIdToLock;
180-
}
181-
182182
@Override
183183
public Void call() throws Exception {
184184
for (int i = 0; i < iterations; i++) {

affinity/src/test/java/net/openhft/affinity/impl/AbstractAffinityImplTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package net.openhft.affinity.impl;
1919

20+
import net.openhft.affinity.BaseAffinityTest;
2021
import net.openhft.affinity.IAffinity;
2122
import org.junit.After;
2223
import org.junit.Test;
@@ -29,7 +30,7 @@
2930
* @author cheremin
3031
* @since 29.12.11, 20:25
3132
*/
32-
public abstract class AbstractAffinityImplTest {
33+
public abstract class AbstractAffinityImplTest extends BaseAffinityTest {
3334

3435
protected static final int CORES = Runtime.getRuntime().availableProcessors();
3536
protected static final BitSet CORES_MASK = new BitSet(CORES);

affinity/src/test/java/net/openhft/affinity/impl/CpuInfoLayoutMappingTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,29 @@
1616

1717
package net.openhft.affinity.impl;
1818

19+
import net.openhft.affinity.BaseAffinityTest;
1920
import org.junit.Test;
2021

2122
import java.io.IOException;
2223
import java.io.InputStream;
2324

2425
import static org.junit.Assert.assertEquals;
2526

26-
public class CpuInfoLayoutMappingTest {
27+
public class CpuInfoLayoutMappingTest extends BaseAffinityTest {
2728

2829
@Test
2930
public void verifyI7CpuInfoMapping() throws IOException {
3031
final InputStream i7 = getClass().getClassLoader().getResourceAsStream("i7.cpuinfo");
3132
VanillaCpuLayout vcl = VanillaCpuLayout.fromCpuInfo(i7);
32-
assertEquals(
33-
"0: CpuInfo{socketId=0, coreId=0, threadId=0}\n" +
34-
"1: CpuInfo{socketId=0, coreId=1, threadId=0}\n" +
35-
"2: CpuInfo{socketId=0, coreId=2, threadId=0}\n" +
36-
"3: CpuInfo{socketId=0, coreId=3, threadId=0}\n" +
37-
"4: CpuInfo{socketId=0, coreId=0, threadId=1}\n" +
38-
"5: CpuInfo{socketId=0, coreId=1, threadId=1}\n" +
39-
"6: CpuInfo{socketId=0, coreId=2, threadId=1}\n" +
40-
"7: CpuInfo{socketId=0, coreId=3, threadId=1}\n",
33+
assertEquals("" +
34+
"0: CpuInfo{socketId=0, coreId=0, threadId=0}\n" +
35+
"1: CpuInfo{socketId=0, coreId=1, threadId=0}\n" +
36+
"2: CpuInfo{socketId=0, coreId=2, threadId=0}\n" +
37+
"3: CpuInfo{socketId=0, coreId=3, threadId=0}\n" +
38+
"4: CpuInfo{socketId=0, coreId=0, threadId=1}\n" +
39+
"5: CpuInfo{socketId=0, coreId=1, threadId=1}\n" +
40+
"6: CpuInfo{socketId=0, coreId=2, threadId=1}\n" +
41+
"7: CpuInfo{socketId=0, coreId=3, threadId=1}\n",
4142
vcl.toString());
4243
}
4344
}

affinity/src/test/java/net/openhft/affinity/impl/LinuxJNAAffinityTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package net.openhft.affinity.impl;
1919

20+
import net.openhft.affinity.BaseAffinityTest;
2021
import org.junit.Assume;
2122
import org.junit.BeforeClass;
2223
import org.junit.Test;
@@ -28,7 +29,7 @@
2829
/*
2930
* Created by Peter Lawrey on 23/03/16.
3031
*/
31-
public class LinuxJNAAffinityTest {
32+
public class LinuxJNAAffinityTest extends BaseAffinityTest {
3233
@BeforeClass
3334
public static void checkJniLibraryPresent() {
3435
Assume.assumeTrue(LinuxJNAAffinity.LOADED);

affinity/src/test/java/net/openhft/affinity/impl/UtilitiesTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
package net.openhft.affinity.impl;
1818

19+
import net.openhft.affinity.BaseAffinityTest;
1920
import org.junit.Test;
2021

2122
import java.util.BitSet;
2223

2324
import static org.junit.Assert.assertEquals;
2425

25-
public class UtilitiesTest {
26+
public class UtilitiesTest extends BaseAffinityTest {
2627

2728
private static String hex(BitSet set, int... bits) {
2829
set.clear();

0 commit comments

Comments
 (0)