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 1 commit
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,7 +32,6 @@
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;
Expand All @@ -47,7 +47,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 +60,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 +153,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 +186,53 @@ 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 = "cdpst1";
String testNodeName2 = "cdpst2";

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

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

// TODO: is there a utility to map these to DS node names?
removeMe.add("0:/");
removeMe.add("1:/" + testNodeName1);
removeMe.add("1:/" + testNodeName2);
}

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