Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHRON-96 moved net.openhft.chronicle.tcp.WithMappedTest.testReplicati…
…onWithMapping into its own test
- Loading branch information
Rob Austin
committed
Jan 14, 2015
1 parent
dfd79dd
commit 0365037
Showing
3 changed files
with
125 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
chronicle/src/test/java/net/openhft/chronicle/tcp/WithMappedTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,111 @@ | |||
package net.openhft.chronicle.tcp; | |||
|
|||
import net.openhft.affinity.AffinityLock; | |||
import net.openhft.chronicle.Chronicle; | |||
import net.openhft.chronicle.ChronicleQueueBuilder; | |||
import net.openhft.chronicle.ExcerptAppender; | |||
import net.openhft.chronicle.ExcerptTailer; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TestName; | |||
|
|||
import java.io.File; | |||
|
|||
import static org.junit.Assert.*; | |||
|
|||
/** | |||
* @author Rob Austin. | |||
*/ | |||
public class WithMappedTest extends ChronicleTcpTestBase { | |||
|
|||
@Rule | |||
public final TestName testName = new TestName(); | |||
|
|||
|
|||
@Test | |||
public void testReplicationWithMapping() throws Exception { | |||
final int RUNS = 100; | |||
|
|||
final String sourceBasePath = getVanillaTestPath("-source"); | |||
final String sinkBasePath = getVanillaTestPath("-sink"); | |||
|
|||
final ChronicleTcpTestBase.PortSupplier portSupplier = new ChronicleTcpTestBase.PortSupplier(); | |||
|
|||
final Chronicle source = ChronicleQueueBuilder.vanilla(sourceBasePath) | |||
.source() | |||
.bindAddress(0) | |||
.connectionListener(portSupplier) | |||
.build(); | |||
|
|||
final int port = portSupplier.getAndCheckPort(); | |||
final Chronicle sink = ChronicleQueueBuilder.vanilla(sinkBasePath) | |||
.sink() | |||
.withMapping(new StatefulVanillaChronicleTest.NoOpMappingFunction()) // this is sent to the source | |||
.connectAddress("localhost", port) | |||
.build(); | |||
|
|||
try { | |||
|
|||
final Thread at = new Thread("th-appender") { | |||
public void run() { | |||
AffinityLock lock = AffinityLock.acquireLock(); | |||
try { | |||
final ExcerptAppender appender = source.createAppender(); | |||
for (int i = 0; i < RUNS; i++) { | |||
appender.startExcerpt(); | |||
long value = 1000000000 + i; | |||
appender.append(value).append(' '); | |||
appender.finish(); | |||
} | |||
|
|||
appender.close(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} finally { | |||
lock.release(); | |||
} | |||
} | |||
}; | |||
|
|||
final Thread tt = new Thread("th-tailer") { | |||
public void run() { | |||
AffinityLock lock = AffinityLock.acquireLock(); | |||
try { | |||
final ExcerptTailer tailer = sink.createTailer(); | |||
for (int i = 0; i < RUNS; i++) { | |||
long value = 1000000000 + i; | |||
assertTrue(tailer.nextIndex()); | |||
long val = tailer.parseLong(); | |||
|
|||
assertEquals("i: " + i, value, val); | |||
assertEquals("i: " + i, 0, tailer.remaining()); | |||
tailer.finish(); | |||
} | |||
|
|||
tailer.close(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} finally { | |||
lock.release(); | |||
} | |||
} | |||
}; | |||
|
|||
at.start(); | |||
tt.start(); | |||
|
|||
at.join(); | |||
tt.join(); | |||
} finally { | |||
sink.close(); | |||
sink.clear(); | |||
|
|||
source.close(); | |||
source.clear(); | |||
|
|||
assertFalse(new File(sourceBasePath).exists()); | |||
assertFalse(new File(sinkBasePath).exists()); | |||
} | |||
} | |||
|
|||
} |