Skip to content

Commit

Permalink
Revert "GEODE-8136: Move UncheckedUtils to geode-common (#5123)"
Browse files Browse the repository at this point in the history
This reverts commit 10af7ea.
  • Loading branch information
Bill committed Nov 5, 2020
1 parent 4886d20 commit 986334e
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 174 deletions.

This file was deleted.

Expand Up @@ -22,6 +22,7 @@
import static org.apache.geode.cache.RegionShortcut.PARTITION_PERSISTENT;
import static org.apache.geode.distributed.ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION;
import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
import static org.apache.geode.internal.cache.util.UncheckedUtils.cast;
import static org.apache.geode.internal.lang.SystemPropertyHelper.GEMFIRE_PREFIX;
import static org.apache.geode.management.ManagementService.getExistingManagementService;
import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
Expand All @@ -31,7 +32,6 @@
import static org.apache.geode.test.dunit.VM.getVM;
import static org.apache.geode.test.dunit.VM.getVMId;
import static org.apache.geode.test.dunit.rules.DistributedRule.getDistributedSystemProperties;
import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;

Expand Down Expand Up @@ -76,14 +76,14 @@
import org.apache.geode.cache.client.internal.InternalClientCache;
import org.apache.geode.cache.execute.FunctionAdapter;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.FunctionService;
import org.apache.geode.cache.execute.RegionFunctionContext;
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.distributed.LocatorLauncher;
import org.apache.geode.distributed.ServerLauncher;
import org.apache.geode.distributed.internal.ServerLocation;
import org.apache.geode.internal.cache.BucketAdvisor.ServerBucketProfile;
import org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException;
import org.apache.geode.internal.cache.execute.util.TypedFunctionService;
import org.apache.geode.management.ManagementService;
import org.apache.geode.management.membership.MembershipEvent;
import org.apache.geode.management.membership.UniversalMembershipListenerAdapter;
Expand Down Expand Up @@ -1336,22 +1336,22 @@ private void doGets() {
}

private void executeFunctions(Region<Object, Object> region) {
TypedFunctionService.onRegion(region)
cast(FunctionService.onRegion(region))
.withFilter(filter(0))
.execute(new PutFunction())
.getResult();

TypedFunctionService.onRegion(region)
cast(FunctionService.onRegion(region))
.withFilter(filter(0, 1))
.execute(new PutFunction())
.getResult();

TypedFunctionService.onRegion(region)
cast(FunctionService.onRegion(region))
.withFilter(filter(0, 1, 2, 3))
.execute(new PutFunction())
.getResult();

TypedFunctionService.onRegion(region)
cast(FunctionService.onRegion(region))
.execute(new PutFunction())
.getResult();
}
Expand Down Expand Up @@ -1389,7 +1389,7 @@ private File[] getDiskDirs() throws IOException {
}

private InternalCache getInternalCache(ServerLauncher serverLauncher) {
return uncheckedCast(serverLauncher.getCache());
return cast(serverLauncher.getCache());
}

private void waitForLocalBucketsCreation() {
Expand Down
Expand Up @@ -22,13 +22,13 @@
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIENT_AUTHENTICATOR;
import static org.apache.geode.distributed.ConfigurationProperties.SECURITY_CLIENT_AUTH_INIT;
import static org.apache.geode.distributed.ConfigurationProperties.SERIALIZABLE_OBJECT_FILTER;
import static org.apache.geode.internal.cache.execute.DistributedRegionFunctionExecutionDUnitTest.UncheckedUtils.cast;
import static org.apache.geode.test.awaitility.GeodeAwaitility.getTimeout;
import static org.apache.geode.test.dunit.IgnoredException.addIgnoredException;
import static org.apache.geode.test.dunit.VM.getController;
import static org.apache.geode.test.dunit.VM.getVM;
import static org.apache.geode.test.dunit.VM.toArray;
import static org.apache.geode.util.internal.GeodeGlossary.GEMFIRE_PREFIX;
import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;

Expand Down Expand Up @@ -59,6 +59,7 @@
import org.apache.geode.cache.client.PoolFactory;
import org.apache.geode.cache.client.PoolManager;
import org.apache.geode.cache.client.internal.InternalClientCache;
import org.apache.geode.cache.execute.Execution;
import org.apache.geode.cache.execute.Function;
import org.apache.geode.cache.execute.FunctionContext;
import org.apache.geode.cache.execute.FunctionException;
Expand All @@ -69,7 +70,6 @@
import org.apache.geode.cache.server.CacheServer;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.execute.util.TypedFunctionService;
import org.apache.geode.security.templates.DummyAuthenticator;
import org.apache.geode.security.templates.UserPasswordAuthInit;
import org.apache.geode.test.dunit.AsyncInvocation;
Expand Down Expand Up @@ -257,7 +257,7 @@ public void testDistributedRegionFunctionExecutionOnDataPolicyReplicateNotTimedO
empty.invoke(() -> populateRegion(200));

AsyncInvocation executeFunctionInReplicate1 = replicate1.invokeAsync(() -> {
ResultCollector<String, List<String>> resultCollector = TypedFunctionService
ResultCollector<String, List<String>> resultCollector = FunctionServiceCast
.<Void, String, List<String>>onRegion(getRegion())
.withFilter(filter)
.execute(LongRunningFunction.class.getSimpleName(), getTimeout().toMillis(),
Expand Down Expand Up @@ -302,7 +302,7 @@ public void testDistributedRegionFunctionExecutionOnDataPolicyReplicateTimedOut(

replicate1.invoke(() -> {
Throwable thrown = catchThrowable(() -> {
TypedFunctionService
FunctionServiceCast
.<Void, String, List<String>>onRegion(getRegion())
.withFilter(filter)
.execute(LongRunningFunction.class.getSimpleName(), 1000, MILLISECONDS);
Expand Down Expand Up @@ -950,7 +950,7 @@ public void inlineFunctionIsUsedOnClientInsteadOfLookingUpFunctionById() {
}

client.invoke(() -> {
ResultCollector<Boolean, List<Boolean>> resultCollector = TypedFunctionService
ResultCollector<Boolean, List<Boolean>> resultCollector = FunctionServiceCast
.<Boolean, Boolean, List<Boolean>>onRegion(getRegion())
.setArguments(true)
.execute(inlineFunction("Success", true));
Expand Down Expand Up @@ -1158,13 +1158,13 @@ private void registerThrowsFunctionInvocationTargetExceptionFunction(boolean isH
}

private void executeNoResultFunction() {
TypedFunctionService
FunctionServiceCast
.onRegion(getRegion())
.execute(new NoResultFunction());
}

private List<Boolean> executeDistributedRegionFunction() {
return TypedFunctionService
return FunctionServiceCast
.<Boolean, Boolean, List<Boolean>>onRegion(getRegion())
.withFilter(filter)
.setArguments(false)
Expand All @@ -1173,7 +1173,7 @@ private List<Boolean> executeDistributedRegionFunction() {
}

private void executeThrowsRuntimeExceptionFunction() {
TypedFunctionService
FunctionServiceCast
.<Void, Void, Void>onRegion(getRegion())
.withFilter(filter)
.execute(new ThrowsRuntimeExceptionFunction());
Expand All @@ -1187,7 +1187,7 @@ private void executeResultWithExceptionFunction() {
filter.add("execKey-" + 100 + i);
}

ResultCollector<Object, List<Object>> resultCollector = TypedFunctionService
ResultCollector<Object, List<Object>> resultCollector = FunctionServiceCast
.<Boolean, Object, List<Object>>onRegion(getRegion())
.withFilter(filter)
.setArguments(true)
Expand All @@ -1200,7 +1200,7 @@ private void executeResultWithExceptionFunction() {
.as("First element of " + resultCollector.getResult())
.isInstanceOf(CustomRuntimeException.class);

resultCollector = TypedFunctionService
resultCollector = FunctionServiceCast
.<Set<String>, Object, List<Object>>onRegion(getRegion())
.withFilter(filter)
.setArguments(filter)
Expand All @@ -1220,7 +1220,7 @@ private void executeResultWithExceptionFunction() {

private void executeNoLastResultFunction() {
Throwable thrown = catchThrowable(() -> {
TypedFunctionService
FunctionServiceCast
.onRegion(getRegion())
.withFilter(filter)
.execute(new NoLastResultFunction())
Expand All @@ -1234,15 +1234,15 @@ private void executeNoLastResultFunction() {
private void executeUnregisteredFunction() {
FunctionService.unregisterFunction(new DistributedRegionFunction().getId());

TypedFunctionService
FunctionServiceCast
.<Void, Boolean, List<Boolean>>onRegion(getRegion())
.withFilter(filter)
.execute(new DistributedRegionFunction())
.getResult();
}

private void executeFunctionFunctionInvocationTargetException() {
ResultCollector<Integer, List<Integer>> resultCollector = TypedFunctionService
ResultCollector<Integer, List<Integer>> resultCollector = FunctionServiceCast
.<Boolean, Integer, List<Integer>>onRegion(getRegion())
.setArguments(true)
.execute(ThrowsFunctionInvocationTargetExceptionFunction.class.getSimpleName());
Expand All @@ -1253,7 +1253,7 @@ private void executeFunctionFunctionInvocationTargetException() {

private void executeFunctionFunctionInvocationTargetExceptionWithoutHA() {
Throwable thrown = catchThrowable(() -> {
TypedFunctionService
FunctionServiceCast
.<Boolean, Integer, List<Integer>>onRegion(getRegion())
.setArguments(true)
.execute(ThrowsFunctionInvocationTargetExceptionFunction.class.getSimpleName())
Expand All @@ -1268,7 +1268,7 @@ private void executeFunctionFunctionInvocationTargetExceptionWithoutHA() {
}

private void executeFunctionFunctionInvocationTargetException_ClientServer() {
ResultCollector<Integer, List<Integer>> resultCollector = TypedFunctionService
ResultCollector<Integer, List<Integer>> resultCollector = FunctionServiceCast
.<Boolean, Integer, List<Integer>>onRegion(getRegion())
.setArguments(true)
.execute(ThrowsFunctionInvocationTargetExceptionFunction.class.getSimpleName());
Expand All @@ -1279,7 +1279,7 @@ private void executeFunctionFunctionInvocationTargetException_ClientServer() {

private void executeFunctionFunctionInvocationTargetException_ClientServer_WithoutHA() {
Throwable thrown = catchThrowable(() -> {
TypedFunctionService
FunctionServiceCast
.<Boolean, Integer, List<Integer>>onRegion(getRegion())
.setArguments(true)
.execute(ThrowsFunctionInvocationTargetExceptionFunction.class.getSimpleName())
Expand All @@ -1294,7 +1294,7 @@ private void executeFunctionFunctionInvocationTargetException_ClientServer_Witho
}

private static <K, V> Region<K, V> getRegion() {
return uncheckedCast(REGION.get());
return cast(REGION.get());
}

private static void setRegion(Region<?, ?> region) {
Expand Down Expand Up @@ -1327,8 +1327,7 @@ private static class ResultWithExceptionFunction implements Function<Object> {
@Override
public void execute(FunctionContext<Object> context) {
if (context.getArguments() instanceof Set) {
Set<Integer> arguments =
uncheckedCast(context.getArguments());
Set<Integer> arguments = cast(context.getArguments());
for (int i = 0; i < arguments.size(); i++) {
context.getResultSender().sendResult(i);
}
Expand Down Expand Up @@ -1558,4 +1557,26 @@ public int compare(Object o1, Object o2) {
return -1;
}
}

@SuppressWarnings("unchecked")
static class FunctionServiceCast {

/**
* Provide unchecked cast of FunctionService.onRegion.
*/
static <IN, OUT, AGG> Execution<IN, OUT, AGG> onRegion(Region<?, ?> region) {
return FunctionService.onRegion(region);
}
}

@SuppressWarnings({"unchecked", "unused"})
static class UncheckedUtils {

/**
* Provide unchecked cast of specified Object.
*/
static <T> T cast(Object object) {
return (T) object;
}
}
}
Expand Up @@ -36,10 +36,10 @@
import static org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningWithColocationAndPersistenceDUnitTest.Quarter.Q2;
import static org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningWithColocationAndPersistenceDUnitTest.Quarter.Q3;
import static org.apache.geode.internal.cache.partitioned.fixed.FixedPartitioningWithColocationAndPersistenceDUnitTest.Quarter.Q4;
import static org.apache.geode.internal.cache.util.UncheckedUtils.cast;
import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
import static org.apache.geode.test.dunit.VM.getVM;
import static org.apache.geode.test.dunit.VM.getVMId;
import static org.apache.geode.util.internal.UncheckedUtils.uncheckedCast;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -1502,9 +1502,9 @@ private <K, V> Region<K, V> getLocalDataSet(Region<K, V> region) {
PartitionedRegionDataStore dataStore = partitionedRegion.getDataStore();

if (dataStore != null) {
return uncheckedCast(new LocalDataSet(partitionedRegion, dataStore.getAllLocalBucketIds()));
return cast(new LocalDataSet(partitionedRegion, dataStore.getAllLocalBucketIds()));
}
return uncheckedCast(new LocalDataSet(partitionedRegion, emptySet()));
return cast(new LocalDataSet(partitionedRegion, emptySet()));
}

private void validateQuartersData() throws ParseException {
Expand Down Expand Up @@ -1555,20 +1555,20 @@ private void validateColocatedData(int count) {
InternalDistributedMember idmForShipment = shipments.getBucketPrimary(i);

// take all the keys from the shipment for each bucket
Set<CustomerId> customerKey = uncheckedCast(customers.getBucketKeys(i));
Set<CustomerId> customerKey = cast(customers.getBucketKeys(i));
assertThat(customerKey).isNotNull();

for (CustomerId customerId : customerKey) {
assertThat(customers.get(customerId)).isNotNull();

Set<OrderId> orderKey = uncheckedCast(orders.getBucketKeys(i));
Set<OrderId> orderKey = cast(orders.getBucketKeys(i));
for (OrderId orderId : orderKey) {
assertThat(orders.get(orderId)).isNotNull();
if (orderId.getCustomerId().equals(customerId)) {
assertThat(idmForOrder).isEqualTo(idmForCustomer);
}

Set<ShipmentId> shipmentKey = uncheckedCast(shipments.getBucketKeys(i));
Set<ShipmentId> shipmentKey = cast(shipments.getBucketKeys(i));
for (ShipmentId shipmentId : shipmentKey) {
assertThat(shipments.get(shipmentId)).isNotNull();
if (shipmentId.getOrderId().equals(orderId)) {
Expand Down

0 comments on commit 986334e

Please sign in to comment.