http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/planner/TaskBundle.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/planner/TaskBundle.java b/storm-core/src/jvm/org/apache/storm/planner/TaskBundle.java index 2437c93..6052b6d 100644 --- a/storm-core/src/jvm/org/apache/storm/planner/TaskBundle.java +++ b/storm-core/src/jvm/org/apache/storm/planner/TaskBundle.java @@ -1,33 +1,28 @@ /** - * 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 + * 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. + * 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.planner; -import org.apache.storm.task.IBolt; import java.io.Serializable; +import org.apache.storm.task.IBolt; public class TaskBundle implements Serializable { public IBolt task; public int componentId; - + public TaskBundle(IBolt task, int componentId) { this.task = task; this.componentId = componentId; } - + }
http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/testing/MockLeaderElector.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/testing/MockLeaderElector.java b/storm-core/src/jvm/org/apache/storm/testing/MockLeaderElector.java index 4710f10..4b0404f 100644 --- a/storm-core/src/jvm/org/apache/storm/testing/MockLeaderElector.java +++ b/storm-core/src/jvm/org/apache/storm/testing/MockLeaderElector.java @@ -1,19 +1,13 @@ /** - * 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 + * 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. + * 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.testing; @@ -21,14 +15,13 @@ package org.apache.storm.testing; import java.util.Arrays; import java.util.List; import java.util.Map; - import org.apache.storm.nimbus.ILeaderElector; import org.apache.storm.nimbus.NimbusInfo; public class MockLeaderElector implements ILeaderElector { private final boolean isLeader; private final NimbusInfo leaderAddress; - + public MockLeaderElector() { this(true, "test-host", 9999); } @@ -36,7 +29,7 @@ public class MockLeaderElector implements ILeaderElector { public MockLeaderElector(boolean isLeader) { this(isLeader, "test-host", 9999); } - + public MockLeaderElector(boolean isLeader, String host, int port) { this.isLeader = isLeader; this.leaderAddress = new NimbusInfo(host, port, true); http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedClientZookeeper.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedClientZookeeper.java b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedClientZookeeper.java index b1f0b49..6c52134 100644 --- a/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedClientZookeeper.java +++ b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedClientZookeeper.java @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.storm.testing.staticmocking; import org.apache.storm.zookeeper.ClientZookeeper; http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedCluster.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedCluster.java b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedCluster.java index 2f1440c..34bfbc3 100644 --- a/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedCluster.java +++ b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedCluster.java @@ -1,24 +1,20 @@ /** - * 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 + * 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. + * 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.testing.staticmocking; import org.apache.storm.cluster.ClusterUtils; -public class MockedCluster implements AutoCloseable { +public class MockedCluster implements AutoCloseable { public MockedCluster(ClusterUtils inst) { ClusterUtils.setInstance(inst); http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedSupervisorUtils.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedSupervisorUtils.java b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedSupervisorUtils.java index d33dc9c..f806bf7 100644 --- a/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedSupervisorUtils.java +++ b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedSupervisorUtils.java @@ -1,19 +1,15 @@ /** - * 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 + * 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. + * 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.testing.staticmocking; import org.apache.storm.daemon.supervisor.SupervisorUtils; http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedZookeeper.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedZookeeper.java b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedZookeeper.java index ca54f6f..6207123 100644 --- a/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedZookeeper.java +++ b/storm-core/src/jvm/org/apache/storm/testing/staticmocking/MockedZookeeper.java @@ -1,19 +1,15 @@ /** - * 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 + * 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. + * 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.testing.staticmocking; import org.apache.storm.zookeeper.Zookeeper; http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/ui/FilterConfiguration.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/ui/FilterConfiguration.java b/storm-core/src/jvm/org/apache/storm/ui/FilterConfiguration.java index e671264..153826e 100644 --- a/storm-core/src/jvm/org/apache/storm/ui/FilterConfiguration.java +++ b/storm-core/src/jvm/org/apache/storm/ui/FilterConfiguration.java @@ -1,20 +1,15 @@ /** - * 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 + * 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. + * 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.ui; import java.util.Map; http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/ui/IConfigurator.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/ui/IConfigurator.java b/storm-core/src/jvm/org/apache/storm/ui/IConfigurator.java index 86e47d4..9424677 100644 --- a/storm-core/src/jvm/org/apache/storm/ui/IConfigurator.java +++ b/storm-core/src/jvm/org/apache/storm/ui/IConfigurator.java @@ -1,20 +1,15 @@ /** - * 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 + * 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. + * 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.ui; import org.eclipse.jetty.server.Server; http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/ui/InvalidRequestException.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/ui/InvalidRequestException.java b/storm-core/src/jvm/org/apache/storm/ui/InvalidRequestException.java index 1fb1d69..04f0596 100644 --- a/storm-core/src/jvm/org/apache/storm/ui/InvalidRequestException.java +++ b/storm-core/src/jvm/org/apache/storm/ui/InvalidRequestException.java @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.storm.ui; public class InvalidRequestException extends Exception { http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java b/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java index be4a4c0..af8999b 100644 --- a/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java +++ b/storm-core/src/jvm/org/apache/storm/ui/UIHelpers.java @@ -1,20 +1,15 @@ /** - * 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 + * 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. + * 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.ui; import com.google.common.base.Joiner; @@ -50,17 +45,19 @@ import org.json.simple.JSONValue; public class UIHelpers { private static final Object[][] PRETTY_SEC_DIVIDERS = { - new Object[]{"s", 60}, - new Object[]{"m", 60}, - new Object[]{"h", 24}, - new Object[]{"d", null}}; + new Object[]{ "s", 60 }, + new Object[]{ "m", 60 }, + new Object[]{ "h", 24 }, + new Object[]{ "d", null } + }; private static final Object[][] PRETTY_MS_DIVIDERS = { - new Object[]{"ms", 1000}, - new Object[]{"s", 60}, - new Object[]{"m", 60}, - new Object[]{"h", 24}, - new Object[]{"d", null}}; + new Object[]{ "ms", 1000 }, + new Object[]{ "s", 60 }, + new Object[]{ "m", 60 }, + new Object[]{ "h", 24 }, + new Object[]{ "d", null } + }; public static String prettyUptimeStr(String val, Object[][] dividers) { int uptime = Integer.parseInt(val); @@ -111,13 +108,13 @@ public class UIHelpers { public static Map<String, Object> unauthorizedUserJson(String user) { return ImmutableMap.of( - "error", "No Authorization", - "errorMessage", String.format("User %s is not authorized.", user)); + "error", "No Authorization", + "errorMessage", String.format("User %s is not authorized.", user)); } private static ServerConnector mkSslConnector(Server server, Integer port, String ksPath, String ksPassword, String ksType, - String keyPassword, String tsPath, String tsPassword, String tsType, - Boolean needClientAuth, Boolean wantClientAuth, Integer headerBufferSize) { + String keyPassword, String tsPath, String tsPassword, String tsType, + Boolean needClientAuth, Boolean wantClientAuth, Integer headerBufferSize) { SslContextFactory factory = new SslContextFactory(); factory.setExcludeCipherSuites("SSL_RSA_WITH_RC4_128_MD5", "SSL_RSA_WITH_RC4_128_SHA"); factory.setExcludeProtocols("SSLv3"); @@ -145,8 +142,8 @@ public class UIHelpers { httpsConfig.setRequestHeaderSize(headerBufferSize); } ServerConnector sslConnector = new ServerConnector(server, - new SslConnectionFactory(factory, HttpVersion.HTTP_1_1.asString()), - new HttpConnectionFactory(httpsConfig)); + new SslConnectionFactory(factory, HttpVersion.HTTP_1_1.asString()), + new HttpConnectionFactory(httpsConfig)); sslConnector.setPort(port); return sslConnector; } @@ -155,7 +152,7 @@ public class UIHelpers { String keyPassword, String tsPath, String tsPassword, String tsType, Boolean needClientAuth, Boolean wantClientAuth) { configSsl(server, port, ksPath, ksPassword, ksType, keyPassword, - tsPath, tsPassword, tsType, needClientAuth, wantClientAuth, null); + tsPath, tsPassword, tsType, needClientAuth, wantClientAuth, null); } public static void configSsl(Server server, Integer port, String ksPath, String ksPassword, String ksType, @@ -163,7 +160,7 @@ public class UIHelpers { Boolean needClientAuth, Boolean wantClientAuth, Integer headerBufferSize) { if (port > 0) { server.addConnector(mkSslConnector(server, port, ksPath, ksPassword, ksType, keyPassword, - tsPath, tsPassword, tsType, needClientAuth, wantClientAuth, headerBufferSize)); + tsPath, tsPassword, tsType, needClientAuth, wantClientAuth, headerBufferSize)); } } @@ -171,7 +168,9 @@ public class UIHelpers { FilterHolder filterHolder = new FilterHolder(new CrossOriginFilter()); filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "*"); filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "GET, POST, PUT"); - filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, "X-Requested-With, X-Requested-By, Access-Control-Allow-Origin, Content-Type, Content-Length, Accept, Origin"); + filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, + "X-Requested-With, X-Requested-By, Access-Control-Allow-Origin, Content-Type, Content-Length, " + + "Accept, Origin"); filterHolder.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*"); return filterHolder; } @@ -183,7 +182,7 @@ public class UIHelpers { public static void configFilter(Server server, Servlet servlet, List<FilterConfiguration> filtersConfs) { configFilter(server, servlet, filtersConfs, null); } - + public static void configFilter(Server server, Servlet servlet, List<FilterConfiguration> filtersConfs, Map<String, String> params) { if (filtersConfs != null) { ServletHolder servletHolder = new ServletHolder(servlet); @@ -197,7 +196,7 @@ public class UIHelpers { server.setHandler(context); } } - + public static void configFilters(ServletContextHandler context, List<FilterConfiguration> filtersConfs) { context.addFilter(corsFilterHandle(), "/*", EnumSet.allOf(DispatcherType.class)); for (FilterConfiguration filterConf : filtersConfs) { @@ -256,7 +255,8 @@ public class UIHelpers { * Modified version of run-jetty * Assumes configurator sets handler. */ - public static void stormRunJetty(Integer port, String host, Integer httpsPort, Integer headerBufferSize, IConfigurator configurator) throws Exception { + public static void stormRunJetty(Integer port, String host, Integer httpsPort, Integer headerBufferSize, + IConfigurator configurator) throws Exception { Server s = jettyCreateServer(port, host, httpsPort, headerBufferSize); if (configurator != null) { configurator.execute(s); @@ -276,7 +276,9 @@ public class UIHelpers { Map<String, String> headersResult = new HashMap<>(); headersResult.put("Cache-Control", "no-cache, no-store"); headersResult.put("Access-Control-Allow-Origin", "*"); - headersResult.put("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Access-Controler-Allow-Origin, X-Requested-By, X-Csrf-Token, Authorization, X-Requested-With"); + headersResult.put("Access-Control-Allow-Headers", + "Content-Type, Access-Control-Allow-Headers, Access-Controler-Allow-Origin, X-Requested-By, X-Csrf-Token, " + + "Authorization, X-Requested-With"); if (callback != null) { headersResult.put("Content-Type", "application/javascript;charset=utf-8"); } else { http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/utils/ClojureTimerTask.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/utils/ClojureTimerTask.java b/storm-core/src/jvm/org/apache/storm/utils/ClojureTimerTask.java index caefdb9..a220a23 100644 --- a/storm-core/src/jvm/org/apache/storm/utils/ClojureTimerTask.java +++ b/storm-core/src/jvm/org/apache/storm/utils/ClojureTimerTask.java @@ -1,20 +1,15 @@ /** - * 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 + * 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. + * 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.utils; import clojure.lang.IFn; @@ -22,14 +17,14 @@ import java.util.TimerTask; public class ClojureTimerTask extends TimerTask { IFn _afn; - + public ClojureTimerTask(IFn afn) { super(); _afn = afn; } - + @Override public void run() { _afn.run(); - } + } } http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/utils/Monitor.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/utils/Monitor.java b/storm-core/src/jvm/org/apache/storm/utils/Monitor.java index 15569d0..8e3ce27 100644 --- a/storm-core/src/jvm/org/apache/storm/utils/Monitor.java +++ b/storm-core/src/jvm/org/apache/storm/utils/Monitor.java @@ -1,26 +1,27 @@ /** - * 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 + * 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. + * 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.utils; -import org.apache.storm.generated.*; +package org.apache.storm.utils; import java.util.HashSet; import java.util.Map; +import org.apache.storm.generated.ClusterSummary; +import org.apache.storm.generated.ExecutorStats; +import org.apache.storm.generated.ExecutorSummary; +import org.apache.storm.generated.GetInfoOptions; +import org.apache.storm.generated.Nimbus; +import org.apache.storm.generated.NumErrorsChoice; +import org.apache.storm.generated.TopologyInfo; +import org.apache.storm.generated.TopologySummary; public class Monitor { private static final String WATCH_TRANSFERRED = "transferred"; @@ -32,75 +33,11 @@ public class Monitor { private String _stream; private String _watch; - private static class MetricsState { - private long lastTime = 0; - private long lastStatted = 0; - - private MetricsState(long lastTime, long lastStatted) { - this.lastTime = lastTime; - this.lastStatted = lastStatted; - } - - public long getLastStatted() { - return lastStatted; - } - - public void setLastStatted(long lastStatted) { - this.lastStatted = lastStatted; - } - - public long getLastTime() { - return lastTime; - } - - public void setLastTime(long lastTime) { - this.lastTime = lastTime; - } - } - - private static class Poller { - private long startTime = 0; - private long pollMs = 0; - - private Poller(long startTime, long pollMs) { - this.startTime = startTime; - this.pollMs = pollMs; - } - - public long nextPoll() throws InterruptedException { - long now = System.currentTimeMillis(); - long cycle = (now - startTime) / pollMs; - long wakeupTime = startTime + (pollMs * (cycle + 1)); - long sleepTime = wakeupTime - now; - if (sleepTime > 0) { - Thread.sleep(sleepTime); - } - now = System.currentTimeMillis(); - return now; - } - - public long getStartTime() { - return startTime; - } - - public void setStartTime(long startTime) { - this.startTime = startTime; - } - - public long getPollMs() { - return pollMs; - } - - public void setPollMs(long pollMs) { - this.pollMs = pollMs; - } - } - - private HashSet<String> getComponents(Nimbus.Iface client, String topology) throws Exception{ + private HashSet<String> getComponents(Nimbus.Iface client, String topology) throws Exception { HashSet<String> components = new HashSet<>(); ClusterSummary clusterSummary = client.getClusterInfo(); TopologySummary topologySummary = null; - for (TopologySummary ts: clusterSummary.get_topologies()) { + for (TopologySummary ts : clusterSummary.get_topologies()) { if (topology.equals(ts.get_name())) { topologySummary = ts; break; @@ -113,7 +50,7 @@ public class Monitor { GetInfoOptions getInfoOpts = new GetInfoOptions(); getInfoOpts.set_num_err_choice(NumErrorsChoice.NONE); TopologyInfo info = client.getTopologyInfoWithOpts(id, getInfoOpts); - for (ExecutorSummary es: info.get_executors()) { + for (ExecutorSummary es : info.get_executors()) { components.add(es.get_component_id()); } } @@ -145,7 +82,7 @@ public class Monitor { throw new IllegalArgumentException("stream name must be something"); } - if ( !WATCH_TRANSFERRED.equals(_watch) && !WATCH_EMITTED.equals(_watch)) { + if (!WATCH_TRANSFERRED.equals(_watch) && !WATCH_EMITTED.equals(_watch)) { throw new IllegalArgumentException("watch item must either be transferred or emitted"); } System.out.println("topology\tcomponent\tparallelism\tstream\ttime-diff ms\t" + _watch + "\tthroughput (Kt/s)"); @@ -173,7 +110,7 @@ public class Monitor { boolean streamFound = false; ClusterSummary clusterSummary = client.getClusterInfo(); TopologySummary topologySummary = null; - for (TopologySummary ts: clusterSummary.get_topologies()) { + for (TopologySummary ts : clusterSummary.get_topologies()) { if (_topology.equals(ts.get_name())) { topologySummary = ts; break; @@ -186,18 +123,18 @@ public class Monitor { GetInfoOptions getInfoOpts = new GetInfoOptions(); getInfoOpts.set_num_err_choice(NumErrorsChoice.NONE); TopologyInfo info = client.getTopologyInfoWithOpts(id, getInfoOpts); - for (ExecutorSummary es: info.get_executors()) { + for (ExecutorSummary es : info.get_executors()) { if (_component.equals(es.get_component_id())) { - componentParallelism ++; + componentParallelism++; ExecutorStats stats = es.get_stats(); if (stats != null) { - Map<String,Map<String,Long>> statted = - WATCH_EMITTED.equals(_watch) ? stats.get_emitted() : stats.get_transferred(); - if ( statted != null) { + Map<String, Map<String, Long>> statted = + WATCH_EMITTED.equals(_watch) ? stats.get_emitted() : stats.get_transferred(); + if (statted != null) { Map<String, Long> e2 = statted.get(":all-time"); if (e2 != null) { Long stream = e2.get(_stream); - if (stream != null){ + if (stream != null) { streamFound = true; totalStatted += stream; } @@ -226,8 +163,10 @@ public class Monitor { long stattedDelta = totalStatted - state.getLastStatted(); state.setLastTime(now); state.setLastStatted(totalStatted); - double throughput = (stattedDelta == 0 || timeDelta == 0) ? 0.0 : ((double)stattedDelta/(double)timeDelta); - System.out.println(_topology+"\t"+_component+"\t"+componentParallelism+"\t"+_stream+"\t"+timeDelta+"\t"+stattedDelta+"\t"+throughput); + double throughput = (stattedDelta == 0 || timeDelta == 0) ? 0.0 : ((double) stattedDelta / (double) timeDelta); + System.out.println( + _topology + "\t" + _component + "\t" + componentParallelism + "\t" + _stream + "\t" + timeDelta + "\t" + stattedDelta + "\t" + + throughput); } public void set_interval(int _interval) { @@ -249,4 +188,68 @@ public class Monitor { public void set_watch(String _watch) { this._watch = _watch; } + + private static class MetricsState { + private long lastTime = 0; + private long lastStatted = 0; + + private MetricsState(long lastTime, long lastStatted) { + this.lastTime = lastTime; + this.lastStatted = lastStatted; + } + + public long getLastStatted() { + return lastStatted; + } + + public void setLastStatted(long lastStatted) { + this.lastStatted = lastStatted; + } + + public long getLastTime() { + return lastTime; + } + + public void setLastTime(long lastTime) { + this.lastTime = lastTime; + } + } + + private static class Poller { + private long startTime = 0; + private long pollMs = 0; + + private Poller(long startTime, long pollMs) { + this.startTime = startTime; + this.pollMs = pollMs; + } + + public long nextPoll() throws InterruptedException { + long now = System.currentTimeMillis(); + long cycle = (now - startTime) / pollMs; + long wakeupTime = startTime + (pollMs * (cycle + 1)); + long sleepTime = wakeupTime - now; + if (sleepTime > 0) { + Thread.sleep(sleepTime); + } + now = System.currentTimeMillis(); + return now; + } + + public long getStartTime() { + return startTime; + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } + + public long getPollMs() { + return pollMs; + } + + public void setPollMs(long pollMs) { + this.pollMs = pollMs; + } + } } http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/src/jvm/org/apache/storm/utils/TopologySpoutLag.java ---------------------------------------------------------------------- diff --git a/storm-core/src/jvm/org/apache/storm/utils/TopologySpoutLag.java b/storm-core/src/jvm/org/apache/storm/utils/TopologySpoutLag.java index 0577261..db4c1d7 100644 --- a/storm-core/src/jvm/org/apache/storm/utils/TopologySpoutLag.java +++ b/storm-core/src/jvm/org/apache/storm/utils/TopologySpoutLag.java @@ -1,23 +1,23 @@ /** - * 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 + * 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. + * 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.utils; +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.storm.Config; import org.apache.storm.generated.ComponentCommon; import org.apache.storm.generated.ComponentObject; @@ -28,27 +28,20 @@ import org.json.simple.parser.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class TopologySpoutLag { // FIXME: This class can be moved to webapp once UI porting is done. private static final String SPOUT_ID = "spoutId"; - private static final String SPOUT_TYPE= "spoutType"; + private static final String SPOUT_TYPE = "spoutType"; private static final String SPOUT_LAG_RESULT = "spoutLagResult"; private static final String ERROR_INFO = "errorInfo"; private final static Logger logger = LoggerFactory.getLogger(TopologySpoutLag.class); - public static Map<String, Map<String, Object>> lag (StormTopology stormTopology, Map<String, Object> topologyConf) { + public static Map<String, Map<String, Object>> lag(StormTopology stormTopology, Map<String, Object> topologyConf) { Map<String, Map<String, Object>> result = new HashMap<>(); Map<String, SpoutSpec> spouts = stormTopology.get_spouts(); String className = null; - for (Map.Entry<String, SpoutSpec> spout: spouts.entrySet()) { + for (Map.Entry<String, SpoutSpec> spout : spouts.entrySet()) { try { SpoutSpec spoutSpec = spout.getValue(); ComponentObject componentObject = spoutSpec.get_spout_object(); @@ -82,18 +75,18 @@ public class TopologySpoutLag { } } - private static List<String> getCommandLineOptionsForNewKafkaSpout (Map<String, Object> jsonConf) { + private static List<String> getCommandLineOptionsForNewKafkaSpout(Map<String, Object> jsonConf) { logger.debug("json configuration: {}", jsonConf); List<String> commands = new ArrayList<>(); String configKeyPrefix = "config."; commands.add("-t"); - commands.add((String)jsonConf.get(configKeyPrefix + "topics")); + commands.add((String) jsonConf.get(configKeyPrefix + "topics")); commands.add("-g"); - commands.add((String)jsonConf.get(configKeyPrefix + "groupid")); + commands.add((String) jsonConf.get(configKeyPrefix + "groupid")); commands.add("-b"); - commands.add((String)jsonConf.get(configKeyPrefix + "bootstrap.servers")); - String securityProtocol = (String)jsonConf.get(configKeyPrefix + "security.protocol"); + commands.add((String) jsonConf.get(configKeyPrefix + "bootstrap.servers")); + String securityProtocol = (String) jsonConf.get(configKeyPrefix + "security.protocol"); if (securityProtocol != null && !securityProtocol.isEmpty()) { commands.add("-s"); commands.add(securityProtocol); @@ -101,21 +94,21 @@ public class TopologySpoutLag { return commands; } - private static List<String> getCommandLineOptionsForOldKafkaSpout (Map<String, Object> jsonConf, Map<String, Object> topologyConf) { + private static List<String> getCommandLineOptionsForOldKafkaSpout(Map<String, Object> jsonConf, Map<String, Object> topologyConf) { logger.debug("json configuration: {}", jsonConf); List<String> commands = new ArrayList<>(); String configKeyPrefix = "config."; commands.add("-o"); commands.add("-t"); - commands.add((String)jsonConf.get(configKeyPrefix + "topics")); + commands.add((String) jsonConf.get(configKeyPrefix + "topics")); commands.add("-n"); - commands.add((String)jsonConf.get(configKeyPrefix + "zkRoot")); - String zkServers = (String)jsonConf.get(configKeyPrefix + "zkServers"); + commands.add((String) jsonConf.get(configKeyPrefix + "zkRoot")); + String zkServers = (String) jsonConf.get(configKeyPrefix + "zkServers"); if (zkServers == null || zkServers.isEmpty()) { StringBuilder zkServersBuilder = new StringBuilder(); Integer zkPort = ((Number) topologyConf.get(Config.STORM_ZOOKEEPER_PORT)).intValue(); - for (String zkServer: (List<String>) topologyConf.get(Config.STORM_ZOOKEEPER_SERVERS)) { + for (String zkServer : (List<String>) topologyConf.get(Config.STORM_ZOOKEEPER_SERVERS)) { zkServersBuilder.append(zkServer + ":" + zkPort + ","); } zkServers = zkServersBuilder.toString(); @@ -124,12 +117,12 @@ public class TopologySpoutLag { commands.add(zkServers); if (jsonConf.get(configKeyPrefix + "leaders") != null) { commands.add("-p"); - commands.add((String)jsonConf.get(configKeyPrefix + "partitions")); + commands.add((String) jsonConf.get(configKeyPrefix + "partitions")); commands.add("-l"); - commands.add((String)jsonConf.get(configKeyPrefix + "leaders")); + commands.add((String) jsonConf.get(configKeyPrefix + "leaders")); } else { commands.add("-r"); - commands.add((String)jsonConf.get(configKeyPrefix + "zkNodeBrokers")); + commands.add((String) jsonConf.get(configKeyPrefix + "zkNodeBrokers")); Boolean isWildCard = (Boolean) topologyConf.get("kafka.topic.wildcard.match"); if (isWildCard != null && isWildCard.booleanValue()) { commands.add("-w"); @@ -138,7 +131,8 @@ public class TopologySpoutLag { return commands; } - private static Map<String, Object> getLagResultForKafka (String spoutId, SpoutSpec spoutSpec, Map<String, Object> topologyConf, boolean old) throws IOException { + private static Map<String, Object> getLagResultForKafka(String spoutId, SpoutSpec spoutSpec, Map<String, Object> topologyConf, + boolean old) throws IOException { ComponentCommon componentCommon = spoutSpec.get_common(); String json = componentCommon.get_json_conf(); Map<String, Object> result = null; @@ -156,7 +150,8 @@ public class TopologySpoutLag { } catch (ParseException e) { throw new IOException(e); } - commands.addAll(old ? getCommandLineOptionsForOldKafkaSpout(jsonMap, topologyConf) : getCommandLineOptionsForNewKafkaSpout(jsonMap)); + commands.addAll( + old ? getCommandLineOptionsForOldKafkaSpout(jsonMap, topologyConf) : getCommandLineOptionsForNewKafkaSpout(jsonMap)); logger.debug("Command to run: {}", commands); @@ -187,11 +182,13 @@ public class TopologySpoutLag { return kafkaSpoutLagInfo; } - private static Map<String, Object> getLagResultForNewKafkaSpout (String spoutId, SpoutSpec spoutSpec, Map<String, Object> topologyConf) throws IOException { + private static Map<String, Object> getLagResultForNewKafkaSpout(String spoutId, SpoutSpec spoutSpec, + Map<String, Object> topologyConf) throws IOException { return getLagResultForKafka(spoutId, spoutSpec, topologyConf, false); } - private static Map<String, Object> getLagResultForOldKafkaSpout (String spoutId, SpoutSpec spoutSpec, Map<String, Object> topologyConf) throws IOException { + private static Map<String, Object> getLagResultForOldKafkaSpout(String spoutId, SpoutSpec spoutSpec, + Map<String, Object> topologyConf) throws IOException { return getLagResultForKafka(spoutId, spoutSpec, topologyConf, true); } } http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/MockAutoCred.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/MockAutoCred.java b/storm-core/test/jvm/org/apache/storm/MockAutoCred.java index 1a746ca..5eede63 100644 --- a/storm-core/test/jvm/org/apache/storm/MockAutoCred.java +++ b/storm-core/test/jvm/org/apache/storm/MockAutoCred.java @@ -1,30 +1,23 @@ /** - * 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 + * 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. + * 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; +import java.util.Map; +import javax.security.auth.Subject; import org.apache.storm.security.INimbusCredentialPlugin; import org.apache.storm.security.auth.IAutoCredentials; import org.apache.storm.security.auth.ICredentialsRenewer; -import java.util.Map; - -import javax.security.auth.Subject; - /** * mock implementation of INimbusCredentialPlugin,IAutoCredentials and ICredentialsRenewer for testing only. */ http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/command/RebalanceTest.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/command/RebalanceTest.java b/storm-core/test/jvm/org/apache/storm/command/RebalanceTest.java index cec4958..e85beb5 100644 --- a/storm-core/test/jvm/org/apache/storm/command/RebalanceTest.java +++ b/storm-core/test/jvm/org/apache/storm/command/RebalanceTest.java @@ -1,29 +1,22 @@ /** - * 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 + * 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. + * 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.command; +import java.util.Map; import org.junit.Assert; import org.junit.Test; -import java.util.Map; - public class RebalanceTest { @Test http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/command/SetLogLevelTest.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/command/SetLogLevelTest.java b/storm-core/test/jvm/org/apache/storm/command/SetLogLevelTest.java index 4582371..5951752 100644 --- a/storm-core/test/jvm/org/apache/storm/command/SetLogLevelTest.java +++ b/storm-core/test/jvm/org/apache/storm/command/SetLogLevelTest.java @@ -1,30 +1,23 @@ /** - * 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 + * 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. + * 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.command; +import java.util.Map; import org.apache.storm.generated.LogLevel; import org.apache.storm.generated.LogLevelAction; import org.junit.Assert; import org.junit.Test; -import java.util.Map; - public class SetLogLevelTest { @Test http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/command/TestCLI.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/command/TestCLI.java b/storm-core/test/jvm/org/apache/storm/command/TestCLI.java index d1caa3c..fd06cbe 100644 --- a/storm-core/test/jvm/org/apache/storm/command/TestCLI.java +++ b/storm-core/test/jvm/org/apache/storm/command/TestCLI.java @@ -1,28 +1,21 @@ /** - * 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 + * 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. + * 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.command; -import org.junit.Test; - import java.util.HashMap; import java.util.List; import java.util.Map; +import org.junit.Test; import static org.junit.Assert.assertEquals; @@ -31,22 +24,23 @@ public class TestCLI { @Test public void testSimple() throws Exception { Map<String, Object> values = CLI.opt("a", "aa", null) - .opt("b", "bb", 1, CLI.AS_INT) - .opt("c", "cc", 1, CLI.AS_INT, CLI.FIRST_WINS) - .opt("d", "dd", null, CLI.AS_STRING, CLI.INTO_LIST) - .opt("e", "ee", null, CLI.AS_INT) - .opt("f", "ff", null, new PairParse(), CLI.INTO_MAP) - .arg("A") - .arg("B", CLI.AS_INT) - .parse("-a100", "--aa", "200", "-c2", "-b", "50", "--cc", "100", "A-VALUE", "1", "2", "3", "-b40", "-d1", "-d2", "-d3" - , "-f", "key1=value1", "-f", "key2=value2"); + .opt("b", "bb", 1, CLI.AS_INT) + .opt("c", "cc", 1, CLI.AS_INT, CLI.FIRST_WINS) + .opt("d", "dd", null, CLI.AS_STRING, CLI.INTO_LIST) + .opt("e", "ee", null, CLI.AS_INT) + .opt("f", "ff", null, new PairParse(), CLI.INTO_MAP) + .arg("A") + .arg("B", CLI.AS_INT) + .parse("-a100", "--aa", "200", "-c2", "-b", "50", "--cc", "100", "A-VALUE", "1", "2", "3", "-b40", + "-d1", "-d2", "-d3" + , "-f", "key1=value1", "-f", "key2=value2"); assertEquals(8, values.size()); - assertEquals("200", (String)values.get("a")); - assertEquals((Integer)40, (Integer)values.get("b")); - assertEquals((Integer)2, (Integer)values.get("c")); + assertEquals("200", (String) values.get("a")); + assertEquals((Integer) 40, (Integer) values.get("b")); + assertEquals((Integer) 2, (Integer) values.get("c")); assertEquals(null, values.get("e")); - List<String> d = (List<String>)values.get("d"); + List<String> d = (List<String>) values.get("d"); assertEquals(3, d.size()); assertEquals("1", d.get(0)); assertEquals("2", d.get(1)); http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java b/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java index 64ea8ac..23b1c8f 100644 --- a/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java +++ b/storm-core/test/jvm/org/apache/storm/metric/FakeMetricConsumer.java @@ -1,39 +1,39 @@ /** - * 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 + * 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. + * 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.metric; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.HashBasedTable; import com.google.common.collect.Multimap; import com.google.common.collect.Table; - -import org.apache.storm.metric.api.IMetricsConsumer; -import org.apache.storm.task.IErrorReporter; -import org.apache.storm.task.TopologyContext; - import java.util.Collection; import java.util.HashMap; import java.util.Map; +import org.apache.storm.metric.api.IMetricsConsumer; +import org.apache.storm.task.IErrorReporter; +import org.apache.storm.task.TopologyContext; public class FakeMetricConsumer implements IMetricsConsumer { public static final Table<String, String, Multimap<Integer, Object>> buffer = HashBasedTable.create(); + public static Map<Integer, Collection<Object>> getTaskIdToBuckets(String componentName, String metricName) { + synchronized (buffer) { + Multimap<Integer, Object> taskIdToBuckets = buffer.get(componentName, metricName); + return (null != taskIdToBuckets) ? taskIdToBuckets.asMap() : null; + } + } + @Override public void prepare(Map<String, Object> topoConf, Object registrationArgument, TopologyContext context, IErrorReporter errorReporter) { synchronized (buffer) { @@ -78,11 +78,4 @@ public class FakeMetricConsumer implements IMetricsConsumer { } return expanded; } - - public static Map<Integer, Collection<Object>> getTaskIdToBuckets(String componentName, String metricName) { - synchronized (buffer) { - Multimap<Integer, Object> taskIdToBuckets = buffer.get(componentName, metricName); - return (null != taskIdToBuckets) ? taskIdToBuckets.asMap() : null; - } - } } http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/nimbus/InMemoryTopologyActionNotifier.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/nimbus/InMemoryTopologyActionNotifier.java b/storm-core/test/jvm/org/apache/storm/nimbus/InMemoryTopologyActionNotifier.java index c1f082c..a7102c4 100644 --- a/storm-core/test/jvm/org/apache/storm/nimbus/InMemoryTopologyActionNotifier.java +++ b/storm-core/test/jvm/org/apache/storm/nimbus/InMemoryTopologyActionNotifier.java @@ -1,28 +1,23 @@ /** - * 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 + * 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. + * 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.nimbus; -import java.util.Map; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; -import java.util.HashMap; +import java.util.Map; -public class InMemoryTopologyActionNotifier implements ITopologyActionNotifierPlugin { +public class InMemoryTopologyActionNotifier implements ITopologyActionNotifierPlugin { //static to ensure eventhough the class is created using reflection we can still get //the topology to actions @@ -36,7 +31,7 @@ public class InMemoryTopologyActionNotifier implements ITopologyActionNotifierP @Override public synchronized void notify(String topologyName, String action) { - if(!topologyToActions.containsKey(topologyName)) { + if (!topologyToActions.containsKey(topologyName)) { topologyToActions.put(topologyName, new LinkedList<String>()); } topologyToActions.get(topologyName).addLast(action); http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java b/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java index 5fbf472..f122ff6 100644 --- a/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java +++ b/storm-core/test/jvm/org/apache/storm/serialization/SerializationTest.java @@ -15,20 +15,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.storm.serialization; import com.google.common.collect.Lists; +import java.io.IOException; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.storm.Config; import org.apache.storm.testing.TestSerObject; import org.apache.storm.utils.Utils; import org.junit.Assert; import org.junit.Test; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - // FIXME: it should be moved to storm-client when serialization-test.clj can be removed public class SerializationTest { http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/stats/TestStatsUtil.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/stats/TestStatsUtil.java b/storm-core/test/jvm/org/apache/storm/stats/TestStatsUtil.java index 1ca793b..d943bfb 100644 --- a/storm-core/test/jvm/org/apache/storm/stats/TestStatsUtil.java +++ b/storm-core/test/jvm/org/apache/storm/stats/TestStatsUtil.java @@ -1,35 +1,27 @@ /** - * 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 + * 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. + * 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.stats; -import java.util.Arrays; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.HashMap; - -import org.apache.storm.scheduler.WorkerSlot; import org.apache.storm.generated.WorkerResources; import org.apache.storm.generated.WorkerSummary; - -import org.junit.Before; -import org.junit.Test; +import org.apache.storm.scheduler.WorkerSlot; import org.junit.Assert; +import org.junit.Test; public class TestStatsUtil { @@ -42,7 +34,7 @@ public class TestStatsUtil { private Map<String, String> nodeHost = new HashMap<String, String>(); private Map<WorkerSlot, WorkerResources> worker2Resources = new HashMap<WorkerSlot, WorkerResources>(); - private List<Long> makeExecutorId(int firstTask, int lastTask){ + private List<Long> makeExecutorId(int firstTask, int lastTask) { return Arrays.asList(new Long(firstTask), new Long(lastTask)); } @@ -51,7 +43,7 @@ public class TestStatsUtil { hostPort.add("node1"); hostPort.add(new Long(1)); - exec2NodePort.put(makeExecutorId(1,1), hostPort); + exec2NodePort.put(makeExecutorId(1, 1), hostPort); nodeHost.put("node1", "host1"); nodeHost.put("node2", "host2"); @@ -119,9 +111,9 @@ public class TestStatsUtil { } private List<WorkerSummary> checkWorkerStats(boolean includeSys, boolean userAuthorized, String filterSupervisor) { - List<WorkerSummary> summaries = - StatsUtil.aggWorkerStats("my-storm-id", "my-storm-name", - task2Component, beats, exec2NodePort, nodeHost, worker2Resources, + List<WorkerSummary> summaries = + StatsUtil.aggWorkerStats("my-storm-id", "my-storm-name", + task2Component, beats, exec2NodePort, nodeHost, worker2Resources, includeSys, userAuthorized, filterSupervisor); for (WorkerSummary ws : summaries) { String host = ws.get_host(); @@ -178,8 +170,8 @@ public class TestStatsUtil { @Test public void aggWorkerStats() { makeTopoInfo(); - List<WorkerSummary> summaries = checkWorkerStats(true /*include sys*/, - true /*user authorized*/, + List<WorkerSummary> summaries = checkWorkerStats(true /*include sys*/, + true /*user authorized*/, null /*filter supervisor*/); WorkerSummary ws = getWorkerSummaryForPort(summaries, 1); Assert.assertEquals(1, ws.get_component_to_num_tasks().size()); @@ -190,8 +182,8 @@ public class TestStatsUtil { @Test public void aggWorkerStatsWithSystemComponents() { makeTopoInfoWithSysWorker(); - List<WorkerSummary> summaries = checkWorkerStats(true /*include sys*/, - true /*user authorized*/, + List<WorkerSummary> summaries = checkWorkerStats(true /*include sys*/, + true /*user authorized*/, null /*filter supervisor*/); WorkerSummary ws = getWorkerSummaryForPort(summaries, 2); // since we made sys components visible, the component map has all system components @@ -205,8 +197,8 @@ public class TestStatsUtil { @Test public void aggWorkerStatsWithHiddenSystemComponents() { makeTopoInfoWithSysWorker(); - List<WorkerSummary> summaries = checkWorkerStats(false /*DON'T include sys*/, - true /*user authorized*/, + List<WorkerSummary> summaries = checkWorkerStats(false /*DON'T include sys*/, + true /*user authorized*/, null /*filter supervisor*/); WorkerSummary ws1 = getWorkerSummaryForPort(summaries, 1); WorkerSummary ws2 = getWorkerSummaryForPort(summaries, 2); @@ -219,8 +211,8 @@ public class TestStatsUtil { @Test public void aggWorkerStatsForUnauthorizedUser() { makeTopoInfoWithSysWorker(); - List<WorkerSummary> summaries = checkWorkerStats(true /*include sys (should not matter)*/, - false /*user NOT authorized*/, + List<WorkerSummary> summaries = checkWorkerStats(true /*include sys (should not matter)*/, + false /*user NOT authorized*/, null /*filter supervisor*/); WorkerSummary ws1 = getWorkerSummaryForPort(summaries, 1); WorkerSummary ws2 = getWorkerSummaryForPort(summaries, 2); @@ -233,8 +225,8 @@ public class TestStatsUtil { @Test public void aggWorkerStatsFilterSupervisor() { makeTopoInfoWithMissingBeats(); - List<WorkerSummary> summaries = checkWorkerStats(true /*include sys*/, - true /*user authorized*/, + List<WorkerSummary> summaries = checkWorkerStats(true /*include sys*/, + true /*user authorized*/, "node3" /*filter supervisor*/); WorkerSummary ws = getWorkerSummaryForPort(summaries, 3); // only host3 should be returned given filter @@ -247,8 +239,8 @@ public class TestStatsUtil { @Test public void aggWorkerStatsFilterSupervisorAndHideSystemComponents() { makeTopoInfoWithMissingBeats(); - List<WorkerSummary> summaries = checkWorkerStats(false /*DON'T include sys*/, - true /*user authorized*/, + List<WorkerSummary> summaries = checkWorkerStats(false /*DON'T include sys*/, + true /*user authorized*/, "node3" /*filter supervisor*/); WorkerSummary ws = getWorkerSummaryForPort(summaries, 3); http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ConfigUtilsInstaller.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ConfigUtilsInstaller.java b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ConfigUtilsInstaller.java index bd39637..f76a01a 100644 --- a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ConfigUtilsInstaller.java +++ b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ConfigUtilsInstaller.java @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.storm.utils.staticmocking; import org.apache.storm.utils.ConfigUtils; @@ -35,7 +36,7 @@ public class ConfigUtilsInstaller implements AutoCloseable { public void close() throws Exception { if (ConfigUtils.setInstance(_oldInstance) != _curInstance) { throw new IllegalStateException( - "Instances of this resource must be closed in reverse order of opening."); + "Instances of this resource must be closed in reverse order of opening."); } } } http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ReflectionUtilsInstaller.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ReflectionUtilsInstaller.java b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ReflectionUtilsInstaller.java index 21f80bd..c2f1089 100644 --- a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ReflectionUtilsInstaller.java +++ b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ReflectionUtilsInstaller.java @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.storm.utils.staticmocking; import org.apache.storm.utils.ReflectionUtils; @@ -33,7 +34,7 @@ public class ReflectionUtilsInstaller implements AutoCloseable { public void close() throws Exception { if (ReflectionUtils.setInstance(_oldInstance) != _curInstance) { throw new IllegalStateException( - "Instances of this resource must be closed in reverse order of opening."); + "Instances of this resource must be closed in reverse order of opening."); } } } http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ServerConfigUtilsInstaller.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ServerConfigUtilsInstaller.java b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ServerConfigUtilsInstaller.java index eb81bc4..be05d0d 100644 --- a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ServerConfigUtilsInstaller.java +++ b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/ServerConfigUtilsInstaller.java @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.storm.utils.staticmocking; import org.apache.storm.utils.ServerConfigUtils; @@ -35,7 +36,7 @@ public class ServerConfigUtilsInstaller implements AutoCloseable { public void close() throws Exception { if (ServerConfigUtils.setInstance(_oldInstance) != _curInstance) { throw new IllegalStateException( - "Instances of this resource must be closed in reverse order of opening."); + "Instances of this resource must be closed in reverse order of opening."); } } } http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/UtilsInstaller.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/UtilsInstaller.java b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/UtilsInstaller.java index f700bd9..76b1624 100644 --- a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/UtilsInstaller.java +++ b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/UtilsInstaller.java @@ -15,6 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.storm.utils.staticmocking; import org.apache.storm.utils.Utils; @@ -33,7 +34,7 @@ public class UtilsInstaller implements AutoCloseable { public void close() throws Exception { if (Utils.setInstance(_oldInstance) != _curInstance) { throw new IllegalStateException( - "Instances of this resource must be closed in reverse order of opening."); + "Instances of this resource must be closed in reverse order of opening."); } } } http://git-wip-us.apache.org/repos/asf/storm/blob/fc1cf09b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/package-info.java ---------------------------------------------------------------------- diff --git a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/package-info.java b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/package-info.java index b41a2cd..00aa8a3 100644 --- a/storm-core/test/jvm/org/apache/storm/utils/staticmocking/package-info.java +++ b/storm-core/test/jvm/org/apache/storm/utils/staticmocking/package-info.java @@ -1,18 +1,61 @@ /** - * 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 + * 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. + * 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. + * + * Provides implementations for testing static methods. + * + * This package should not exist and is only necessary while we need to mock static methods. + * + * To mock static methods in java, we use a singleton. The class to mock must implement <code>setInstance</code> static method that accepts + * an instance of the selfsame class and returns the previous instance that was set. + * + * Example: + * + * <code> + * public class MyClass { public static MyClass setInstance(MyClass c) { MyClass oldInstance = _instance; _instance = c; return oldInstance; + * } + * + * // Any method that we wish to mock must delegate to the singleton // instance's corresponding member method implementation public static + * int mockableFunction(String arg) { return _instance.mockableFunctionImpl(); } + * + * protected int mockableFunctionImpl(String arg) { return arg.size(); } } + * </code> + * + * Each class that could be mocked should have an Installer class defined in this package that sets the instance on construction and + * implements the + * <code>close</code> method of {@link java.lang.AutoCloseable}. + * + * Example: + * + * <code> + * class MyClassInstaller implementes AutoCloseable { private MyClass _oldInstance; private MyClass _curInstance; + * + * MyClassInstaller(MyClass instance) { _oldInstance = MyClass.setInstance(instance); _curInstance = instance; } + * + * @Override public void close() throws Exception { if (MyClass.setInstance(_oldInstance) != _curInstance) { throw new + * IllegalStateException( "Instances of this resource must be closed in reverse order of opening."); } } } + * </code> + * + * To write a test with the mocked class instantiate a child class that implements the close method, and use try-with-resources. For + * example: + * + * <code> + * MyClass mock = new MyClass() { protected int mockableFunctionImpl(String arg) { return 42; } }; + * + * try(mock) { AssertEqual(42, MyClass.mockableFunction("not 42 characters")); }; + * </code> + * + * + * The resulting code remains thread-unsafe. + * + * This class should be removed when troublesome static methods have been replaced in the code. */ /** @@ -92,4 +135,5 @@ * This class should be removed when troublesome static methods have been * replaced in the code. */ + package org.apache.storm.utils.staticmocking;
