Skip to content

Commit

Permalink
Expose InMemoryBlobStore as test utility under hollow-test
Browse files Browse the repository at this point in the history
  • Loading branch information
nayanika-u committed Sep 28, 2023
1 parent 87aeb96 commit af24abd
Show file tree
Hide file tree
Showing 33 changed files with 73 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
* limitations under the License.
*
*/
package com.netflix.hollow.api.consumer;
package com.netflix.hollow.test;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.HollowConsumer.Blob;
import com.netflix.hollow.api.consumer.HollowConsumer.BlobRetriever;
import com.netflix.hollow.api.consumer.HollowConsumer.HeaderBlob;
Expand All @@ -30,14 +31,14 @@

/// This InMemoryBlobStore is both a HollowProducer.Publisher and HollowConsumer.BlobRetriever!
public class InMemoryBlobStore implements BlobRetriever, Publisher {

private final Set<String> optionalPartsToRetrieve;

private Map<Long, Blob> snapshots;
private Map<Long, Blob> deltas;
private Map<Long, Blob> reverseDeltas;
private Map<Long, HeaderBlob> headers;

public InMemoryBlobStore() {
this(null);
}
Expand All @@ -50,14 +51,14 @@ public InMemoryBlobStore(Set<String> optionalPartsToRetrieve) {
this.optionalPartsToRetrieve = optionalPartsToRetrieve;
}

private HollowConsumer.VersionedBlob getDesiredVersion(long desiredVersion, Map<Long, ? extends HollowConsumer.VersionedBlob> map) {
HollowConsumer.VersionedBlob snapshot = map.get(desiredVersion);
private HollowConsumer.Blob getDesiredVersion(long desiredVersion, Map<Long, ? extends HollowConsumer.Blob> map) {
HollowConsumer.Blob snapshot = map.get(desiredVersion);
if(snapshot != null)
return snapshot;

long greatestPriorSnapshotVersion = Long.MIN_VALUE;

for(Map.Entry<Long, ? extends HollowConsumer.VersionedBlob> entry : map.entrySet()) {
for(Map.Entry<Long, ? extends HollowConsumer.Blob> entry : map.entrySet()) {
if(entry.getKey() > greatestPriorSnapshotVersion && entry.getKey() < desiredVersion)
greatestPriorSnapshotVersion = entry.getKey();
}
Expand All @@ -67,7 +68,7 @@ private HollowConsumer.VersionedBlob getDesiredVersion(long desiredVersion, Map<

@Override
public Blob retrieveSnapshotBlob(long desiredVersion) {
return (Blob) getDesiredVersion(desiredVersion, snapshots);
return getDesiredVersion(desiredVersion, snapshots);
}

@Override
Expand Down Expand Up @@ -134,22 +135,23 @@ public OptionalBlobPartInput getOptionalBlobPartInputs() throws IOException {
return parts;
}
};

switch(blob.getType()) {
case SNAPSHOT:
snapshots.put(blob.getToVersion(), consumerBlob);
break;
case DELTA:
deltas.put(blob.getFromVersion(), consumerBlob);
break;
case REVERSE_DELTA:
reverseDeltas.put(blob.getFromVersion(), consumerBlob);
break;
case SNAPSHOT:
snapshots.put(blob.getToVersion(), consumerBlob);
break;
case DELTA:
deltas.put(blob.getFromVersion(), consumerBlob);
break;
case REVERSE_DELTA:
reverseDeltas.put(blob.getFromVersion(), consumerBlob);
break;
}
}

public void removeSnapshot(long version) {
snapshots.remove(version);
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.core.schema.HollowObjectSchema;
import com.netflix.hollow.core.write.objectmapper.HollowPrimaryKey;
import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import com.netflix.hollow.core.util.HollowObjectHashCodeFinder;
import java.util.List;
import java.util.concurrent.Executor;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.io.InputStream;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.BooleanSupplier;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.netflix.hollow.core.memory.MemoryMode;
import com.netflix.hollow.core.read.engine.object.HollowObjectTypeReadState;
import com.netflix.hollow.core.read.filter.TypeFilter;
import com.netflix.hollow.test.InMemoryBlobStore;
import com.netflix.hollow.tools.compact.HollowCompactor.CompactionConfig;
import java.time.Duration;
import java.util.BitSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
import java.util.ArrayList;
import java.util.List;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.io.IOException;
import java.nio.file.Files;
import java.util.Collections;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static java.util.stream.Collectors.toList;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.objects.HollowObject;
import com.netflix.hollow.api.objects.HollowRecord;
import com.netflix.hollow.api.objects.delegate.HollowObjectDelegate;
Expand All @@ -19,6 +18,8 @@
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.netflix.hollow.api.consumer.index;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import static java.util.stream.Collectors.toList;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.objects.HollowObject;
import com.netflix.hollow.api.objects.HollowRecord;
import com.netflix.hollow.api.objects.delegate.HollowObjectDelegate;
Expand All @@ -32,6 +31,8 @@
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Stream;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
package com.netflix.hollow.api.consumer.index;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import static org.mockito.Mockito.when;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.core.read.engine.HollowReadStateEngine;
Expand All @@ -17,6 +16,8 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.netflix.hollow.api.metrics;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.netflix.hollow.api.metrics;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.netflix.hollow.api.metrics;

import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.HollowProducerFakeListener;
import com.netflix.hollow.api.producer.HollowProducerListener;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.netflix.hollow.api.producer;

import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.core.schema.HollowMapSchema;
import com.netflix.hollow.core.util.HollowObjectHashCodeFinder;
Expand All @@ -10,6 +9,8 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.netflix.hollow.api.producer;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.objects.generic.GenericHollowObject;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.core.index.HollowPrimaryKeyIndex;
import com.netflix.hollow.core.write.objectmapper.HollowPrimaryKey;
import java.util.Arrays;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.mockito.ArgumentMatchers.any;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.objects.HollowObject;
import com.netflix.hollow.api.objects.generic.GenericHollowObject;
import com.netflix.hollow.api.producer.HollowProducer.Populator;
Expand Down Expand Up @@ -48,6 +47,8 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.TimeUnit;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.netflix.hollow.api.producer;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.objects.generic.GenericHollowObject;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.core.index.HollowPrimaryKeyIndex;
import com.netflix.hollow.core.write.objectmapper.HollowPrimaryKey;
import java.util.Arrays;
import java.util.stream.IntStream;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.junit.Assert.assertEquals;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.objects.HollowObject;
import com.netflix.hollow.api.objects.generic.GenericHollowObject;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
Expand All @@ -38,6 +37,8 @@
import java.util.Collection;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.netflix.hollow.api.producer;

import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.enforcer.SingleProducerEnforcer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.api.producer.listener.AnnouncementListener;
Expand All @@ -23,6 +22,8 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionException;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.netflix.hollow.api.producer;

import com.netflix.hollow.api.consumer.HollowConsumer;
import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.core.HollowBlobHeader;
import com.netflix.hollow.core.HollowStateEngine;
import com.netflix.hollow.core.read.engine.HollowBlobHeaderReader;
import java.io.IOException;
import java.util.function.Function;

import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
*/
package com.netflix.hollow.api.producer.validation;

import com.netflix.hollow.api.consumer.InMemoryBlobStore;
import com.netflix.hollow.api.producer.HollowProducer;
import com.netflix.hollow.api.producer.fs.HollowInMemoryBlobStager;
import com.netflix.hollow.test.InMemoryBlobStore;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
Expand Down
Loading

0 comments on commit af24abd

Please sign in to comment.