You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@storm.apache.org by GitBox <gi...@apache.org> on 2020/04/13 21:30:30 UTC

[GitHub] [storm] govind-menon commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory

govind-menon commented on a change in pull request #3244: [STORM-3600] Add caching in Cluster.calculateSharedOffHeapNodeMemory
URL: https://github.com/apache/storm/pull/3244#discussion_r407732285
 
 

 ##########
 File path: storm-server/src/test/java/org/apache/storm/scheduler/resource/strategies/scheduling/TestLargeCluster.java
 ##########
 @@ -0,0 +1,458 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.storm.scheduler.resource.strategies.scheduling;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.core.config.Configurator;
+import org.apache.storm.Config;
+import org.apache.storm.DaemonConfig;
+import org.apache.storm.generated.StormTopology;
+import org.apache.storm.metric.StormMetricsRegistry;
+import org.apache.storm.scheduler.Cluster;
+import org.apache.storm.scheduler.ExecutorDetails;
+import org.apache.storm.scheduler.INimbus;
+import org.apache.storm.scheduler.IScheduler;
+import org.apache.storm.scheduler.SupervisorDetails;
+import org.apache.storm.scheduler.Topologies;
+import org.apache.storm.scheduler.TopologyDetails;
+import org.apache.storm.scheduler.WorkerSlot;
+import org.apache.storm.scheduler.resource.ResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResources;
+import org.apache.storm.scheduler.resource.normalization.NormalizedResourcesExtension;
+import org.apache.storm.scheduler.resource.normalization.ResourceMetrics;
+import org.apache.storm.utils.ObjectReader;
+import org.apache.storm.utils.Time;
+import org.apache.storm.utils.Utils;
+import org.junit.Assert;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+@ExtendWith({NormalizedResourcesExtension.class})
+public class TestLargeCluster {
+    private static final Logger LOG = LoggerFactory.getLogger(TestLargeCluster.class);
+
+    public static final String TEST_CLUSTER_NAME = "largeCluster01";
+    public static final String TEST_RESOURCE_PATH = "clusterconf/" + TEST_CLUSTER_NAME;
+
+    private static IScheduler scheduler = null;
+
+    @AfterEach
+    public void cleanup() {
+        if (scheduler != null) {
+            scheduler.cleanup();
+            scheduler = null;
+        }
+    }
+
+    /**
+     * Get the list of serialized topology (*code.ser) and configuration (*conf.ser)
+     * resource files in the path. The resources are sorted so that paired topology and conf
+     * files are sequential. Unpaired files may be ignored by the caller.
+     *
+     * @param path directory in which resources exist.
+     * @return
+     * @throws IOException
+     */
+    public static List<String> getResourceFiles(String path) throws IOException {
+        List<String> fileNames = new ArrayList<>();
+
+        try (
+                InputStream in = getResourceAsStream(path);
+                BufferedReader br = new BufferedReader(new InputStreamReader(in))
+        ) {
+            String resource;
+
+            while ((resource = br.readLine()) != null) {
+                if (resource.endsWith("code.ser") || resource.endsWith("conf.ser")) {
+                    fileNames.add(path + "/" + resource);
+                }
+            }
+            Collections.sort(fileNames);
+        }
+        return fileNames;
+    }
+
+    /**
+     * InputStream to read the fully qualified resource path.
+     *
+     * @param resource
+     * @return
+     */
+    public static InputStream getResourceAsStream(String resource) {
+        final InputStream in = getContextClassLoader().getResourceAsStream(resource);
+        return in == null ? ClassLoader.getSystemClassLoader().getResourceAsStream(resource) : in;
+    }
+
+    /**
+     * Read the contents of the fully qualified resource path.
+     *
+     * @param resource
+     * @return
+     * @throws Exception
+     */
+    public static byte[] getResourceAsBytes(String resource) throws Exception {
+        InputStream in = getResourceAsStream(resource);
+        if (in == null) {
+            return null;
+        }
+        try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
+            while (in.available() > 0) {
+                out.write(in.read());
+            }
+            return out.toByteArray();
 
 Review comment:
   Agreed - try with resources will close as part of the "destructor"

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services