Skip to content
Closed
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
9 changes: 9 additions & 0 deletions geode-assembly/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ publishing {
}
}

task createObjectSizerTenJar(type: Jar) {
description 'Assembles jar for use in "ConfigureEvictionThroughGfsh" "deploy jar" command.'
archiveName 'ObjectSizerTen.jar'
from sourceSets.acceptanceTest.output
destinationDir new File("${buildDir}/resources/acceptanceTest")
include 'org/apache/geode/management/internal/cli/commands/ObjectSizerTen.*'
}
acceptanceTest.dependsOn createObjectSizerTenJar

logger.info("Gradle doesn't automatically remove the jar artifact even though we disabled it")
logger.info("this causes publishing to fail. So we nuke all the disabled artifacts from all configurations.")
configurations.all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,36 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import org.apache.geode.test.compiler.JarBuilder;
import org.apache.geode.test.junit.rules.gfsh.GfshExecution;
import org.apache.geode.test.junit.rules.gfsh.GfshRule;
import org.apache.geode.test.junit.rules.gfsh.GfshScript;

/**
* Consumes {@link ObjectSizerTen} as built and packaged into the jar deployed below.
*/
// GEODE-1897 Users should be able to configure eviction through gfsh
public class ConfigureEvictionThroughGfsh {

@Rule
public GfshRule gfsh = new GfshRule();

private URL jarToDeploy;

@Before
public void setJar() {
jarToDeploy = getClass().getResource("/ObjectSizerTen.jar");
assertThat(jarToDeploy).isNotNull();
}

@Test
public void configureEvictionByEntryCount() throws Exception {
public void configureEvictionByEntryCount() {

GfshExecution execution = GfshScript
.of("start locator --name=locator", "start server --name=server",
Expand Down Expand Up @@ -92,7 +103,7 @@ public void configureEvictionByEntryCount() throws Exception {
}

@Test
public void configureEvictionByMaxMemory() throws Exception {
public void configureEvictionByMaxMemory() {
GfshExecution execution = GfshScript
.of("start locator --name=locator", "start server --name=server",
"create region --name=region1 --eviction-action=local-destroy --eviction-max-memory=1000 --type=REPLICATE",
Expand Down Expand Up @@ -145,28 +156,16 @@ public void configureEvictionByMaxMemory() throws Exception {
.containsPattern("eviction-max-memory\\s+ | 1000");
}

private File createJar() throws IOException {
File jarToDeploy = new File(gfsh.getTemporaryFolder().getRoot(), "ourJar.jar");

String classContents =
"import org.apache.geode.cache.util.ObjectSizer; import org.apache.geode.cache.Declarable;public class MySizer implements ObjectSizer, Declarable { public int sizeof(Object o) { return 10; } }";

JarBuilder jarBuilder = new JarBuilder();
jarBuilder.buildJar(jarToDeploy, classContents);

return jarToDeploy;
}

@Test
public void configureEvictionByObjectSizer() throws Exception {
public void configureEvictionByObjectSizer() throws URISyntaxException {
GfshExecution execution = GfshScript
.of("start locator --name=locator", "start server --name=server", "sleep --time=1",
"deploy --jar=" + createJar().getAbsolutePath(),
"create region --name=region1 --eviction-action=local-destroy --eviction-max-memory=1000 --eviction-object-sizer=MySizer --type=REPLICATE",
"create region --name=region2 --eviction-action=overflow-to-disk --eviction-max-memory=1000 --eviction-object-sizer=MySizer --type=REPLICATE",
"create region --name=region3 --eviction-action=overflow-to-disk --eviction-max-memory=1000 --eviction-object-sizer=MySizer --type=REPLICATE_PERSISTENT",
"create region --name=region4 --eviction-action=local-destroy --eviction-max-memory=1000 --eviction-object-sizer=MySizer --type=LOCAL",
"create region --name=region5 --eviction-action=overflow-to-disk --eviction-max-memory=1000 --eviction-object-sizer=MySizer --type=LOCAL")
"deploy --jar=" + jarToDeploy.toURI().getPath(),
"create region --name=region1 --eviction-action=local-destroy --eviction-max-memory=1000 --eviction-object-sizer=org.apache.geode.management.internal.cli.commands.ObjectSizerTen --type=REPLICATE",
"create region --name=region2 --eviction-action=overflow-to-disk --eviction-max-memory=1000 --eviction-object-sizer=org.apache.geode.management.internal.cli.commands.ObjectSizerTen --type=REPLICATE",
"create region --name=region3 --eviction-action=overflow-to-disk --eviction-max-memory=1000 --eviction-object-sizer=org.apache.geode.management.internal.cli.commands.ObjectSizerTen --type=REPLICATE_PERSISTENT",
"create region --name=region4 --eviction-action=local-destroy --eviction-max-memory=1000 --eviction-object-sizer=org.apache.geode.management.internal.cli.commands.ObjectSizerTen --type=LOCAL",
"create region --name=region5 --eviction-action=overflow-to-disk --eviction-max-memory=1000 --eviction-object-sizer=org.apache.geode.management.internal.cli.commands.ObjectSizerTen --type=LOCAL")
.execute(gfsh);

assertThat(execution.getOutputText()).contains("Region \"/region1\" created on \"server\"");
Expand All @@ -177,7 +176,7 @@ public void configureEvictionByObjectSizer() throws Exception {

execution = GfshScript
.of("connect --locator=localhost[10334]",
"create region --name=region6 --eviction-action=local-destroy --eviction-max-memory=1000 --eviction-object-sizer=MySizer --type=REPLICATE_PERSISTENT")
"create region --name=region6 --eviction-action=local-destroy --eviction-max-memory=1000 --eviction-object-sizer=org.apache.geode.management.internal.cli.commands.ObjectSizerTen --type=REPLICATE_PERSISTENT")
.expectFailure().execute(gfsh);
assertThat(execution.getOutputText()).contains(
"ERROR: An Eviction Controller with local destroy eviction action is incompatible with");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more contributor license
* agreements. See the NOTICE file distributed with this work for additional information regarding
* copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the License. You may obtain a
* copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.apache.geode.management.internal.cli.commands;

import org.apache.geode.cache.Declarable;
import org.apache.geode.cache.util.ObjectSizer;

/**
* This class is built and packaged into a jar for consumption in
* {@link ConfigureEvictionThroughGfsh}
*/
@SuppressWarnings("unused")
public class ObjectSizerTen implements ObjectSizer, Declarable {
public int sizeof(Object o) {
return 10;
}
}
7 changes: 6 additions & 1 deletion gradle/test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,37 @@ subprojects {
}

task repeatDistributedTest(type: RepeatTest) {
dependsOn distributedTest.taskDependencies
classpath = project.sourceSets.distributedTest.runtimeClasspath
testClassesDirs = project.sourceSets.distributedTest.output.classesDirs
}

task repeatIntegrationTest(type: RepeatTest) {
dependsOn integrationTest.taskDependencies
classpath = project.sourceSets.integrationTest.runtimeClasspath
testClassesDirs = project.sourceSets.integrationTest.output.classesDirs
}

task repeatAcceptanceTest(type: RepeatTest) {
dependsOn acceptanceTest.taskDependencies
classpath = project.sourceSets.acceptanceTest.runtimeClasspath
testClassesDirs = project.sourceSets.acceptanceTest.output.classesDirs
}

task repeatUpgradeTest(type: RepeatTest) {
dependsOn upgradeTest.taskDependencies
classpath = project.sourceSets.upgradeTest.runtimeClasspath
testClassesDirs = project.sourceSets.upgradeTest.output.classesDirs
}

task repeatUnitTest(type: RepeatTest) {
dependsOn test.taskDependencies
// default classpath works for this one.
}

configure([repeatDistributedTest, repeatIntegrationTest, repeatUpgradeTest, repeatUnitTest, repeatAcceptanceTest]) {
times = Integer.parseInt(repeat)
useJUnit {}
useJUnit()
outputs.upToDateWhen { false }

if (project.hasProperty("failOnNoMatchingTests")) {
Expand Down