Skip to content

Commit 6e1c12c

Browse files
Merge pull request #166 from OpenHFT/codex/manipulate-affinity-and-assert-value
Add unit test for Affinity.resetToBaseAffinity
2 parents 561190e + f5b3e76 commit 6e1c12c

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package net.openhft.affinity;
2+
3+
import net.openhft.affinity.impl.VanillaCpuLayout;
4+
import org.junit.Test;
5+
6+
import java.io.File;
7+
8+
import static org.junit.Assert.assertEquals;
9+
10+
public class AffinityResetToBaseAffinityTest extends BaseAffinityTest {
11+
12+
@Test
13+
public void resettingShouldRestoreBaseAffinity() throws Exception {
14+
if (!new File("/proc/cpuinfo").exists()) {
15+
System.out.println("Cannot run affinity test as this system doesn't have a /proc/cpuinfo file");
16+
return;
17+
}
18+
19+
// initialise CPU layout from the running machine so acquireLock works
20+
AffinityLock.cpuLayout(VanillaCpuLayout.fromCpuInfo());
21+
22+
assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity());
23+
AffinityLock lock = AffinityLock.acquireLock();
24+
try {
25+
assertEquals(1, Affinity.getAffinity().cardinality());
26+
27+
Affinity.resetToBaseAffinity();
28+
assertEquals(AffinityLock.BASE_AFFINITY, Affinity.getAffinity());
29+
} finally {
30+
lock.release();
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)