Skip to content

Commit

Permalink
Chronicle-Bytes builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey committed Mar 23, 2015
1 parent f23c028 commit ae33a13
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 82 deletions.
2 changes: 1 addition & 1 deletion chronicle-queue/pom.xml
Expand Up @@ -30,7 +30,7 @@
</parent>

<artifactId>chronicle-queue</artifactId>
<version>4.0.0-alapha-SNAPSHOT</version>
<version>4.0.0-alpha-SNAPSHOT</version>
<packaging>bundle</packaging>
<name>OpenHFT/Chronicle-Queue</name>

Expand Down
Expand Up @@ -32,35 +32,17 @@ class Header implements Marshallable {
private LongValue index2Index = null;
private LongValue lastIndex = null;


private LongValueInstance tempWriteByte = new LongValueInstance();
private LongValueInstance tempIndex2Index = new LongValueInstance();
private LongValueInstance tempLastIndex = new LongValueInstance();

{
tempLastIndex.setValue(-1);
}

LongValue writeByte() {
if (writeByte == null)
return tempWriteByte;
return writeByte;
}


LongValue index2Index() {
if (index2Index == null)
return tempIndex2Index;
return index2Index;
}


LongValue lastIndex() {

if (lastIndex == null) {
return tempLastIndex;
}

return lastIndex;
}

Expand All @@ -72,7 +54,6 @@ public Header init(@NotNull Compression compression) {
user = System.getProperty("user.name");
host = SingleChronicleQueue.getHostName();
this.compression = compression.name();
writeByte().setOrderedValue(PADDED_SIZE);
return this;
}

Expand Down Expand Up @@ -101,46 +82,15 @@ public void writeMarshallable(@NotNull WireOut out) {
@Override
public void readMarshallable(@NotNull WireIn in) {
in.read(Field.uuid).uuid(u -> uuid = u)
.read(Field.writeByte).int64(writeByte, Header.this::newWriteByte)
.read(Field.writeByte).int64(writeByte, x -> writeByte = x)
.read(Field.created).zonedDateTime(c -> created = c)
.read(Field.user).text(u -> user = u)
.read(Field.host).text(h -> host = h)
.read(Field.compression).text(h -> compression = h)
.read(Field.indexCount).int32(h -> indexCount = h)
.read(Field.indexSpacing).int32(h -> indexSpacing = h)
.read(Field.index2Index).int64(index2Index, this::newIndex2Index)
.read(Field.lastIndex).int64(lastIndex, this::newLastIndex);
}

private void newIndex2Index(LongValue x) {
lastIndex = x;
lastIndex.setValue(tempLastIndex.getValue());
try {
tempLastIndex.close();
} catch (IOException e) {

}
}

private void newWriteByte(LongValue x) {
writeByte = x;
writeByte.setValue(tempWriteByte.getValue());
try {
tempWriteByte.close();
} catch (IOException e) {

}
}

private void newLastIndex(LongValue x) {
lastIndex = x;
lastIndex.setValue(tempLastIndex.getValue());

try {
tempLastIndex.close();
} catch (IOException e) {

}
.read(Field.index2Index).int64(index2Index, x -> index2Index = x)
.read(Field.lastIndex).int64(lastIndex, x -> lastIndex = x);
}

public long getWriteByte() {
Expand Down
Expand Up @@ -279,7 +279,7 @@ long newIndex() {

long indexSize = 1L << 17L;

try (NativeStore<Void> allocate = NativeStore.nativeStore(6)) {
try (NativeBytesStore<Void> allocate = NativeBytesStore.nativeStore(6)) {

final Bytes<Void> buffer = allocate.bytes();

Expand Down
Expand Up @@ -2,7 +2,7 @@


import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.NativeStore;
import net.openhft.chronicle.bytes.NativeBytesStore;
import net.openhft.chronicle.queue.impl.ringbuffer.BytesRingBuffer;
import org.jetbrains.annotations.NotNull;
import org.junit.*;
Expand All @@ -27,10 +27,10 @@ public class BytesRingBufferTest {
Bytes<ByteBuffer> input = Bytes.wrap(ByteBuffer.allocate(12));
Bytes<ByteBuffer> output;
Bytes<ByteBuffer> out;
NativeStore outBuffer;
NativeBytesStore outBuffer;
@Before
public void setup() {
outBuffer = NativeStore.nativeStore(12);
outBuffer = NativeBytesStore.nativeStore(12);
out = outBuffer.bytes();
out.writeUTFΔ(EXPECTED);
output = out.flip().bytes();
Expand All @@ -44,7 +44,7 @@ public void after() {

@Test
public void testWriteAndRead3SingleThreadedWrite() throws Exception {
try (NativeStore<Void> nativeStore = NativeStore.nativeStore(24)) {
try (NativeBytesStore<Void> nativeStore = NativeBytesStore.nativeStore(24)) {
final BytesRingBuffer bytesRingBuffer = new BytesRingBuffer(nativeStore.bytes());


Expand All @@ -71,7 +71,7 @@ public Bytes provide(long maxSize) {
@Test
public void testSimpledSingleThreadedWriteRead() throws Exception {

try (NativeStore<Void> nativeStore = NativeStore.nativeStore(150)) {
try (NativeByteStore<Void> nativeStore = NativeByteStore.nativeStore(150)) {
final BytesRingBuffer bytesRingBuffer = new BytesRingBuffer(nativeStore.bytes());

bytesRingBuffer.offer(data());
Expand All @@ -82,7 +82,7 @@ public void testSimpledSingleThreadedWriteRead() throws Exception {

@Test
public void testPollWithNoData() throws Exception {
try (NativeStore<Void> nativeStore = NativeStore.nativeStore(150)) {
try (NativeByteStore<Void> nativeStore = NativeByteStore.nativeStore(150)) {

assert nativeStore.isNative();

Expand All @@ -96,7 +96,7 @@ public void testPollWithNoData() throws Exception {

@Test
public void testWriteAndRead() throws Exception {
try (NativeStore<Void> nativeStore = NativeStore.nativeStore(150)) {
try (NativeByteStore<Void> nativeStore = NativeByteStore.nativeStore(150)) {
assert nativeStore.isNative();
final BytesRingBuffer bytesRingBuffer = new BytesRingBuffer(nativeStore.bytes());
data();
Expand All @@ -113,7 +113,7 @@ private Bytes<ByteBuffer> data() {

@Test
public void testFlowAroundSingleThreadedWriteDifferentSizeBuffers() throws Exception {
try (NativeStore<Void> nativeStore = NativeStore.nativeStore(150)) {
try (NativeByteStore<Void> nativeStore = NativeByteStore.nativeStore(150)) {

System.out.println(nativeStore.realCapacity());
System.out.println(nativeStore.capacity());
Expand All @@ -137,7 +137,7 @@ public void testFlowAroundSingleThreadedWriteDifferentSizeBuffers() throws Excep

@Test
public void testWrite3read3SingleThreadedWrite() throws Exception {
try (NativeStore<Void> nativeStore = NativeStore.nativeStore(150)) {
try (NativeByteStore<Void> nativeStore = NativeByteStore.nativeStore(150)) {
final BytesRingBuffer bytesRingBuffer = new BytesRingBuffer(nativeStore.bytes());

assert nativeStore.bytes().capacity() < (1 << 12);
Expand Down Expand Up @@ -180,7 +180,7 @@ public Bytes provide(long maxSize) {
@Test
public void testMultiThreadedCheckAllEntriesReturnedAreValidText() throws Exception {

try (NativeStore allocate = NativeStore.nativeStore(1000)) {
try (NativeByteStore allocate = NativeByteStore.nativeStore(1000)) {
final BytesRingBuffer bytesRingBuffer = new BytesRingBuffer(allocate.bytes());


Expand All @@ -193,7 +193,7 @@ public void testMultiThreadedCheckAllEntriesReturnedAreValidText() throws Except
for (int i = 0; i < iterations; i++) {
final int j = i;
executorService.submit(() -> {
try (NativeStore<Void> nativeStore = NativeStore.nativeStore(iterations)) {
try (NativeByteStore<Void> nativeStore = NativeByteStore.nativeStore(iterations)) {
final Bytes out = nativeStore.bytes();
String expected = EXPECTED_VALUE + j;
out.clear();
Expand Down Expand Up @@ -223,7 +223,7 @@ public void testMultiThreadedCheckAllEntriesReturnedAreValidText() throws Except
executorService.submit(() -> {

try {
try (NativeStore<Void> nativeStore = NativeStore.nativeStore(25)) {
try (NativeByteStore<Void> nativeStore = NativeByteStore.nativeStore(25)) {
Bytes bytes = nativeStore.bytes();
Bytes result = null;
do {
Expand Down Expand Up @@ -260,7 +260,7 @@ public void testMultiThreadedCheckAllEntriesReturnedAreValidText() throws Except
@Test
public void testMultiThreadedWithIntValues() throws Exception {

try (NativeStore allocate = NativeStore.nativeStore(1000)) {
try (NativeByteStore allocate = NativeByteStore.nativeStore(1000)) {


final BytesRingBuffer bytesRingBuffer = new BytesRingBuffer(allocate.bytes());
Expand All @@ -276,7 +276,7 @@ public void testMultiThreadedWithIntValues() throws Exception {
final int j = i;
executorService.submit(() -> {

try (NativeStore allocate2 = NativeStore.nativeStore(iterations)) {
try (NativeByteStore allocate2 = NativeByteStore.nativeStore(iterations)) {
final Bytes out = allocate2.bytes();

out.clear();
Expand Down Expand Up @@ -307,7 +307,7 @@ public void testMultiThreadedWithIntValues() throws Exception {
executorService.submit(() -> {

try {
try (NativeStore allocate3 = NativeStore.nativeStore(25)) {
try (NativeByteStore allocate3 = NativeByteStore.nativeStore(25)) {
final Bytes bytes = allocate3.bytes();
Bytes result = null;
do {
Expand Down
@@ -1,7 +1,6 @@
package net.openhft.chronicle.queue;

import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.NativeStore;
import net.openhft.chronicle.queue.impl.DirectChronicleQueue;
import org.junit.Test;
import org.slf4j.Logger;
Expand Down Expand Up @@ -88,7 +87,7 @@ public void testCreateAppender() throws Exception {
}

private void readSome(DirectChronicleQueue chronicle) {
NativeStore allocate = NativeStore.nativeStore(EXPECTED_BYTES.length);
NativeByteStore allocate = NativeByteStore.nativeStore(EXPECTED_BYTES.length);
final Bytes toRead = allocate.bytes();
AtomicLong offset = new AtomicLong(chronicle.firstBytes());
for (int i = 0; i < RUNS; i++) {
Expand All @@ -98,7 +97,7 @@ private void readSome(DirectChronicleQueue chronicle) {
}

private void writeSome(DirectChronicleQueue chronicle) {
NativeStore allocate = NativeStore.nativeStore(EXPECTED_BYTES.length);
NativeByteStore allocate = NativeByteStore.nativeStore(EXPECTED_BYTES.length);
final Bytes toWrite = allocate.bytes();
toWrite.write(EXPECTED_BYTES);
for (int i = 0; i < RUNS; i++) {
Expand Down
Expand Up @@ -2,20 +2,14 @@

import junit.framework.TestCase;
import net.openhft.chronicle.bytes.Bytes;
import net.openhft.chronicle.bytes.NativeStore;
import net.openhft.chronicle.queue.ChronicleQueueBuilder;
import net.openhft.chronicle.queue.impl.ringbuffer.BytesRingBuffer;
import net.openhft.chronicle.queue.impl.ringbuffer.ZippedDocumentAppender;
import net.openhft.chronicle.wire.TextWire;

import net.openhft.lang.io.DirectBytes;
import net.openhft.lang.io.DirectStore;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicLong;

public class ZipBytesRingBufferTest extends TestCase {
Expand All @@ -27,8 +21,8 @@ public void testZipAndAppend() throws Exception {
try {


NativeStore allocate = NativeStore.nativeStore(1024);
NativeStore msgBytes = NativeStore.nativeStore(150);
NativeByteStore allocate = NativeByteStore.nativeStore(1024);
NativeByteStore msgBytes = NativeByteStore.nativeStore(150);

net.openhft.chronicle.bytes.Bytes message = msgBytes.bytes();
message.writeUTFΔ("Hello World");
Expand Down Expand Up @@ -59,7 +53,7 @@ public void testZipAndAppend() throws Exception {
}

// read the data from chronicle into actual
Bytes actual = NativeStore.nativeStore(100).bytes();
Bytes actual = NativeByteStore.nativeStore(100).bytes();
chronicle.readDocument(offset, actual);

// "Hello World" zipped should be 13 chars
Expand Down

0 comments on commit ae33a13

Please sign in to comment.