Skip to content
Open
Show file tree
Hide file tree
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
@@ -0,0 +1 @@
Core: A default value of `true` for `MESH_HIBERNATE_SECOND_LEVEL_CACHE_ENABLED` config has been restored, enabling the second level SQL cache. The startup of a second level cache in the cluster environment has been fixed.
11 changes: 11 additions & 0 deletions connectors/common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
<artifactId>mesh-mdm-hibernate-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.gentics.mesh</groupId>
<artifactId>mesh-database-tests-common</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.gentics.mesh</groupId>
<artifactId>mesh-test-common</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.gentics.mesh.core;

import com.gentics.mesh.etc.config.HibernateMeshOptions;
import com.gentics.mesh.test.MeshOptionsProvider;
import com.gentics.mesh.test.MeshTestContextProvider;

public class ExternalDatabaseTestContextProvider extends HibernateTestContextProvider implements MeshTestContextProvider {

static {
System.setProperty(MeshOptionsProvider.ENV_OPTIONS_PROVIDER_CLASS, ExternalDatabaseTestContextProvider.class.getCanonicalName());
}

@Override
public void fillMeshOptions(HibernateMeshOptions meshOptions) {
// Taken from the env variables of HibernateMeshOptions
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example setup:

optionsProviderClass=com.gentics.mesh.core.ExternalDatabaseTestContextProvider
testContextProviderClass=com.gentics.mesh.core.ExternalDatabaseTestContextProvider
LIQUIBASE_DUPLICATE_FILE_MODE=WARN
MESH_DATABASE_ADDRESS=<db_address>
MESH_JDBC_DATABASE_NAME=<db_name>
MESH_DB_CONNECTOR_CLASSPATH=<folder_with_connector_and_driver>
MESH_JDBC_CONNECTION_USERNAME=<db_username>
MESH_JDBC_CONNECTION_PASSWORD=<db_password>
LICENSEKEY=<license_if_required>

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -123,5 +123,4 @@ public Comparator<String> reversed() {
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class HibernateStorageOptions implements Option {
public static final String DEFAULT_CONNECTION_PASSWORD = "admin";
public static final Boolean DEFAULT_SHOW_SQL = false;
public static final Boolean DEFAULT_FORMAT_SQL = false;
public static final Boolean DEFAULT_SECOND_LEVEL_CACHE_ENABLED = false;
public static final Boolean DEFAULT_SECOND_LEVEL_CACHE_ENABLED = true;
public static final Boolean DEFAULT_GENERATE_STATISTICS = false;
public static final long DEFAULT_QUERY_TIMEOUT = 0;
public static final int DEFAULT_HIBERNATE_JDBC_BATCH_SIZE = 5;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private void setSecondLevelCacheOptions(ImmutableMap.Builder<String, Object> opt
if (options.getClusterOptions().isEnabled()) {
optionBuilder
.put("hibernate.cache.region.factory_class", HazelcastLocalCacheRegionFactory.class.getName())
.put("hibernate.cache.hazelcast.instance_name", options.getClusterOptions().getClusterName());
.put("hibernate.cache.hazelcast.instance_name", options.getNodeName());
} else {
optionBuilder
.put("hibernate.cache.region.factory_class", JCacheRegionFactory.class.getName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Objects;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.function.Function;

import org.apache.commons.lang3.StringUtils;

Expand Down Expand Up @@ -43,7 +46,7 @@ public interface MeshOptionsProvider {
* @return
*/
public static MeshOptionsProvider getProvider() {
return spawnProviderInstance(System.getProperty(ENV_OPTIONS_PROVIDER_CLASS), MeshOptionsProvider.class);
return spawnProviderInstance(getOptionalConfig(ENV_OPTIONS_PROVIDER_CLASS, (String)null, Function.identity(), Object::toString), MeshOptionsProvider.class);
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -99,4 +102,25 @@ static <T extends MeshOptionsProvider> boolean isEligible(Class<T> classOfT) {
return true;
}
}

/**
* Get an optional configuration from either the environment variable, or the system parameter.
*
* @param <T>
* @param configName
* @param defaultValue
* @param parse
* @param stringify
* @return
*/
static <T> T getOptionalConfig(String configName, T defaultValue, Function<String, T> parse, Function<T, String> stringify) {
return parse.apply(System.getenv()
.entrySet().stream()
.filter(e -> e.getKey().equals(configName))
.map(e -> e.getValue())
.filter(Objects::nonNull)
.findAny()
.or(() -> Optional.ofNullable(System.getProperty(configName, stringify.apply(defaultValue))))
.orElseGet(() -> stringify.apply(defaultValue)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,15 @@ private void addUserGroupRoleProject(Tx tx) {
project.addLanguage(tx.languageDao().findByLanguageTag(getGerman()));
}
HibUser jobUser = userInfo.getUser();
//schemaDao.assign(getSchemaContainer("folder"), project, jobUser, batch); // already done
schemaDao.assign(getSchemaContainer("content"), project, jobUser, batch);
schemaDao.assign(getSchemaContainer("binary_content"), project, jobUser, batch);
if (!schemaDao.isLinkedToProject(getSchemaContainer("folder"), project)) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make the existing database reusable again.

schemaDao.assign(getSchemaContainer("folder"), project, jobUser, batch);
}
if (!schemaDao.isLinkedToProject(getSchemaContainer("content"), project)) {
schemaDao.assign(getSchemaContainer("content"), project, jobUser, batch);
}
if (!schemaDao.isLinkedToProject(getSchemaContainer("binary_content"), project)) {
schemaDao.assign(getSchemaContainer("binary_content"), project, jobUser, batch);
}
projectUuid = project.getUuid();
branchUuid = project.getInitialBranch().getUuid();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.gentics.mesh.test;

import java.util.Comparator;
import java.util.function.Function;

import com.gentics.mesh.etc.config.MeshOptions;

Expand Down Expand Up @@ -31,7 +32,7 @@ public interface MeshTestContextProvider extends MeshOptionsProvider {
* @return
*/
public static MeshTestContextProvider getProvider() {
return MeshOptionsProvider.spawnProviderInstance(System.getProperty(ENV_TEST_CONTEXT_PROVIDER_CLASS), MeshTestContextProvider.class);
return MeshOptionsProvider.spawnProviderInstance(MeshOptionsProvider.getOptionalConfig(ENV_TEST_CONTEXT_PROVIDER_CLASS, (String)null, Function.identity(), Object::toString), MeshTestContextProvider.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import static com.gentics.mesh.test.TestDataProvider.PROJECT_NAME;
import static org.junit.Assert.assertEquals;

import java.util.Optional;
import java.util.UUID;
import java.util.function.BiFunction;

import org.junit.After;
import org.junit.Before;

Expand All @@ -13,10 +17,12 @@
import com.gentics.mesh.core.rest.node.FieldMapImpl;
import com.gentics.mesh.core.rest.node.NodeCreateRequest;
import com.gentics.mesh.core.rest.node.NodeListResponse;
import com.gentics.mesh.core.rest.node.NodeUpsertRequest;
import com.gentics.mesh.core.rest.schema.impl.SchemaReferenceImpl;
import com.gentics.mesh.parameter.impl.DeleteParametersImpl;
import com.gentics.mesh.parameter.impl.VersioningParametersImpl;
import com.gentics.mesh.test.context.AbstractMeshTest;
import com.gentics.mesh.util.UUIDUtil;

public abstract class AbstractMassiveNodeLoadTest extends AbstractMeshTest {

Expand Down Expand Up @@ -44,19 +50,34 @@ public void nukeEmAll() {
}

protected void makeEmAll(long howMany, String parentNodeUuid) {
makeEmAll(howMany, parentNodeUuid, false, Optional.empty());
}

protected void makeEmAll(long howMany, String parentNodeUuid, boolean publish, Optional<BiFunction<UUID, Integer, UUID>> maybeUuidProvider) {
try (Tx tx = tx()) {
if (parentFolderUuid == null) {
SchemaReferenceImpl schemaReference = new SchemaReferenceImpl();
schemaReference.setName("folder");
NodeCreateRequest create2 = new NodeCreateRequest();
FieldMap fields = new FieldMapImpl();
fields.put("name", FieldUtil.createStringField("MassiveParentFolder"));
fields.put("slug", FieldUtil.createStringField("massiveparentfolder"));
create2.setFields(fields);
create2.setSchema(schemaReference);
create2.setLanguage("en");
create2.setParentNodeUuid(parentNodeUuid);
parentFolderUuid = call(() -> client().createNode(PROJECT_NAME, create2)).getUuid();
parentFolderUuid = maybeUuidProvider.map(uuidProvider -> {
NodeUpsertRequest create2 = new NodeUpsertRequest();
create2.setFields(fields);
create2.setSchema(schemaReference);
create2.setLanguage("en");
create2.setParentNodeUuid(parentNodeUuid);
create2.setPublish(publish);
return call(() -> client().upsertNode(PROJECT_NAME, UUIDUtil.toShortUuid(maybeUuidProvider.get().apply(UUIDUtil.toJavaUuid(parentNodeUuid), -1)), create2)).getUuid();
}).orElseGet(() -> {
NodeCreateRequest create2 = new NodeCreateRequest();
create2.setFields(fields);
create2.setSchema(schemaReference);
create2.setLanguage("en");
create2.setParentNodeUuid(parentNodeUuid);
create2.setPublish(publish);
return call(() -> client().createNode(PROJECT_NAME, create2)).getUuid();
});
}

NodeListResponse nodeList = call(() -> client().findNodeChildren(PROJECT_NAME, parentFolderUuid, new VersioningParametersImpl().draft()));
Expand All @@ -66,15 +87,27 @@ protected void makeEmAll(long howMany, String parentNodeUuid) {
schemaReference.setName("folder");

for (int i = 0; i < howMany; i++) {
NodeCreateRequest create2 = new NodeCreateRequest();
final int ii = i;
FieldMap fields = new FieldMapImpl();
fields.put("name", FieldUtil.createStringField("Folder " + i));
fields.put("slug", FieldUtil.createStringField("folder" + i));
create2.setFields(fields);
create2.setSchema(schemaReference);
create2.setLanguage("en");
create2.setParentNodeUuid(parentFolderUuid);
call(() -> client().createNode(PROJECT_NAME, create2));
maybeUuidProvider.ifPresentOrElse(uuidProvider -> {
NodeUpsertRequest upsert2 = new NodeUpsertRequest();
upsert2.setFields(fields);
upsert2.setSchema(schemaReference);
upsert2.setLanguage("en");
upsert2.setParentNodeUuid(parentFolderUuid);
upsert2.setPublish(publish);
call(() -> client().upsertNode(PROJECT_NAME, UUIDUtil.toShortUuid(uuidProvider.apply(UUIDUtil.toJavaUuid(parentFolderUuid), ii)), upsert2));
}, () -> {
NodeCreateRequest create2 = new NodeCreateRequest();
create2.setFields(fields);
create2.setSchema(schemaReference);
create2.setLanguage("en");
create2.setParentNodeUuid(parentFolderUuid);
create2.setPublish(publish);
call(() -> client().createNode(PROJECT_NAME, create2));
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class NodeLotOfChildrenTest extends AbstractMassiveNodeLoadTest {

@Test
public void testReadAll() {
String uuid = tx(() -> project().getBaseNode().getUuid());
NodeListResponse nodeList = call(() -> client().findNodeChildren(PROJECT_NAME, parentFolderUuid, new VersioningParametersImpl().draft()));
assertEquals("The subnode did not contain the created node", numOfNodesPerLevel, nodeList.getData().size());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.gentics.mesh.cache;

import java.time.Instant;
import java.time.format.DateTimeFormatter;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.function.BiFunction;

import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.rules.Timeout;

import com.gentics.mesh.core.node.AbstractMassiveNodeLoadTest;
import com.gentics.mesh.util.UUIDUtil;

import ch.qos.logback.core.util.Duration;

public abstract class AbstractMassivePublishTest extends AbstractMassiveNodeLoadTest {

/**
* Global Test Timeout of 60 Minutes, to fit 'em all
*/
public static Timeout globalTimeout= new Timeout(60, TimeUnit.MINUTES);

@ClassRule
public static RuleChain chain = RuleChain.outerRule(globalTimeout).around(testContext);

protected static final UUID VERY_BASE_UUID = UUIDUtil.toJavaUuid("6B06697A9ABE11F096B6F7559C093C6E");

public AbstractMassivePublishTest() {
super(10000);
}

@Before
public void makeEmAll() {
// No make yet
}

@Test
public void testAndMeasureMassivePublish() {
Instant started = Instant.now();
System.out.println(String.format("Publish started at %s", DateTimeFormatter.ISO_INSTANT.format(started)));
makeEmAll(numOfNodesPerLevel, tx(() -> project().getBaseNode().getUuid()), true, getMaybeUuidProvider());
Instant ended = Instant.now();
System.out.println(String.format("Publish ended at %s, duration %s", DateTimeFormatter.ISO_INSTANT.format(ended), Duration.buildByMilliseconds(ended.toEpochMilli() - started.toEpochMilli())));
}

protected abstract Optional<BiFunction<UUID, Integer, UUID>> getMaybeUuidProvider();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.gentics.mesh.cache;

import static com.gentics.mesh.test.ElasticsearchTestMode.TRACKING;
import static com.gentics.mesh.test.TestSize.FULL;

import java.math.BigInteger;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiFunction;

import org.junit.experimental.categories.Category;

import com.gentics.mesh.etc.config.HibernateMeshOptions;
import com.gentics.mesh.etc.config.MeshOptions;
import com.gentics.mesh.test.MeshOptionChanger;
import com.gentics.mesh.test.MeshTestSetting;
import com.gentics.mesh.test.category.FailingTests;
import com.gentics.mesh.util.UUIDUtil;

@MeshTestSetting(elasticsearch = TRACKING, testSize = FULL, startServer = true, customOptionChanger = NodeMassiveOrderedPublishTestCached.class)
@Category({FailingTests.class})
//Not actually failing, but may last long
public class NodeMassiveOrderedPublishTestCached extends AbstractMassivePublishTest implements MeshOptionChanger {

@Override
public void change(MeshOptions options) {
HibernateMeshOptions.class.cast(options).getStorageOptions().setSecondLevelCacheEnabled(true);
}

@Override
protected Optional<BiFunction<UUID, Integer, UUID>> getMaybeUuidProvider() {
return Optional.of((uuid, i) -> {
if (i < 0) {
i = 0;
uuid = VERY_BASE_UUID;
}
BigInteger number = new BigInteger(UUIDUtil.toBytes(uuid));
// Minus!
number = number.subtract(BigInteger.valueOf(i));
return UUIDUtil.toJavaUuid(number.toByteArray());
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.gentics.mesh.cache;

import static com.gentics.mesh.test.ElasticsearchTestMode.TRACKING;
import static com.gentics.mesh.test.TestSize.FULL;

import java.math.BigInteger;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiFunction;

import org.junit.experimental.categories.Category;

import com.gentics.mesh.etc.config.HibernateMeshOptions;
import com.gentics.mesh.etc.config.MeshOptions;
import com.gentics.mesh.test.MeshOptionChanger;
import com.gentics.mesh.test.MeshTestSetting;
import com.gentics.mesh.test.category.FailingTests;
import com.gentics.mesh.util.UUIDUtil;

@MeshTestSetting(elasticsearch = TRACKING, testSize = FULL, startServer = true, customOptionChanger = NodeMassiveOrderedPublishTestNoCache.class)
@Category({FailingTests.class})
//Not actually failing, but may last long
public class NodeMassiveOrderedPublishTestNoCache extends AbstractMassivePublishTest implements MeshOptionChanger {

@Override
public void change(MeshOptions options) {
HibernateMeshOptions.class.cast(options).getStorageOptions().setSecondLevelCacheEnabled(false);
}

@Override
protected Optional<BiFunction<UUID, Integer, UUID>> getMaybeUuidProvider() {
return Optional.of((uuid, i) -> {
if (i < 0) {
i = 0;
uuid = VERY_BASE_UUID;
}
BigInteger number = new BigInteger(UUIDUtil.toBytes(uuid));
// Plus!
number = number.add(BigInteger.valueOf(i));
return UUIDUtil.toJavaUuid(number.toByteArray());
});
}
}
Loading