Skip to content

Commit

Permalink
Unit test to verify that publish failure doesn't break write state
Browse files Browse the repository at this point in the history
  • Loading branch information
akhaku committed May 8, 2018
1 parent ad7b72e commit a33811d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,10 @@ public void removeListener(HollowProducerListener listener) {
listeners.remove(listener);
}

private void publish(final WriteState writeState, final Artifacts artifacts) throws IOException {
/**
* Publish the write state, storing the artifacts in the provided object. Visible for testing.
*/
protected void publish(final WriteState writeState, final Artifacts artifacts) throws IOException {
ProducerStatus.Builder psb = listeners.firePublishStart(writeState.getVersion());
try {
stageBlob(writeState, artifacts, Blob.Type.SNAPSHOT);
Expand Down Expand Up @@ -948,11 +951,11 @@ public List<Throwable> getIndividualFailures() {
}
}

public static interface Announcer {
public void announce(long stateVersion);
public interface Announcer {
void announce(long stateVersion);
}

private static final class Artifacts {
protected static final class Artifacts {
Blob snapshot = null;
Blob delta = null;
Blob reverseDelta = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
*/
package com.netflix.hollow.api.producer;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.spy;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.objects.delegate.HollowObjectGenericDelegate;
import com.netflix.hollow.api.objects.generic.GenericHollowObject;
import com.netflix.hollow.api.producer.HollowProducer.Artifacts;
import com.netflix.hollow.api.producer.HollowProducer.Blob;
import com.netflix.hollow.api.producer.HollowProducer.Blob.Type;
import com.netflix.hollow.api.producer.HollowProducer.ReadState;
import com.netflix.hollow.api.producer.HollowProducer.WriteState;
import com.netflix.hollow.api.producer.HollowProducerListener.ProducerStatus;
import com.netflix.hollow.api.producer.HollowProducerListener.RestoreStatus;
import com.netflix.hollow.api.producer.HollowProducerListener.Status;
Expand Down Expand Up @@ -199,6 +205,25 @@ public void testPublishAndRestoreWithSchemaChanges() throws Exception {
}
}

@Test
public void testRollsBackStateEngineOnPublishFailure() throws Exception {
HollowProducer producer = spy(createProducer(tmpFolder, schema));
Assert.assertEquals("Should have no populated ordinals", 0,
producer.getWriteEngine().getTypeState("TestPojo").getPopulatedBitSet().cardinality());
doThrow(new RuntimeException("Publish failed")).when(producer).publish(
any(WriteState.class), any(Artifacts.class));
try {
producer.runCycle(new HollowProducer.Populator() {
public void populate(WriteState newState) {
newState.add(new TestPojoV1(1, 1));
}
});
} catch (RuntimeException e) { // expected
}
Assert.assertEquals("Should still have no populated ordinals", 0,
producer.getWriteEngine().getTypeState("TestPojo").getPopulatedBitSet().cardinality());
}

private long testPublishV1(HollowProducer producer, final int size, final int valueMultiplier) {
producer.runCycle(new HollowProducer.Populator() {
public void populate(HollowProducer.WriteState newState) throws Exception {
Expand Down

0 comments on commit a33811d

Please sign in to comment.