hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cdoug...@apache.org
Subject [1/2] hadoop git commit: YARN-4976. Missing NullPointer check in ContainerLaunchContextPBImpl. Contributed by Giovanni Matteo Fumarola
Date Thu, 21 Apr 2016 17:49:51 GMT
Repository: hadoop
Updated Branches:
  refs/heads/branch-2 432531dcf -> 878924189
  refs/heads/trunk b4be288c5 -> 95a504660


YARN-4976. Missing NullPointer check in ContainerLaunchContextPBImpl. Contributed by Giovanni
Matteo Fumarola


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/95a50466
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/95a50466
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/95a50466

Branch: refs/heads/trunk
Commit: 95a50466075c28110fa7c297e9c5246892076ca8
Parents: b4be288
Author: Chris Douglas <cdouglas@apache.org>
Authored: Thu Apr 21 10:45:38 2016 -0700
Committer: Chris Douglas <cdouglas@apache.org>
Committed: Thu Apr 21 10:45:38 2016 -0700

----------------------------------------------------------------------
 .../impl/pb/ContainerLaunchContextPBImpl.java   | 14 ++--
 .../TestApplicationClientProtocolRecords.java   | 69 ++++++++++++++++++++
 2 files changed, 79 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/95a50466/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerLaunchContextPBImpl.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerLaunchContextPBImpl.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerLaunchContextPBImpl.java
index 12dcfcd..30403ca 100644
--- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerLaunchContextPBImpl.java
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/main/java/org/apache/hadoop/yarn/api/records/impl/pb/ContainerLaunchContextPBImpl.java
@@ -369,14 +369,20 @@ extends ContainerLaunchContext {
           public void remove() {
             throw new UnsupportedOperationException();
           }
-          
+
           @Override
           public StringStringMapProto next() {
             String key = keyIter.next();
-            return StringStringMapProto.newBuilder().setKey(key).setValue(
-                (environment.get(key))).build();
+            String value = environment.get(key);
+
+            if (value == null) {
+              value = "";
+            }
+
+            return StringStringMapProto.newBuilder().setKey(key)
+                .setValue((value)).build();
           }
-          
+
           @Override
           public boolean hasNext() {
             return keyIter.hasNext();

http://git-wip-us.apache.org/repos/asf/hadoop/blob/95a50466/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/impl/pb/TestApplicationClientProtocolRecords.java
----------------------------------------------------------------------
diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/impl/pb/TestApplicationClientProtocolRecords.java
b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/impl/pb/TestApplicationClientProtocolRecords.java
new file mode 100644
index 0000000..0294ad1
--- /dev/null
+++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-common/src/test/java/org/apache/hadoop/yarn/api/records/impl/pb/TestApplicationClientProtocolRecords.java
@@ -0,0 +1,69 @@
+/**
+* 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.hadoop.yarn.api.records.impl.pb;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hadoop.io.DataOutputBuffer;
+import org.apache.hadoop.security.Credentials;
+import org.apache.hadoop.yarn.api.records.ApplicationAccessType;
+import org.apache.hadoop.yarn.api.records.ContainerLaunchContext;
+import org.apache.hadoop.yarn.api.records.LocalResource;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class TestApplicationClientProtocolRecords {
+
+  /*
+   * This test validates the scenario in which the client sets a null value for a
+   * particular environment.
+   *
+   */
+  @Test
+  public void testCLCPBImplNullEnv() throws IOException {
+    Map<String, LocalResource> localResources = Collections.emptyMap();
+    Map<String, String> environment = new HashMap<String, String>();
+    List<String> commands = Collections.emptyList();
+    Map<String, ByteBuffer> serviceData = Collections.emptyMap();
+    Credentials containerCreds = new Credentials();
+    DataOutputBuffer dob = new DataOutputBuffer();
+    containerCreds.writeTokenStorageToStream(dob);
+    ByteBuffer containerTokens =
+        ByteBuffer.wrap(dob.getData(), 0, dob.getLength());
+    Map<ApplicationAccessType, String> acls = Collections.emptyMap();
+
+    environment.put("testCLCPBImplNullEnv", null);
+
+    ContainerLaunchContext clc =
+        ContainerLaunchContext.newInstance(localResources, environment,
+            commands, serviceData, containerTokens, acls);
+
+    ContainerLaunchContext clcProto = new ContainerLaunchContextPBImpl(
+        ((ContainerLaunchContextPBImpl) clc).getProto());
+
+    Assert.assertEquals("",
+        clcProto.getEnvironment().get("testCLCPBImplNullEnv"));
+
+  }
+}


Mime
View raw message