Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAK-11113: Change CompressedDocumentPropertyStateTest to extend AbstractDocumentStoreTest (and remove test nodes) #1751

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
*/
package org.apache.jackrabbit.oak.plugins.document;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
Expand All @@ -31,14 +32,14 @@
import java.util.Objects;
import java.util.Set;

import com.mongodb.ReadPreference;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.jackrabbit.oak.api.CommitFailedException;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.Compression;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoDocumentStore;
import org.apache.jackrabbit.oak.plugins.document.mongo.MongoTestUtils;
import org.apache.jackrabbit.oak.plugins.document.util.Utils;
import org.apache.jackrabbit.oak.spi.blob.BlobStore;
import org.apache.jackrabbit.oak.spi.blob.MemoryBlobStore;
import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
Expand All @@ -47,7 +48,9 @@
import org.junit.Rule;
import org.junit.Test;

public class CompressedDocumentPropertyStateTest {
import com.mongodb.ReadPreference;

public class CompressedDocumentPropertyStateTest extends AbstractDocumentStoreTest {

private static final String STRING_HUGEVALUE = RandomStringUtils.random(10050, "dummytest");
private static final int DEFAULT_COMPRESSION_THRESHOLD = 1024;
Expand All @@ -58,6 +61,10 @@ public class CompressedDocumentPropertyStateTest {

private Set<String> reads = new HashSet<>();

public CompressedDocumentPropertyStateTest(DocumentStoreFixture dsf) {
super(dsf);
}

private BlobStore bs = new MemoryBlobStore() {
@Override
public InputStream getInputStream(String blobId)
Expand Down Expand Up @@ -147,7 +154,6 @@ public void testOneCompressOtherUncompressInEquals() throws IOException {
DocumentNodeStore store = mock(DocumentNodeStore.class);
String name = "propertyName";
String value = "testValue";
Compression compression = Compression.GZIP;

// Create a PropertyState instance with a compressed value
CompressedDocumentPropertyState.setCompressionThreshold(1);
Expand Down Expand Up @@ -181,80 +187,50 @@ public void testInterestingStringsWithCompression() {
}

@Test
public void testBrokenSurrogateWithoutCompressionForMongo() throws CommitFailedException {
getBrokenSurrogateAndInitializeDifferentStores(DocumentStoreFixture.MONGO, false);
}

@Test
public void testBrokenSurrogateWithoutCompressionForRDB() throws CommitFailedException {
getBrokenSurrogateAndInitializeDifferentStores(DocumentStoreFixture.RDB_H2, false);
public void testBrokenSurrogateWithoutCompression() throws CommitFailedException {
getBrokenSurrogateAndInitializeDifferentStores(false);
}

@Test
public void testBrokenSurrogateWithoutCompressionForInMemory() throws CommitFailedException {
getBrokenSurrogateAndInitializeDifferentStores(DocumentStoreFixture.MEMORY, false);
}

@Test
public void testBrokenSurrogateWithCompressionForMongo() throws CommitFailedException {
public void testBrokenSurrogateWithCompression() throws CommitFailedException {
CompressedDocumentPropertyState.setCompressionThreshold(1);
getBrokenSurrogateAndInitializeDifferentStores(DocumentStoreFixture.MONGO, true);
getBrokenSurrogateAndInitializeDifferentStores(true);
}

@Test
public void testBrokenSurrogateWithCompressionForRDB() throws CommitFailedException {
CompressedDocumentPropertyState.setCompressionThreshold(1);
getBrokenSurrogateAndInitializeDifferentStores(DocumentStoreFixture.RDB_H2, true);
}

@Test
public void testBrokenSurrogateWithCompressionForInMemory() throws CommitFailedException {
CompressedDocumentPropertyState.setCompressionThreshold(1);
getBrokenSurrogateAndInitializeDifferentStores(DocumentStoreFixture.MEMORY, true);
}

private void getBrokenSurrogateAndInitializeDifferentStores(DocumentStoreFixture fixture, boolean compressionEnabled) throws CommitFailedException {
assumeTrue(fixture.isAvailable());
private void getBrokenSurrogateAndInitializeDifferentStores(boolean compressionEnabled) throws CommitFailedException {
assumeTrue(dsf.isAvailable());
String test = "brokensurrogate:dfsa\ud800";
DocumentStore store = null;
DocumentNodeStore nodeStore = null;

try {
store = fixture.createDocumentStore();

if (store instanceof MongoDocumentStore) {
// Enforce primary read preference, otherwise tests may fail on a
// replica set with a read preference configured to secondary.
// Revision GC usually runs with a modified range way in the past,
// which means changes made it to the secondary, but not in this
// test using a virtual clock
MongoTestUtils.setReadPreference(store, ReadPreference.primary());
}
nodeStore = new DocumentMK.Builder().setDocumentStore(store).getNodeStore();

createPropAndCheckValue(nodeStore, test, compressionEnabled);

} finally {
if (nodeStore != null) {
nodeStore.dispose();
}
if (ds instanceof MongoDocumentStore) {
// Enforce primary read preference, otherwise tests may fail on a
// replica set with a read preference configured to secondary.
// Revision GC usually runs with a modified range way in the past,
// which means changes made it to the secondary, but not in this
// test using a virtual clock
MongoTestUtils.setReadPreference(ds, ReadPreference.primary());
}
nodeStore = new DocumentMK.Builder().setDocumentStore(ds).getNodeStore();

createPropAndCheckValue(nodeStore, test, compressionEnabled);
}

private void createPropAndCheckValue(DocumentNodeStore nodeStore, String test, boolean compressionEnabled) throws CommitFailedException {
NodeBuilder builder = nodeStore.getRoot().builder();
String testNodeName1 = "cdpst";

if (compressionEnabled) {
CompressedDocumentPropertyState.setCompressionThreshold(1);
}
builder.child("test").setProperty("p", test, Type.STRING);
builder.child(testNodeName1).setProperty("p", test, Type.STRING);
TestUtils.merge(nodeStore, builder);

PropertyState p = nodeStore.getRoot().getChildNode("test").getProperty("p");
PropertyState p = nodeStore.getRoot().getChildNode(testNodeName1).getProperty("p");
assertEquals(Objects.requireNonNull(p).getValue(Type.STRING), test);
}

removeMe.add(Utils.getIdFromPath("/"));
removeMe.add(Utils.getIdFromPath("/" + testNodeName1));
}

@Test
public void testEqualsWithCompression() throws IOException {
Expand Down
Loading