Skip to content

Commit

Permalink
CLOG-29 Bug when logging exception with the chronicle logback appender
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Feb 10, 2015
1 parent 9410371 commit a175644
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 25 deletions.
2 changes: 1 addition & 1 deletion chronicle/pom.xml
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>net.openhft</groupId>
<artifactId>lang</artifactId>
<version>6.5</version>
<version>6.5.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.openhft</groupId>
Expand Down
Expand Up @@ -22,6 +22,8 @@
import net.openhft.lang.io.NativeBytes;
import net.openhft.lang.io.VanillaMappedBlocks;
import net.openhft.lang.io.VanillaMappedBytes;
import net.openhft.lang.io.serialization.BytesMarshallableSerializer;
import net.openhft.lang.io.serialization.JDKObjectSerializer;
import net.openhft.lang.io.serialization.impl.VanillaBytesMarshallerFactory;
import net.openhft.lang.model.constraints.NotNull;
import net.openhft.lang.model.constraints.Nullable;
Expand Down Expand Up @@ -351,7 +353,16 @@ public String dumpState() {
// inherited - long limitAddr;

protected AbstractIndexedExcerpt() throws IOException {
super(new VanillaBytesMarshallerFactory(), NO_PAGE, NO_PAGE, null);
//super(new VanillaBytesMarshallerFactory(), NO_PAGE, NO_PAGE, null);
super(
BytesMarshallableSerializer.create(
new VanillaBytesMarshallerFactory(),
JDKObjectSerializer.INSTANCE),
NO_PAGE,
NO_PAGE,
null
);

cacheLineSize = IndexedChronicle.this.builder.cacheLineSize();
cacheLineMask = (cacheLineSize - 1);
dataBlockSize = IndexedChronicle.this.builder.dataBlockSize();
Expand Down
37 changes: 21 additions & 16 deletions chronicle/src/main/java/net/openhft/chronicle/VanillaChronicle.java
Expand Up @@ -25,7 +25,9 @@
import net.openhft.lang.io.IOTools;
import net.openhft.lang.io.NativeBytes;
import net.openhft.lang.io.VanillaMappedBytes;
import net.openhft.lang.io.serialization.BytesMarshallerFactory;
import net.openhft.lang.io.serialization.BytesMarshallableSerializer;
import net.openhft.lang.io.serialization.JDKObjectSerializer;
import net.openhft.lang.io.serialization.ObjectSerializer;
import net.openhft.lang.io.serialization.impl.VanillaBytesMarshallerFactory;
import net.openhft.lang.model.constraints.NotNull;

Expand Down Expand Up @@ -63,7 +65,7 @@ public class VanillaChronicle implements Chronicle {
public static final long INDEX_DATA_OFFSET_MASK = -1L >>> -INDEX_DATA_OFFSET_BITS;

private final String name;
private final ThreadLocal<WeakReference<BytesMarshallerFactory>> marshallersCache;
private final ThreadLocal<WeakReference<ObjectSerializer>> marshallersCache;
private final ThreadLocal<WeakReference<VanillaTailer>> tailerCache;
private final ThreadLocal<WeakReference<VanillaAppender>> appenderCache;
private final VanillaIndexCache indexCache;
Expand All @@ -84,7 +86,7 @@ public class VanillaChronicle implements Chronicle {

VanillaChronicle(ChronicleQueueBuilder.VanillaChronicleQueueBuilder builder) {
this.builder = builder.clone();
this.marshallersCache = new ThreadLocal<WeakReference<BytesMarshallerFactory>>();
this.marshallersCache = new ThreadLocal<WeakReference<ObjectSerializer>>();
this.tailerCache = new ThreadLocal<WeakReference<VanillaTailer>>();
this.appenderCache = new ThreadLocal<WeakReference<VanillaAppender>>();
this.name = builder.path().getName();
Expand Down Expand Up @@ -133,20 +135,23 @@ public int getEntriesForCycleBits() {
return entriesForCycleBits;
}

BytesMarshallerFactory acquireBMF() {
WeakReference<BytesMarshallerFactory> bmfRef = marshallersCache.get();
BytesMarshallerFactory bmf = null;
if (bmfRef != null)
bmf = bmfRef.get();
if (bmf == null) {
bmf = createBMF();
marshallersCache.set(new WeakReference<BytesMarshallerFactory>(bmf));
ObjectSerializer acquireSerializer() {
WeakReference<ObjectSerializer> serializerRef = marshallersCache.get();

ObjectSerializer serializer = null;
if (serializerRef != null) {
serializer = serializerRef.get();
}

if (serializer == null) {
serializer = BytesMarshallableSerializer.create(
new VanillaBytesMarshallerFactory(),
JDKObjectSerializer.INSTANCE);

marshallersCache.set(new WeakReference<ObjectSerializer>(serializer));
}
return bmf;
}

BytesMarshallerFactory createBMF() {
return new VanillaBytesMarshallerFactory();
return serializer;
}

@NotNull
Expand Down Expand Up @@ -301,7 +306,7 @@ private abstract class AbstractVanillaExcerpt extends NativeBytes implements


public AbstractVanillaExcerpt() {
super(acquireBMF(), NO_PAGE, NO_PAGE, null);
super(acquireSerializer(), NO_PAGE, NO_PAGE, null);
}


Expand Down
Expand Up @@ -22,8 +22,7 @@

import java.io.IOException;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;

public class IndexedChronicle2Test extends IndexedChronicleTestBase {

Expand Down Expand Up @@ -142,4 +141,33 @@ public void testIndexedChronicle_003() throws IOException {

assertClean(basePath);
}

@Test
public void testExceptionSerialization() throws IOException {
final String basePath = getTestPath();

final Chronicle ch = ChronicleQueueBuilder.indexed(basePath).build();
final ExcerptAppender ap = ch.createAppender();
final ExcerptTailer tl = ch.createTailer();

ap.startExcerpt();
ap.writeObject(new UnsupportedOperationException("UOE"));
ap.finish();
ap.close();

assertTrue(tl.nextIndex());
Object obj = tl.readObject();
assertNotNull(obj);
assertTrue(obj instanceof Throwable);
assertTrue(obj instanceof UnsupportedOperationException);

tl.finish();

assertFalse(tl.nextIndex());

tl.close();
ch.close();

assertClean(basePath);
}
}
Expand Up @@ -25,19 +25,46 @@
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicLong;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

public class VanillaChronicle3Test extends VanillaChronicleTestBase {

@Test
public void testFinishAfterClose() throws IOException {
public void testExceptionSerialization() throws IOException {
final String basePath = getTestPath();

final Chronicle ch = ChronicleQueueBuilder.vanilla(basePath).build();
final ExcerptAppender ap = ch.createAppender();
final ExcerptTailer tl = ch.createTailer();

ap.startExcerpt();
ap.writeObject(new UnsupportedOperationException("UOE"));
ap.finish();
ap.close();

assertTrue(tl.nextIndex());
Object obj = tl.readObject();
assertNotNull(obj);
assertTrue(obj instanceof Throwable);
assertTrue(obj instanceof UnsupportedOperationException);

tl.finish();

assertFalse(tl.nextIndex());

tl.close();
ch.close();
ch.clear();

assertFalse(new File(basePath).exists());
}

@Test
public void testVanillaFinishAfterClose() throws IOException {
final String basePath = getTestPath();
final VanillaChronicle chronicle = (VanillaChronicle)ChronicleQueueBuilder.vanilla(basePath).build();
final ExcerptAppender appender = chronicle.createAppender();
Expand Down Expand Up @@ -137,7 +164,7 @@ public void testJira92() throws Exception {
}

@Test
public void testCheckedVanillaExcerpt_001() throws IOException {
public void testCheckedVanillaExcerpt() throws IOException {
final String basePath = getTestPath();
final VanillaChronicle chronicle = (VanillaChronicle)ChronicleQueueBuilder.vanilla(basePath)
.useCheckedExcerpt(true)
Expand Down

0 comments on commit a175644

Please sign in to comment.