You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tez.apache.org by ab...@apache.org on 2022/02/15 09:42:42 UTC

[tez] branch branch-0.9 updated: TEZ-4384: Remove unused EnvironmentUpdateUtils remaining from TEZ-1837 (#186) (Laszlo Attila Toth reviewed by Laszlo Bodor)

This is an automated email from the ASF dual-hosted git repository.

abstractdog pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/tez.git


The following commit(s) were added to refs/heads/branch-0.9 by this push:
     new b68ec25  TEZ-4384: Remove unused EnvironmentUpdateUtils remaining from TEZ-1837 (#186) (Laszlo Attila Toth reviewed by Laszlo Bodor)
b68ec25 is described below

commit b68ec252164c3355920b4c2fb85e4f22c9457a18
Author: László Attila Tóth <LA...@users.noreply.github.com>
AuthorDate: Tue Feb 15 10:42:03 2022 +0100

    TEZ-4384: Remove unused EnvironmentUpdateUtils remaining from TEZ-1837 (#186) (Laszlo Attila Toth reviewed by Laszlo Bodor)
---
 .../apache/tez/common/EnvironmentUpdateUtils.java  | 127 ---------------------
 .../tez/common/TestEnvironmentUpdateUtils.java     |  96 ----------------
 2 files changed, 223 deletions(-)

diff --git a/tez-common/src/main/java/org/apache/tez/common/EnvironmentUpdateUtils.java b/tez-common/src/main/java/org/apache/tez/common/EnvironmentUpdateUtils.java
deleted file mode 100644
index 0e597b3..0000000
--- a/tez-common/src/main/java/org/apache/tez/common/EnvironmentUpdateUtils.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/**
- * 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.tez.common;
-
-import org.apache.hadoop.classification.InterfaceAudience;
-import org.apache.hadoop.util.Shell;
-
-import java.lang.reflect.Field;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * A utility class which allows one to dynamically update/change Environment variables
- */
-@InterfaceAudience.Private
-public class EnvironmentUpdateUtils {
-
-  /**
-   * Allows dynamic update to the environment variables. After calling put,
-   * System.getenv(key) will then return value.
-   *
-   * @param key System environment variable
-   * @param value Value to assign to system environment variable
-   */
-  public synchronized static void put(String key, String value){
-    Map<String, String> environment = new HashMap<String, String>(System.getenv());
-    environment.put(key, value);
-    if (!Shell.WINDOWS) {
-      updateEnvironment(environment);
-    } else {
-      updateEnvironmentOnWindows(environment);
-    }
-  }
-
-  /**
-   * Allows dynamic update to a collection of environment variables. After
-   * calling putAll, System.getenv(key) will then return value for each entry
-   * in the map
-   *
-   * @param additionalEnvironment Collection where the key is the System
-   * environment variable and the value is the value to assign the system
-   * environment variable
-   */
-  public synchronized static void putAll(Map<String, String> additionalEnvironment) {
-    Map<String, String> environment = new HashMap<String, String>(System.getenv());
-    environment.putAll(additionalEnvironment);
-    if (!Shell.WINDOWS) {
-      updateEnvironment(environment);
-    } else {
-      updateEnvironmentOnWindows(environment);
-    }
-  }
-
-  /**
-   * Finds and modifies internal storage for system environment variables using
-   * reflection
-   *
-   * @param environment Collection where the key is the System
-   * environment variable and the value is the value to assign the system
-   * environment variable
-   */
-  @SuppressWarnings("unchecked")
-  private static void updateEnvironment(Map<String, String> environment) {
-    final Map<String, String> currentEnv = System.getenv();
-    copyMapValuesToPrivateField(currentEnv.getClass(), currentEnv, "m", environment);
-  }
-
-  /**
-   * Finds and modifies internal storage for system environment variables using reflection. This
-   * method works only on windows. Note that the actual env is not modified, rather the copy of env
-   * which the JVM creates at the beginning of execution is.
-   *
-   * @param environment Collection where the key is the System
-   * environment variable and the value is the value to assign the system
-   * environment variable
-   */
-  @SuppressWarnings("unchecked")
-  private static void updateEnvironmentOnWindows(Map<String, String> environment) {
-    try {
-      Class<?> processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
-      copyMapValuesToPrivateField(processEnvironmentClass, null, "theEnvironment", environment);
-      copyMapValuesToPrivateField(processEnvironmentClass, null, "theCaseInsensitiveEnvironment",
-          environment);
-    } catch (ClassNotFoundException e) {
-      throw new IllegalStateException("Failed to update Environment variables", e);
-    }
-  }
-
-  /**
-   * Copies the given map values to the field specified by {@code fieldName}
-   * @param klass The {@code Class} of the object
-   * @param object The object to modify or null if the field is static
-   * @param fieldName The name of the field to set
-   * @param newMapValues The values to replace the current map.
-   */
-  @SuppressWarnings("unchecked")
-  private static void copyMapValuesToPrivateField(Class<?> klass, Object object, String fieldName,
-                                                  Map<String, String> newMapValues) {
-    try {
-      Field field = klass.getDeclaredField(fieldName);
-      field.setAccessible(true);
-      Map<String, String> currentMap = (Map<String, String>) field.get(object);
-      currentMap.clear();
-      currentMap.putAll(newMapValues);
-    } catch (NoSuchFieldException e) {
-      throw new IllegalStateException("Failed to update Environment variables", e);
-    } catch (IllegalAccessException e) {
-      throw new IllegalStateException("Failed to update Environment variables", e);
-    }
-  }
-}
diff --git a/tez-common/src/test/java/org/apache/tez/common/TestEnvironmentUpdateUtils.java b/tez-common/src/test/java/org/apache/tez/common/TestEnvironmentUpdateUtils.java
deleted file mode 100644
index a9cecc2..0000000
--- a/tez-common/src/test/java/org/apache/tez/common/TestEnvironmentUpdateUtils.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- * 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.tez.common;
-
-import static org.junit.Assert.assertEquals;
-
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.common.util.concurrent.MoreExecutors;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-public class TestEnvironmentUpdateUtils {
-
-  @Test(timeout = 5000)
-  public void testMultipleUpdateEnvironment() {
-    EnvironmentUpdateUtils.put("test.environment1", "test.value1");
-    EnvironmentUpdateUtils.put("test.environment2", "test.value2");
-    assertEquals("Environment was not set propertly", "test.value1", System.getenv("test.environment1"));
-    assertEquals("Environment was not set propertly", "test.value2", System.getenv("test.environment2"));
-  }
-
-  @Test(timeout = 5000)
-  public void testConcurrentRequests() throws InterruptedException {
-    int timeoutSecond = 5;
-    int concurThread = 10;
-    int exceptionCount = 0;
-    List<Callable<Object>> tasks = new ArrayList<Callable<Object>>();
-    List<ListenableFuture<Object>> pendingTasks = new ArrayList<ListenableFuture<Object>>();
-    final ExecutorService callbackExecutor = Executors.newFixedThreadPool(concurThread,
-        new ThreadFactoryBuilder().setDaemon(false).setNameFormat("CallbackExecutor").build());
-    ListeningExecutorService taskExecutorService =
-        MoreExecutors.listeningDecorator(callbackExecutor);
-    while(concurThread > 0){
-      ListenableFuture<Object> runningTaskFuture =
-          taskExecutorService.submit(new EnvironmentRequest());
-      pendingTasks.add(runningTaskFuture);
-      concurThread--;
-    }
-
-    //waiting for all threads submitted to thread pool
-    for (ListenableFuture<Object> future : pendingTasks) {
-     try {
-        future.get();
-      } catch (ExecutionException e) {
-        exceptionCount++;
-      }
-    }
-
-    //stop accepting new threads and shutdown threadpool
-    taskExecutorService.shutdown();
-    try {
-      if(!taskExecutorService.awaitTermination(timeoutSecond, TimeUnit.SECONDS)) {
-        taskExecutorService.shutdownNow();
-      }
-    } catch (InterruptedException ie) {
-      taskExecutorService.shutdownNow();
-    }
-
-    assertEquals(0, exceptionCount);
-  }
-
-  private class EnvironmentRequest implements Callable<Object> {
-
-    @Override
-    public Object call() throws Exception {
-      EnvironmentUpdateUtils.put("test.environment.concurrent"
-          +Thread.currentThread().getId(), "test.evironment.concurrent");
-      return null;
-    }
-  }
- }