mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Use Jvm.{level}() handlers instead of calling loggers directly, and unit tests cleanup esp use of @After, https://github.com/OpenHFT/Chronicle-Core/issues/233
This commit is contained in:
@@ -36,8 +36,6 @@ public class BuildVersionTest {
|
||||
/**
|
||||
* check that the map records the version
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Test
|
||||
public void testVersion() throws IOException, InterruptedException {
|
||||
|
||||
@@ -28,8 +28,6 @@ import static net.openhft.chronicle.map.Issue62ChronicleServer.prepare;
|
||||
|
||||
public class Issue62ChronicleClient {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(Issue62ChronicleClient.class);
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
prepare(MAP_FILE_B);
|
||||
|
||||
@@ -45,11 +43,11 @@ public class Issue62ChronicleClient {
|
||||
try (ChronicleMap<String, Long> map =
|
||||
cityPostalCodesMapBuilder.createPersistedTo(MAP_FILE_B)) {
|
||||
|
||||
LOGGER.info("Starting");
|
||||
System.out.println( "Starting");
|
||||
Jvm.pause(3000);
|
||||
|
||||
for (Entry<String, Long> entry : map.entrySet()) {
|
||||
LOGGER.info("{} : {}", entry.getKey(), entry.getValue());
|
||||
System.out.println(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ public class Issue62ChronicleServer {
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
final static File MAP_FILE_B =
|
||||
Paths.get(OS.getTarget(), Time.uniqueId() + "map.b").toFile();
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(Issue62ChronicleServer.class);
|
||||
private final static File MAP_FILE_A =
|
||||
Paths.get(OS.getTarget(), Time.uniqueId() + "map.a").toFile();
|
||||
|
||||
@@ -63,7 +62,7 @@ public class Issue62ChronicleServer {
|
||||
cityPostalCodes.put(STR + i, (long) i);
|
||||
}
|
||||
|
||||
LOGGER.info("Map created");
|
||||
System.out.println("Map created");
|
||||
Jvm.pause(15000);
|
||||
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ public class DirtyReadOffender implements Runnable {
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender ACQUIRING offHeapLock.writeLock();"
|
||||
);
|
||||
while ((stamp = this.offHeapLock.writeLock()) == 0) {
|
||||
;
|
||||
while ((stamp = this.offHeapLock.writeLock()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
|
||||
@@ -36,8 +36,7 @@ public class DirtyReadVictim implements Runnable {
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
" DirtyReadVictim CALLING offHeapLock.tryOptimisticRead()"
|
||||
);
|
||||
while ((stamp = this.offHeapLock.tryOptimisticRead()) == 0) {
|
||||
;
|
||||
while ((stamp = this.offHeapLock.tryOptimisticRead()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
|
||||
+1
-2
@@ -42,8 +42,7 @@ public class DirtyReadOffender implements Runnable {
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender ACQUIRING offHeapLock.writeLock();"
|
||||
);
|
||||
while ((stamp = this.offHeapLock.writeLock()) == 0) {
|
||||
;
|
||||
while ((stamp = this.offHeapLock.writeLock()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
|
||||
@@ -36,8 +36,7 @@ public class DirtyReadVictim implements Runnable {
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
" DirtyReadVictim CALLING offHeapLock.tryOptimisticRead()"
|
||||
);
|
||||
while ((stamp = this.offHeapLock.tryOptimisticRead()) == 0) {
|
||||
;
|
||||
while ((stamp = this.offHeapLock.tryOptimisticRead()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
|
||||
+1
-2
@@ -368,8 +368,7 @@ public class ChronicleStampedLock extends StampedLock {
|
||||
unlockWrite(stamp);
|
||||
} else if (stamp > 0L) {
|
||||
unlockRead(stamp);
|
||||
} else {
|
||||
;// lock available
|
||||
} else {;// lock available
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -39,8 +39,7 @@ public class DirtyReadIntolerant {
|
||||
" DirtyReadIntolerant sleeping " + sleepMock + " seconds"
|
||||
);
|
||||
Thread.sleep(sleepMock * 1_000);
|
||||
while ((stamp = offHeapLock.readLock()) < 0) {
|
||||
;
|
||||
while ((stamp = offHeapLock.readLock()) < 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
|
||||
+1
-2
@@ -56,8 +56,7 @@ public class DirtyReadOffender {
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender ACQUIRING offHeapLock.writeLock();"
|
||||
);
|
||||
while ((stamp = offHeapLock.writeLock()) == 0) {
|
||||
;
|
||||
while ((stamp = offHeapLock.writeLock()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
" @t=" + System.currentTimeMillis() +
|
||||
|
||||
+1
-2
@@ -43,8 +43,7 @@ public class DirtyReadVictimTest {
|
||||
OS.getTarget() + "/OPERAND_ChronicleStampedLock"
|
||||
/*"C:\\Users\\buddy\\dev\\shm\\OPERAND_ChronicleStampedLock"*/
|
||||
);
|
||||
while ((stamp = offHeapLock.tryOptimisticRead()) == 0) {
|
||||
;
|
||||
while ((stamp = offHeapLock.tryOptimisticRead()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
|
||||
@@ -39,8 +39,6 @@ public class StateMachineData implements Byteable {
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* @param states
|
||||
* @return
|
||||
*/
|
||||
public boolean stateIn(StateMachineState... states) {
|
||||
StateMachineState currentState = getState();
|
||||
@@ -54,8 +52,6 @@ public class StateMachineData implements Byteable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
public boolean setState(StateMachineState from, StateMachineState to) {
|
||||
if (this.bs == null) throw new NullPointerException("Byteable is not set to off heap");
|
||||
@@ -64,7 +60,6 @@ public class StateMachineData implements Byteable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public StateMachineState getState() {
|
||||
if (this.bs == null) throw new NullPointerException("Byteable is not set to off heap");
|
||||
@@ -74,7 +69,6 @@ public class StateMachineData implements Byteable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param state
|
||||
*/
|
||||
public void setState(StateMachineState state) {
|
||||
if (this.bs == null) throw new NullPointerException("Byteable is not set to off heap");
|
||||
@@ -86,8 +80,6 @@ public class StateMachineData implements Byteable {
|
||||
* Wait for a state and make a transition.
|
||||
* It spins initially (1000 iterations), then uses a Thread.yield() .
|
||||
*
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
public void waitForState(StateMachineState from, StateMachineState to) {
|
||||
if (this.bs == null) throw new NullPointerException("Byteable is not set to off heap");
|
||||
@@ -105,7 +97,6 @@ public class StateMachineData implements Byteable {
|
||||
// *************************************************************************
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int getStateData() {
|
||||
if (this.bs != null) {
|
||||
@@ -116,7 +107,6 @@ public class StateMachineData implements Byteable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param data
|
||||
*/
|
||||
public void setStateData(int data) {
|
||||
if (this.bs != null) {
|
||||
@@ -125,7 +115,6 @@ public class StateMachineData implements Byteable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int incStateData() {
|
||||
if (this.bs != null) {
|
||||
@@ -136,7 +125,6 @@ public class StateMachineData implements Byteable {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean done() {
|
||||
if (this.bs != null) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package net.openhft.chronicle.map.ipc;
|
||||
|
||||
import net.openhft.chronicle.core.Jvm;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@@ -27,12 +28,8 @@ public class StateMachineProcessor implements Runnable {
|
||||
private final StateMachineState from;
|
||||
private final StateMachineState transition;
|
||||
private final StateMachineState to;
|
||||
private final Logger logger;
|
||||
|
||||
/**
|
||||
* @param smd
|
||||
* @param from
|
||||
* @param to
|
||||
*/
|
||||
public StateMachineProcessor(final StateMachineData smd, StateMachineState from, StateMachineState transition, StateMachineState to) {
|
||||
this.smd = smd;
|
||||
@@ -40,14 +37,9 @@ public class StateMachineProcessor implements Runnable {
|
||||
this.transition = transition;
|
||||
this.to = to;
|
||||
|
||||
this.logger = LoggerFactory.getLogger(from + " => " + transition + " => " + to);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param smd
|
||||
* @param from
|
||||
* @param transition
|
||||
* @param to
|
||||
*/
|
||||
public static void runProcessor(final StateMachineData smd, StateMachineState from, StateMachineState transition, StateMachineState to) {
|
||||
new StateMachineProcessor(smd, from, transition, to).run();
|
||||
@@ -60,7 +52,7 @@ public class StateMachineProcessor implements Runnable {
|
||||
doProcess();
|
||||
}
|
||||
|
||||
logger.info("Wait for {}", from);
|
||||
Jvm.debug().on(getClass(), "Wait for " + from);
|
||||
smd.waitForState(from, transition);
|
||||
|
||||
doProcess();
|
||||
@@ -70,11 +62,10 @@ public class StateMachineProcessor implements Runnable {
|
||||
private void doProcess() {
|
||||
smd.incStateData();
|
||||
|
||||
logger.info("Status {}, Next {}, Data {}",
|
||||
from,
|
||||
to,
|
||||
smd.getStateData()
|
||||
);
|
||||
Jvm.debug().on(getClass(),
|
||||
"Status " + from + ", " +
|
||||
"Next " + to + ", " +
|
||||
"Data " + smd.getStateData());
|
||||
|
||||
smd.setState(transition, to);
|
||||
}
|
||||
|
||||
@@ -35,7 +35,6 @@ public enum StateMachineState {
|
||||
/**
|
||||
* c-tor
|
||||
*
|
||||
* @param state
|
||||
*/
|
||||
StateMachineState(int state) {
|
||||
this.state = state;
|
||||
@@ -52,7 +51,6 @@ public enum StateMachineState {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public int value() {
|
||||
return this.state;
|
||||
|
||||
@@ -63,8 +63,7 @@ public class DirtyReadOffenderIPCTest implements Runnable {
|
||||
"..... @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender ACQUIRING offHeapLock.writeLock();"
|
||||
);
|
||||
while ((stamp = offHeapLock.writeLock()) == 0) {
|
||||
;
|
||||
while ((stamp = offHeapLock.writeLock()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
"..... @t=" + System.currentTimeMillis() +
|
||||
|
||||
@@ -52,8 +52,7 @@ class DirtyReadOffenderTest implements Runnable {
|
||||
"..... @t=" + System.currentTimeMillis() +
|
||||
" DirtyReadOffender ACQUIRING offHeapLock.writeLock();"
|
||||
);
|
||||
while ((stamp = offHeapLock.writeLock()) == 0) {
|
||||
;
|
||||
while ((stamp = offHeapLock.writeLock()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
"..... @t=" + System.currentTimeMillis() +
|
||||
|
||||
@@ -31,7 +31,6 @@ public class DirtyReadVictimIPCTest {
|
||||
* <p>
|
||||
* this belief is STRICTLY conjecture.
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
|
||||
@Test
|
||||
@@ -85,8 +84,7 @@ public class DirtyReadVictimIPCTest {
|
||||
OS.getTarget() + "/shm-" +
|
||||
"OPERAND_ChronicleStampedLock"
|
||||
);
|
||||
while ((stamp = offHeapLock.tryOptimisticRead()) == 0) {
|
||||
;
|
||||
while ((stamp = offHeapLock.tryOptimisticRead()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
@@ -180,8 +178,7 @@ public class DirtyReadVictimIPCTest {
|
||||
OS.getTarget() + "/shm-"
|
||||
+ "OPERAND_ChronicleStampedLock"
|
||||
);
|
||||
while ((stamp = offHeapLock.tryOptimisticRead()) == 0) {
|
||||
;
|
||||
while ((stamp = offHeapLock.tryOptimisticRead()) == 0) {;
|
||||
}
|
||||
System.out.println(
|
||||
" ,,@t=" + System.currentTimeMillis() +
|
||||
|
||||
@@ -323,7 +323,6 @@ public class ProcessInstanceLimiter implements Runnable {
|
||||
* slot, it will callback thisProcessOfTypeHasStartedAtSlot(), otherwise one
|
||||
* of the other callback interface methods will be called.
|
||||
*
|
||||
* @param processType
|
||||
*/
|
||||
public void startingProcessOfType(String processType) {
|
||||
Data data = this.timedata.get(processType);
|
||||
|
||||
Reference in New Issue
Block a user