Skip to content

Commit

Permalink
GEODE-1930: apply build and dunit changes to support JMX tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kirklund committed Jan 25, 2017
1 parent 44cd72d commit e3eb927
Show file tree
Hide file tree
Showing 19 changed files with 343 additions and 61 deletions.
1 change: 1 addition & 0 deletions geode-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ dependencies {

// Test Dependencies
// External
testCompile 'com.jayway.jsonpath:json-path-assert:' + project.'json-path-assert.version'
testCompile 'org.apache.bcel:bcel:' + project.'bcel.version'
testRuntime 'org.apache.derby:derby:' + project.'derby.version'
testCompile 'org.mockito:mockito-core:' + project.'mockito-core.version'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.apache.geode.management;

import java.beans.ConstructorProperties;
import java.io.Serializable;

import org.apache.geode.cache.Region;

Expand All @@ -25,7 +26,7 @@
* @since GemFire 7.0
*
*/
public class JVMMetrics {
public class JVMMetrics implements Serializable {

/**
* Number of GCs performed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package org.apache.geode.management;

import java.beans.ConstructorProperties;
import java.io.Serializable;

/**
* Composite data type used to distribute metrics for the operating system hosting a member of the
Expand All @@ -23,7 +24,7 @@
* @since GemFire 7.0
*
*/
public class OSMetrics {
public class OSMetrics implements Serializable {

/**
* Maximum number file descriptor which can be opened
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ public RegionMXBean getLocalRegionMBean(String regionPath) {
}


public <T> T getMBeanProxy(ObjectName objectName, Class<T> interfaceClass) {
public <T> T getMBeanProxy(ObjectName objectName, Class<T> interfaceClass) { // TODO: this is too
// generic
if (!isStartedAndOpen()) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@
import org.apache.geode.internal.cache.DistributedCacheOperation;
import org.apache.geode.internal.cache.GemFireCacheImpl;
import org.apache.geode.internal.cache.LocalRegion;
import org.apache.geode.pdx.internal.EnumId;
import org.apache.geode.pdx.internal.EnumInfo;
import org.apache.geode.pdx.internal.PeerTypeRegistration;
import org.apache.geode.pdx.internal.TypeRegistry;
import org.apache.geode.test.dunit.AsyncInvocation;
import org.apache.geode.test.dunit.DUnitBlackboard;
import org.apache.geode.test.dunit.Host;
Expand All @@ -60,16 +58,6 @@
@Category({DistributedTest.class, SerializationTest.class})
public class PdxSerializableDUnitTest extends JUnit4CacheTestCase {

public Cache getCache(Properties properties) {
getSystem(properties);
return getCache();
}


public PdxSerializableDUnitTest() {
super();
}

@Test
public void testSimplePut() {
Host host = Host.getHost(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,58 @@ public synchronized boolean cancel(final boolean mayInterruptIfRunning) {
return false;
}

/**
* Waits if necessary for at most the given time for the computation to complete.
*
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
*
* @return this {@code AsyncInvocation}
*
* @throws AssertionError wrapping any {@code Exception} thrown by this {@code AsyncInvocation}.
*
* @throws CancellationException if the computation was cancelled
*
* @throws ExecutionException if the computation threw an exception
*
* @throws InterruptedException if the current thread is interrupted.
*
* @throws TimeoutException if the wait timed out
*/
public AsyncInvocation<V> await(final long timeout, final TimeUnit unit)
throws ExecutionException, InterruptedException, TimeoutException {
long millis = unit.toMillis(timeout);
join(millis);
timeoutIfAlive(millis);
checkException();
return this;
}

/**
* Waits if necessary for at most the given time for the computation to complete.
*
* @return this {@code AsyncInvocation}
*
* @throws AssertionError wrapping any {@code Exception} thrown by this {@code AsyncInvocation}.
*
* @throws AssertionError wrapping a {@code TimeoutException} if this {@code AsyncInvocation}
* fails to complete within the default timeout of 60 seconds as defined by
* {@link #DEFAULT_JOIN_MILLIS}.
*
* @throws CancellationException if the computation was cancelled
*
* @throws ExecutionException if the computation threw an exception
*
* @throws InterruptedException if the current thread is interrupted.
*/
public AsyncInvocation<V> await() throws ExecutionException, InterruptedException {
try {
return await(DEFAULT_JOIN_MILLIS, TimeUnit.MILLISECONDS);
} catch (TimeoutException timeoutException) {
throw new AssertionError(timeoutException);
}
}

/**
* Waits if necessary for the work to complete, and then returns the result of this
* {@code AsyncInvocation}.
Expand Down Expand Up @@ -353,10 +405,6 @@ public V get() throws ExecutionException, InterruptedException {
*
* @throws AssertionError wrapping any {@code Exception} thrown by this {@code AsyncInvocation}.
*
* @throws AssertionError wrapping a {@code TimeoutException} if this {@code AsyncInvocation}
* fails to complete within the default timeout of 60 seconds as defined by
* {@link #DEFAULT_JOIN_MILLIS}.
*
* @throws CancellationException if the computation was cancelled
*
* @throws ExecutionException if the computation threw an exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ public final Cache getCache(final CacheFactory factory) {
return getCache(false, factory);
}

public final Cache getCache(final Properties properties) {
getSystem(properties);
return getCache();
}

public final Cache getCache(final boolean client) {
return getCache(client, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ protected JUnit4DistributedTestCase(final DistributedTestFixture distributedTest
}

@Rule
public SerializableTestName testName = new SerializableTestName();
public SerializableTestName testNameForDistributedTestCase = new SerializableTestName();

private static DUnitBlackboard blackboard;

Expand All @@ -139,7 +139,7 @@ public final String getName() {
if (this.distributedTestFixture != this) {
return this.distributedTestFixture.getName();
}
return this.testName.getMethodName();
return this.testNameForDistributedTestCase.getMethodName();
}

public final Class<? extends DistributedTestFixture> getTestClass() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ public DistributedDisconnectRule(final RemoteInvoker invoker, final Builder buil
@Override
protected void before() throws Throwable {
if (this.disconnectBefore) {
invoker().invokeEverywhere(serializableRunnable());
invoker().invokeInEveryVM(serializableRunnable());
}
}

@Override
protected void after() {
if (this.disconnectAfter) {
invoker().invokeEverywhere(serializableRunnable());
invoker().invokeInEveryVM(serializableRunnable());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public DistributedRestoreSystemProperties(final RemoteInvoker invoker) {
@Override
public void before() throws Throwable {
super.before();
this.invoker.remoteInvokeInEveryVMAndLocator(new SerializableRunnable() {
this.invoker.invokeInEveryVM(new SerializableRunnable() {
@Override
public void run() {
originalProperties = getProperties();
Expand All @@ -58,7 +58,7 @@ public void run() {
@Override
public void after() {
super.after();
this.invoker.remoteInvokeInEveryVMAndLocator(new SerializableRunnable() {
this.invoker.invokeInEveryVM(new SerializableRunnable() {
@Override
public void run() {
setProperties(originalProperties);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* 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.test.dunit.rules;

import org.apache.geode.test.junit.rules.UseJacksonForJsonPathRule;

public class DistributedUseJacksonForJsonPathRule extends UseJacksonForJsonPathRule {

private static UseJacksonForJsonPathRule instance = new UseJacksonForJsonPathRule();

private final RemoteInvoker invoker;

public DistributedUseJacksonForJsonPathRule() {
this(new RemoteInvoker());
}

public DistributedUseJacksonForJsonPathRule(final RemoteInvoker invoker) {
this.invoker = invoker;
}

@Override
public void before() {
this.invoker.invokeInEveryVM(DistributedUseJacksonForJsonPathRule::invokeBefore);
}

@Override
public void after() {
this.invoker.invokeInEveryVM(DistributedUseJacksonForJsonPathRule::invokeAfter);
}

private static void invokeBefore() {
instance.before();
}

private static void invokeAfter() {
instance.after();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

import java.io.Serializable;

import org.apache.geode.test.dunit.SerializableRunnable;
import org.apache.geode.test.dunit.Invoke;
import org.apache.geode.test.dunit.SerializableRunnableIF;

/**
* Provides remote invocation support to a {@code TestRule}. These methods will invoke a
Expand All @@ -28,18 +29,27 @@ class RemoteInvoker implements Serializable {

private static final long serialVersionUID = -1759722991299584649L;

public void invokeEverywhere(final SerializableRunnable runnable) {
// controller VM
// dunit VMs
// locator VM

/**
* Invokes in these VMs: controller VM and dunit VMs but not the dunit locator VM
*/
public void invokeInEveryVM(final SerializableRunnableIF runnable) {
try {
runnable.run();
} catch (Exception e) {
throw new RuntimeException(e);
}
invokeInEveryVM(runnable);
invokeInLocator(runnable);
Invoke.invokeInEveryVM(runnable);
}

public void remoteInvokeInEveryVMAndLocator(final SerializableRunnable runnable) {
invokeInEveryVM(runnable);
/**
* Invokes in all VMs: controller VM, dunit VMs, and the dunit locator VM
*/
public void invokeInEveryVMAndLocator(final SerializableRunnableIF runnable) {
Invoke.invokeInEveryVM(runnable);
invokeInLocator(runnable);
}
}
Loading

0 comments on commit e3eb927

Please sign in to comment.