http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/internal/U.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/internal/U.java b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/internal/U.java index ef36125..05c76b4 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/internal/U.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/typedef/internal/U.java @@ -20,9 +20,9 @@ package org.apache.ignite.internal.util.typedef.internal; import org.apache.ignite.internal.util.*; /** - * Defines internal {@code typedef} for {@link GridUtils}. Since Java doesn't provide type aliases + * Defines internal {@code typedef} for {@link IgniteUtils}. Since Java doesn't provide type aliases * (like Scala, for example) we resort to these types of measures. This is intended for internal * use only and meant to provide for more terse code when readability of code is not compromised. */ @SuppressWarnings({"ExtendsUtilityClass"}) -public class U extends GridUtils { /* No-op. */ } +public class U extends IgniteUtils { /* No-op. */ }
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java index 8a2247e..6342bb5 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/misc/VisorResolveHostNameTask.java @@ -63,7 +63,7 @@ public class VisorResolveHostNameTask extends VisorOneNodeTask<Void, Map<String, try { IgniteBiTuple<Collection<String>, Collection<String>> addrs = - GridUtils.resolveLocalAddresses(InetAddress.getByName("0.0.0.0")); + IgniteUtils.resolveLocalAddresses(InetAddress.getByName("0.0.0.0")); assert(addrs.get1() != null); assert(addrs.get2() != null); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java index 95bb434..190f6da 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/visor/query/VisorQueryUtils.java @@ -53,8 +53,8 @@ public class VisorQueryUtils { if (o != null) { Class<?> clazz = o.getClass(); - return clazz.isArray() ? GridUtils.compact(clazz.getComponentType().getName()) + "[]" - : GridUtils.compact(o.getClass().getName()); + return clazz.isArray() ? IgniteUtils.compact(clazz.getComponentType().getName()) + "[]" + : IgniteUtils.compact(o.getClass().getName()); } else return "n/a"; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/IgniteOptimizedMarshaller.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/IgniteOptimizedMarshaller.java b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/IgniteOptimizedMarshaller.java index bee3a2e..22349e1 100644 --- a/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/IgniteOptimizedMarshaller.java +++ b/modules/core/src/main/java/org/apache/ignite/marshaller/optimized/IgniteOptimizedMarshaller.java @@ -183,7 +183,7 @@ public class IgniteOptimizedMarshaller extends IgniteAbstractMarshaller { if (path == null) return; - URL url = GridUtils.resolveGridGainUrl(path, false); + URL url = IgniteUtils.resolveGridGainUrl(path, false); if (url == null) throw new IgniteCheckedException("Failed to find resource for name: " + path); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/IgniteExceptionHelpLinksSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/IgniteExceptionHelpLinksSelfTest.java b/modules/core/src/test/java/org/apache/ignite/IgniteExceptionHelpLinksSelfTest.java index 3fbf4ec..d555c41 100644 --- a/modules/core/src/test/java/org/apache/ignite/IgniteExceptionHelpLinksSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/IgniteExceptionHelpLinksSelfTest.java @@ -18,12 +18,11 @@ package org.apache.ignite; import junit.framework.*; -import org.apache.ignite.*; import org.jetbrains.annotations.*; import java.util.*; -import static org.apache.ignite.internal.util.GridUtils.*; +import static org.apache.ignite.internal.util.IgniteUtils.*; /** * Tests for proper link output in stack traces. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java index ca71778..2c0b1dd 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/GridEventStorageCheckAllEventsSelfTest.java @@ -233,7 +233,7 @@ public class GridEventStorageCheckAllEventsSelfTest extends GridCommonAbstractTe /** * Returns timestamp at the method call moment, but sleeps before return, - * to allow pass {@link GridUtils#currentTimeMillis()}. + * to allow pass {@link IgniteUtils#currentTimeMillis()}. * * @return Call timestamp. * @throws InterruptedException If sleep was interrupted. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java index fa3aeb3..d0dcda6 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheAbstractMetricsSelfTest.java @@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.cache; import org.apache.ignite.*; import org.apache.ignite.cache.*; import org.apache.ignite.internal.*; -import org.apache.ignite.internal.util.GridUtils; +import org.apache.ignite.internal.util.IgniteUtils; import org.apache.ignite.internal.util.lang.*; import org.apache.ignite.testframework.*; import org.apache.ignite.transactions.*; @@ -739,7 +739,7 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract } // One more update from the same cache entry to ensure that expire time is shifted forward. - GridUtils.sleep(100); + IgniteUtils.sleep(100); tx = inTx ? c.txStart() : null; @@ -764,7 +764,7 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract } // And one more direct update to ensure that expire time is shifted forward. - GridUtils.sleep(100); + IgniteUtils.sleep(100); assertEquals(0, grid(0).cache(null).metrics().getCacheEvictions()); @@ -791,7 +791,7 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract } // And one more update to ensure that ttl is not changed and expire time is not shifted forward. - GridUtils.sleep(100); + IgniteUtils.sleep(100); assertEquals(0, grid(0).cache(null).metrics().getCacheEvictions()); @@ -864,7 +864,7 @@ public abstract class GridCacheAbstractMetricsSelfTest extends GridCacheAbstract tx.commit(); } - GridUtils.sleep(2000); + IgniteUtils.sleep(2000); entry = c.entry(key); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithSpecifiedWorkDirectorySelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithSpecifiedWorkDirectorySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithSpecifiedWorkDirectorySelfTest.java index d6ef6f3..0e034af 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithSpecifiedWorkDirectorySelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithSpecifiedWorkDirectorySelfTest.java @@ -31,7 +31,7 @@ import java.io.*; import java.util.*; import static org.apache.ignite.IgniteSystemProperties.*; -import static org.apache.ignite.internal.util.GridUtils.*; +import static org.apache.ignite.internal.util.IgniteUtils.*; /** * Checks creation of work folder. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithUndefinedGridGainHomeSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithUndefinedGridGainHomeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithUndefinedGridGainHomeSelfTest.java index 0fc0ef4..a56f8b2 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithUndefinedGridGainHomeSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/GridStartupWithUndefinedGridGainHomeSelfTest.java @@ -29,7 +29,7 @@ import org.apache.ignite.internal.util.typedef.internal.*; import org.apache.ignite.testframework.junits.common.*; import static org.apache.ignite.IgniteSystemProperties.*; -import static org.apache.ignite.internal.util.GridUtils.*; +import static org.apache.ignite.internal.util.IgniteUtils.*; /** * Checks that node can be started without operations with undefined GRIDGAIN_HOME. @@ -58,7 +58,7 @@ public class GridStartupWithUndefinedGridGainHomeSelfTest extends TestCase { * @throws Exception If failed. */ public void testStartStopWithUndefinedGridGainHome() throws Exception { - GridUtils.nullifyHomeDirectory(); + IgniteUtils.nullifyHomeDirectory(); // We can't use U.getGridGainHome() here because // it will initialize cached value which is forbidden to override. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java b/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java index b095c5f..b9bb5ab 100644 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/GridTestClockTimer.java @@ -17,8 +17,6 @@ package org.apache.ignite.internal.util; -import org.apache.ignite.internal.util.*; - /** * Clock timer for tests. */ @@ -26,13 +24,13 @@ public class GridTestClockTimer implements Runnable { /** {@inheritDoc} */ @Override public void run() { while (true) { - GridUtils.curTimeMillis = System.currentTimeMillis(); + IgniteUtils.curTimeMillis = System.currentTimeMillis(); try { Thread.sleep(10); } catch (InterruptedException ignored) { - GridUtils.log(null, "Timer thread has been interrupted."); + IgniteUtils.log(null, "Timer thread has been interrupted."); break; } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/internal/util/GridUtilsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/GridUtilsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/GridUtilsSelfTest.java deleted file mode 100644 index 3848b7f..0000000 --- a/modules/core/src/test/java/org/apache/ignite/internal/util/GridUtilsSelfTest.java +++ /dev/null @@ -1,728 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.ignite.internal.util; - -import org.apache.ignite.Ignite; -import org.apache.ignite.cluster.ClusterGroup; -import org.apache.ignite.cluster.ClusterNode; -import org.apache.ignite.compute.ComputeJob; -import org.apache.ignite.compute.ComputeJobAdapter; -import org.apache.ignite.internal.util.lang.GridPeerDeployAware; -import org.apache.ignite.internal.util.typedef.X; -import org.apache.ignite.internal.util.typedef.internal.U; -import org.apache.ignite.testframework.GridTestUtils; -import org.apache.ignite.testframework.http.GridEmbeddedHttpServer; -import org.apache.ignite.testframework.junits.GridTestKernalContext; -import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; -import org.apache.ignite.testframework.junits.common.GridCommonTest; -import org.jetbrains.annotations.Nullable; - -import java.io.*; -import java.lang.annotation.*; -import java.math.BigInteger; -import java.net.InetSocketAddress; -import java.net.URL; -import java.nio.ByteBuffer; -import java.util.*; - -import static org.junit.Assert.assertArrayEquals; - -/** - * Grid utils tests. - */ -@GridCommonTest(group = "Utils") -public class GridUtilsSelfTest extends GridCommonAbstractTest { - /** */ - public static final int[] EMPTY = new int[0]; - - /** - * @return 120 character length string. - */ - private String text120() { - char[] chs = new char[120]; - - Arrays.fill(chs, 'x'); - - return new String(chs); - } - - /** - * - */ - public void testIsPow2() { - assertTrue(U.isPow2(1)); - assertTrue(U.isPow2(2)); - assertTrue(U.isPow2(4)); - assertTrue(U.isPow2(8)); - assertTrue(U.isPow2(16)); - assertTrue(U.isPow2(16 * 16)); - assertTrue(U.isPow2(32 * 32)); - - assertFalse(U.isPow2(-4)); - assertFalse(U.isPow2(-3)); - assertFalse(U.isPow2(-2)); - assertFalse(U.isPow2(-1)); - assertFalse(U.isPow2(0)); - assertFalse(U.isPow2(3)); - assertFalse(U.isPow2(5)); - assertFalse(U.isPow2(6)); - assertFalse(U.isPow2(7)); - assertFalse(U.isPow2(9)); - } - - /** - * @throws Exception If failed. - */ - public void testAllLocalIps() throws Exception { - Collection<String> ips = U.allLocalIps(); - - System.out.println("All local IPs: " + ips); - } - - /** - * @throws Exception If failed. - */ - public void testAllLocalMACs() throws Exception { - Collection<String> macs = U.allLocalMACs(); - - System.out.println("All local MACs: " + macs); - } - - /** - * On linux NetworkInterface.getHardwareAddress() returns null from time to time. - * - * @throws Exception If failed. - */ - public void testAllLocalMACsMultiThreaded() throws Exception { - GridTestUtils.runMultiThreaded(new Runnable() { - @Override public void run() { - for (int i = 0; i < 30; i++) { - Collection<String> macs = U.allLocalMACs(); - - assertTrue("Mac address are not defined.", !macs.isEmpty()); - } - } - }, 32, "thread"); - } - - /** - * @throws Exception If failed. - */ - public void testByteArray2String() throws Exception { - assertEquals("{0x0A,0x14,0x1E,0x28,0x32,0x3C,0x46,0x50,0x5A}", - U.byteArray2String(new byte[] {10, 20, 30, 40, 50, 60, 70, 80, 90}, "0x%02X", ",0x%02X")); - } - - /** - * @throws Exception If failed. - */ - public void testFormatMins() throws Exception { - printFormatMins(0); - printFormatMins(1); - printFormatMins(2); - printFormatMins(59); - printFormatMins(60); - printFormatMins(61); - printFormatMins(60 * 24 - 1); - printFormatMins(60 * 24); - printFormatMins(60 * 24 + 1); - printFormatMins(5 * 60 * 24 - 1); - printFormatMins(5 * 60 * 24); - printFormatMins(5 * 60 * 24 + 1); - } - - /** - * Helper method for {@link #testFormatMins()} - * - * @param mins Minutes to test. - */ - private void printFormatMins(long mins) { - System.out.println("For " + mins + " minutes: " + X.formatMins(mins)); - } - - /** - * @throws Exception If failed. - */ - public void testDownloadUrlFromHttp() throws Exception { - GridEmbeddedHttpServer srv = null; - try { - String urlPath = "/testDownloadUrl/"; - srv = GridEmbeddedHttpServer.startHttpServer().withFileDownloadingHandler(urlPath, - GridTestUtils.resolveGridGainPath("/modules/core/src/test/config/tests.properties")); - - File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "url-http.file"); - - file = U.downloadUrl(new URL(srv.getBaseUrl() + urlPath), file); - - assert file.exists(); - assert file.delete(); - } - finally { - if (srv != null) - srv.stop(1); - } - } - - /** - * @throws Exception If failed. - */ - public void testDownloadUrlFromHttps() throws Exception { - GridEmbeddedHttpServer srv = null; - try { - String urlPath = "/testDownloadUrl/"; - srv = GridEmbeddedHttpServer.startHttpsServer().withFileDownloadingHandler(urlPath, - GridTestUtils.resolveGridGainPath("modules/core/src/test/config/tests.properties")); - - File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "url-http.file"); - - file = U.downloadUrl(new URL(srv.getBaseUrl() + urlPath), file); - - assert file.exists(); - assert file.delete(); - } - finally { - if (srv != null) - srv.stop(1); - } - } - - /** - * @throws Exception If failed. - */ - public void testDownloadUrlFromLocalFile() throws Exception { - File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "url-http.file"); - - file = U.downloadUrl( - GridTestUtils.resolveGridGainPath("modules/core/src/test/config/tests.properties").toURI().toURL(), file); - - assert file.exists(); - assert file.delete(); - } - - /** - * @throws Exception If failed. - */ - public void testOs() throws Exception { - System.out.println("OS string: " + U.osString()); - System.out.println("JDK string: " + U.jdkString()); - System.out.println("OS/JDK string: " + U.osJdkString()); - - System.out.println("Is Windows: " + U.isWindows()); - System.out.println("Is Windows 95: " + U.isWindows95()); - System.out.println("Is Windows 98: " + U.isWindows98()); - System.out.println("Is Windows NT: " + U.isWindowsNt()); - System.out.println("Is Windows 2000: " + U.isWindows2k()); - System.out.println("Is Windows 2003: " + U.isWindows2003()); - System.out.println("Is Windows XP: " + U.isWindowsXp()); - System.out.println("Is Windows Vista: " + U.isWindowsVista()); - System.out.println("Is Linux: " + U.isLinux()); - System.out.println("Is Mac OS: " + U.isMacOs()); - System.out.println("Is Netware: " + U.isNetWare()); - System.out.println("Is Solaris: " + U.isSolaris()); - System.out.println("Is Solaris SPARC: " + U.isSolarisSparc()); - System.out.println("Is Solaris x86: " + U.isSolarisX86()); - System.out.println("Is Windows7: " + U.isWindows7()); - System.out.println("Is Sufficiently Tested OS: " + U.isSufficientlyTestedOs()); - } - - /** - * @throws Exception If failed. - */ - public void testJavaSerialization() throws Exception { - ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); - ObjectOutputStream objOut = new ObjectOutputStream(byteOut); - - objOut.writeObject(new byte[] {1, 2, 3, 4, 5, 5}); - - objOut.flush(); - - byte[] sBytes = byteOut.toByteArray(); - - ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(sBytes)); - - in.readObject(); - } - - /** - * - */ - public void testHidePassword() { - Collection<String> uriList = new ArrayList<>(); - - uriList.add("ftp://anonymous:111111;freq=5...@unknown.host:21/pub/gg-test"); - uriList.add("ftp://anonymous:111111;freq=5000@localhost:21/pub/gg-test"); - - uriList.add("http://freq=5000@localhost/tasks"); - uriList.add("http://freq=5...@unknownhost.host/tasks"); - - for (String uri : uriList) - X.println(uri + " -> " + U.hidePassword(uri)); - } - - /** - * Test job to test possible indefinite recursion in detecting peer deploy aware. - */ - @SuppressWarnings({"UnusedDeclaration"}) - private class SelfReferencedJob extends ComputeJobAdapter implements GridPeerDeployAware { - /** */ - private SelfReferencedJob ref; - - /** */ - private SelfReferencedJob[] arr; - - /** */ - private Collection<SelfReferencedJob> col; - - /** */ - private ClusterNode node; - - /** */ - private ClusterGroup subGrid; - - /** - * @param ignite Grid. - */ - private SelfReferencedJob(Ignite ignite) { - node = ignite.cluster().localNode(); - - ref = this; - - arr = new SelfReferencedJob[] {this, this}; - - col = Arrays.asList(this, this, this); - - GridTestKernalContext ctx = newContext(); - - subGrid = ignite.cluster().forNodes(Collections.singleton(node)); - } - - /** {@inheritDoc} */ - @Override public Object execute() { - return null; - } - - /** {@inheritDoc} */ - @Override public Class<?> deployClass() { - return getClass(); - } - - /** {@inheritDoc} */ - @Override public ClassLoader classLoader() { - return getClass().getClassLoader(); - } - } - - /** - * @throws Exception If test fails. - */ - public void testDetectPeerDeployAwareInfiniteRecursion() throws Exception { - Ignite g = startGrid(1); - - try { - final SelfReferencedJob job = new SelfReferencedJob(g); - - GridPeerDeployAware d = U.detectPeerDeployAware(U.peerDeployAware(job)); - - assert d != null; - assert SelfReferencedJob.class == d.deployClass(); - assert d.classLoader() == SelfReferencedJob.class.getClassLoader(); - } - finally { - stopGrid(1); - } - } - - /** - * @param r Runnable. - * @return Job created for given runnable. - */ - private static ComputeJob job(final Runnable r) { - return new ComputeJobAdapter() { - @Nullable @Override public Object execute() { - r.run(); - - return null; - } - }; - } - - /** - * - * @throws Exception If failed. - */ - public void testParseIsoDate() throws Exception { - Calendar cal = U.parseIsoDate("2009-12-08T13:30:44.000Z"); - - assert cal.get(Calendar.YEAR) == 2009; - assert cal.get(Calendar.MONTH) == 11; - assert cal.get(Calendar.DAY_OF_MONTH) == 8; - assert cal.get(Calendar.HOUR_OF_DAY) == 13; - assert cal.get(Calendar.MINUTE) == 30; - assert cal.get(Calendar.SECOND) == 44; - assert cal.get(Calendar.MILLISECOND) == 0; - assert cal.get(Calendar.ZONE_OFFSET) == 0 : - "Unexpected value: " + cal.get(Calendar.ZONE_OFFSET); - - cal = U.parseIsoDate("2009-12-08T13:30:44.000+03:00"); - - assert cal.get(Calendar.YEAR) == 2009; - assert cal.get(Calendar.MONTH) == 11; - assert cal.get(Calendar.DAY_OF_MONTH) == 8; - assert cal.get(Calendar.HOUR_OF_DAY) == 13; - assert cal.get(Calendar.MINUTE) == 30; - assert cal.get(Calendar.SECOND) == 44; - assert cal.get(Calendar.MILLISECOND) == 0; - assert cal.get(Calendar.ZONE_OFFSET) == 3 * 60 * 60 * 1000 : - "Unexpected value: " + cal.get(Calendar.ZONE_OFFSET); - - cal = U.parseIsoDate("2009-12-08T13:30:44.000+0300"); - - assert cal.get(Calendar.YEAR) == 2009; - assert cal.get(Calendar.MONTH) == 11; - assert cal.get(Calendar.DAY_OF_MONTH) == 8; - assert cal.get(Calendar.HOUR_OF_DAY) == 13; - assert cal.get(Calendar.MINUTE) == 30; - assert cal.get(Calendar.SECOND) == 44; - assert cal.get(Calendar.MILLISECOND) == 0; - assert cal.get(Calendar.ZONE_OFFSET) == 3 * 60 * 60 * 1000 : - "Unexpected value: " + cal.get(Calendar.ZONE_OFFSET); - } - - /** - * @throws Exception If test failed. - */ - public void testPeerDeployAware0() throws Exception { - Collection<Object> col = new ArrayList<>(); - - col.add(null); - col.add(null); - col.add(null); - - GridPeerDeployAware pda = U.peerDeployAware0(col); - - assert pda != null; - - col.clear(); - - col.add(null); - - pda = U.peerDeployAware0(col); - - assert pda != null; - - col.clear(); - - pda = U.peerDeployAware0(col); - - assert pda != null; - - col.clear(); - - col.add(null); - col.add("Test"); - col.add(null); - - pda = U.peerDeployAware0(col); - - assert pda != null; - - col.clear(); - - col.add("Test"); - - pda = U.peerDeployAware0(col); - - assert pda != null; - - col.clear(); - - col.add("Test"); - col.add(this); - - pda = U.peerDeployAware0(col); - - assert pda != null; - - col.clear(); - - col.add(null); - col.add("Test"); - col.add(null); - col.add(this); - col.add(null); - - pda = U.peerDeployAware0(col); - - assert pda != null; - } - - /** - * Test UUID to bytes array conversion. - */ - public void testsGetBytes() { - for (int i = 0; i < 100; i++) { - UUID id = UUID.randomUUID(); - - byte[] bytes = GridUtils.uuidToBytes(id); - BigInteger n = new BigInteger(bytes); - - assert n.shiftRight(Long.SIZE).longValue() == id.getMostSignificantBits(); - assert n.longValue() == id.getLeastSignificantBits(); - } - } - - /** - * - */ - @SuppressWarnings("ZeroLengthArrayAllocation") - public void testReadByteArray() { - assertTrue(Arrays.equals(new byte[0], U.readByteArray(ByteBuffer.allocate(0)))); - assertTrue(Arrays.equals(new byte[0], U.readByteArray(ByteBuffer.allocate(0), ByteBuffer.allocate(0)))); - - Random rnd = new Random(); - - byte[] bytes = new byte[13]; - - rnd.nextBytes(bytes); - - assertTrue(Arrays.equals(bytes, U.readByteArray(ByteBuffer.wrap(bytes)))); - assertTrue(Arrays.equals(bytes, U.readByteArray(ByteBuffer.wrap(bytes), ByteBuffer.allocate(0)))); - assertTrue(Arrays.equals(bytes, U.readByteArray(ByteBuffer.allocate(0), ByteBuffer.wrap(bytes)))); - - for (int i = 0; i < 1000; i++) { - int n = rnd.nextInt(100); - - bytes = new byte[n]; - - rnd.nextBytes(bytes); - - ByteBuffer[] bufs = new ByteBuffer[1 + rnd.nextInt(10)]; - - int x = 0; - - for (int j = 0; j < bufs.length - 1; j++) { - int size = x == n ? 0 : rnd.nextInt(n - x); - - bufs[j] = (ByteBuffer)ByteBuffer.wrap(bytes).position(x).limit(x += size); - } - - bufs[bufs.length - 1] = (ByteBuffer)ByteBuffer.wrap(bytes).position(x).limit(n); - - assertTrue(Arrays.equals(bytes, U.readByteArray(bufs))); - } - } - - /** - * - */ - @SuppressWarnings("ZeroLengthArrayAllocation") - public void testHashCodeFromBuffers() { - assertEquals(Arrays.hashCode(new byte[0]), U.hashCode(ByteBuffer.allocate(0))); - assertEquals(Arrays.hashCode(new byte[0]), U.hashCode(ByteBuffer.allocate(0), ByteBuffer.allocate(0))); - - Random rnd = new Random(); - - for (int i = 0; i < 1000; i++) { - ByteBuffer[] bufs = new ByteBuffer[1 + rnd.nextInt(15)]; - - for (int j = 0; j < bufs.length; j++) { - byte[] bytes = new byte[rnd.nextInt(25)]; - - rnd.nextBytes(bytes); - - bufs[j] = ByteBuffer.wrap(bytes); - } - - assertEquals(U.hashCode(bufs), Arrays.hashCode(U.readByteArray(bufs))); - } - } - - /** - * Test annotation look up. - */ - public void testGetAnnotations() { - assert U.getAnnotation(A1.class, Ann1.class) != null; - assert U.getAnnotation(A2.class, Ann1.class) != null; - - assert U.getAnnotation(A1.class, Ann2.class) != null; - assert U.getAnnotation(A2.class, Ann2.class) != null; - - assert U.getAnnotation(A3.class, Ann1.class) == null; - assert U.getAnnotation(A3.class, Ann2.class) != null; - } - - /** - * - */ - public void testUnique() { - int[][][] arrays = new int[][][]{ - new int[][]{EMPTY, EMPTY, EMPTY}, - new int[][]{new int[]{1, 2, 3}, EMPTY, new int[]{1, 2, 3}}, - new int[][]{new int[]{1, 2, 3}, new int[]{1, 2, 3}, new int[]{1, 2, 3}}, - new int[][]{new int[]{1, 2, 3}, new int[]{1, 3}, new int[]{1, 2, 3}}, - new int[][]{new int[]{1, 2, 30, 40, 50}, new int[]{2, 40}, new int[]{1, 2, 30, 40, 50}}, - new int[][]{new int[]{-100, -13, 1, 2, 5, 30, 40, 50}, new int[]{1, 2, 6, 100, 113}, - new int[]{-100, -13, 1, 2, 5, 6, 30, 40, 50, 100, 113}} - }; - - for (int[][] a : arrays) { - assertArrayEquals(a[2], U.unique(a[0], a[0].length, a[1], a[1].length)); - - assertArrayEquals(a[2], U.unique(a[1], a[1].length, a[0], a[0].length)); - } - - assertArrayEquals(new int[]{1, 2, 3, 4}, U.unique(new int[]{1, 2, 3, 8}, 3, new int[]{2, 4, 5}, 2)); - assertArrayEquals(new int[]{2, 4}, U.unique(new int[]{1, 2, 3, 8}, 0, new int[]{2, 4, 5}, 2)); - assertArrayEquals(new int[]{1, 2, 4, 5}, U.unique(new int[]{1, 2, 3, 8}, 2, new int[]{2, 4, 5, 6}, 3)); - assertArrayEquals(new int[]{1, 2}, U.unique(new int[]{1, 2, 3, 8}, 2, new int[]{2, 4, 5, 6}, 0)); - } - - /** - * - */ - public void testDifference() { - int[][][] arrays = new int[][][]{ - new int[][]{EMPTY, EMPTY, EMPTY}, - new int[][]{new int[]{1, 2, 3}, EMPTY, new int[]{1, 2, 3}}, - new int[][]{EMPTY, new int[]{1, 2, 3}, EMPTY}, - new int[][]{new int[]{1, 2, 3}, new int[]{1, 2, 3}, EMPTY}, - new int[][]{new int[]{-100, -50, 1, 2, 3}, new int[]{-50, -1, 1, 3}, new int[]{-100, 2}}, - new int[][]{new int[]{-100, 1, 2, 30, 40, 50}, new int[]{2, 40}, new int[]{-100, 1, 30, 50}}, - new int[][]{new int[]{-1, 1, 2, 30, 40, 50}, new int[]{1, 2, 100, 113}, new int[]{-1, 30, 40, 50}} - }; - - for (int[][] a : arrays) - assertArrayEquals(a[2], U.difference(a[0], a[0].length, a[1], a[1].length)); - - assertArrayEquals(new int[]{1, 2}, U.difference(new int[]{1, 2, 30, 40, 50}, 3, new int[]{30, 40}, 2)); - assertArrayEquals(EMPTY, U.difference(new int[]{1, 2, 30, 40, 50}, 0, new int[]{30, 40}, 2)); - assertArrayEquals(new int[]{1, 2, 40}, U.difference(new int[]{1, 2, 30, 40, 50}, 4, new int[]{30, 40}, 1)); - assertArrayEquals(new int[]{1, 2, 30, 40}, U.difference(new int[]{1, 2, 30, 40, 50}, 4, new int[]{30, 40}, 0)); - } - - /** - * - */ - public void testCopyIfExceeded() { - int[][] arrays = new int[][]{new int[]{13, 14, 17, 11}, new int[]{13}, EMPTY}; - - for (int[] a : arrays) { - int[] b = Arrays.copyOf(a, a.length); - - assertEquals(a, U.copyIfExceeded(a, a.length)); - assertArrayEquals(b, U.copyIfExceeded(a, a.length)); - - for (int j = 0; j < a.length - 1; j++) - assertArrayEquals(Arrays.copyOf(b, j), U.copyIfExceeded(a, j)); - } - } - - /** - * - */ - public void testIsIncreasingArray() { - assertTrue(U.isIncreasingArray(EMPTY, 0)); - assertTrue(U.isIncreasingArray(new int[]{Integer.MIN_VALUE, -10, 1, 13, Integer.MAX_VALUE}, 5)); - assertTrue(U.isIncreasingArray(new int[]{1, 2, 3, -1, 5}, 0)); - assertTrue(U.isIncreasingArray(new int[]{1, 2, 3, -1, 5}, 3)); - assertFalse(U.isIncreasingArray(new int[]{1, 2, 3, -1, 5}, 4)); - assertFalse(U.isIncreasingArray(new int[]{1, 2, 3, -1, 5}, 5)); - assertFalse(U.isIncreasingArray(new int[]{1, 2, 3, 3, 5}, 4)); - assertTrue(U.isIncreasingArray(new int[]{1, -1}, 1)); - assertFalse(U.isIncreasingArray(new int[]{1, -1}, 2)); - assertTrue(U.isIncreasingArray(new int[]{13, 13, 13}, 1)); - assertFalse(U.isIncreasingArray(new int[]{13, 13, 13}, 2)); - assertFalse(U.isIncreasingArray(new int[]{13, 13, 13}, 3)); - } - - /** - * - */ - public void testIsNonDecreasingArray() { - assertTrue(U.isNonDecreasingArray(EMPTY, 0)); - assertTrue(U.isNonDecreasingArray(new int[]{Integer.MIN_VALUE, -10, 1, 13, Integer.MAX_VALUE}, 5)); - assertTrue(U.isNonDecreasingArray(new int[]{1, 2, 3, -1, 5}, 0)); - assertTrue(U.isNonDecreasingArray(new int[]{1, 2, 3, -1, 5}, 3)); - assertFalse(U.isNonDecreasingArray(new int[]{1, 2, 3, -1, 5}, 4)); - assertFalse(U.isNonDecreasingArray(new int[]{1, 2, 3, -1, 5}, 5)); - assertTrue(U.isNonDecreasingArray(new int[]{1, 2, 3, 3, 5}, 4)); - assertTrue(U.isNonDecreasingArray(new int[]{1, -1}, 1)); - assertFalse(U.isNonDecreasingArray(new int[]{1, -1}, 2)); - assertTrue(U.isNonDecreasingArray(new int[]{13, 13, 13}, 1)); - assertTrue(U.isNonDecreasingArray(new int[]{13, 13, 13}, 2)); - assertTrue(U.isNonDecreasingArray(new int[]{13, 13, 13}, 3)); - } - - /** - * Test InetAddress Comparator. - */ - public void testInetAddressesComparator() { - List<InetSocketAddress> ips = new ArrayList<InetSocketAddress>() { - { - add(new InetSocketAddress("127.0.0.1", 1)); - add(new InetSocketAddress("10.0.0.1", 1)); - add(new InetSocketAddress("172.16.0.1", 1)); - add(new InetSocketAddress("192.168.0.1", 1)); - add(new InetSocketAddress("100.0.0.1", 1)); - add(new InetSocketAddress("XXX", 1)); - } - }; - - Collections.sort(ips, U.inetAddressesComparator(true)); - - assertTrue(ips.get(0).getAddress().isLoopbackAddress()); - assertTrue(ips.get(ips.size() - 1).isUnresolved()); - - Collections.sort(ips, U.inetAddressesComparator(false)); - - assertTrue(ips.get(ips.size() - 2).getAddress().isLoopbackAddress()); - assertTrue(ips.get(ips.size() - 1).isUnresolved()); - } - - - public void testMD5Calculation() throws Exception { - String md5 = GridUtils.calculateMD5(new ByteArrayInputStream("Corrupted information.".getBytes())); - - assertEquals("d7dbe555be2eee7fa658299850169fa1", md5); - } - - /** - * Test enum. - */ - private enum TestEnum { - E1, - E2, - E3 - } - - @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) - private @interface Ann1 {} - - @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) - private @interface Ann2 {} - - private static class A1 implements I3, I5 {} - private static class A2 extends A1 {} - private static class A3 implements I5 {} - - @Ann1 private interface I1 {} - private interface I2 extends I1 {} - private interface I3 extends I2 {} - @Ann2 private interface I4 {} - private interface I5 extends I4 {} -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java new file mode 100644 index 0000000..c5917bd --- /dev/null +++ b/modules/core/src/test/java/org/apache/ignite/internal/util/IgniteUtilsSelfTest.java @@ -0,0 +1,728 @@ +/* + * 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.ignite.internal.util; + +import org.apache.ignite.Ignite; +import org.apache.ignite.cluster.ClusterGroup; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.compute.ComputeJob; +import org.apache.ignite.compute.ComputeJobAdapter; +import org.apache.ignite.internal.util.lang.GridPeerDeployAware; +import org.apache.ignite.internal.util.typedef.X; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.testframework.GridTestUtils; +import org.apache.ignite.testframework.http.GridEmbeddedHttpServer; +import org.apache.ignite.testframework.junits.GridTestKernalContext; +import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest; +import org.apache.ignite.testframework.junits.common.GridCommonTest; +import org.jetbrains.annotations.Nullable; + +import java.io.*; +import java.lang.annotation.*; +import java.math.BigInteger; +import java.net.InetSocketAddress; +import java.net.URL; +import java.nio.ByteBuffer; +import java.util.*; + +import static org.junit.Assert.assertArrayEquals; + +/** + * Grid utils tests. + */ +@GridCommonTest(group = "Utils") +public class IgniteUtilsSelfTest extends GridCommonAbstractTest { + /** */ + public static final int[] EMPTY = new int[0]; + + /** + * @return 120 character length string. + */ + private String text120() { + char[] chs = new char[120]; + + Arrays.fill(chs, 'x'); + + return new String(chs); + } + + /** + * + */ + public void testIsPow2() { + assertTrue(U.isPow2(1)); + assertTrue(U.isPow2(2)); + assertTrue(U.isPow2(4)); + assertTrue(U.isPow2(8)); + assertTrue(U.isPow2(16)); + assertTrue(U.isPow2(16 * 16)); + assertTrue(U.isPow2(32 * 32)); + + assertFalse(U.isPow2(-4)); + assertFalse(U.isPow2(-3)); + assertFalse(U.isPow2(-2)); + assertFalse(U.isPow2(-1)); + assertFalse(U.isPow2(0)); + assertFalse(U.isPow2(3)); + assertFalse(U.isPow2(5)); + assertFalse(U.isPow2(6)); + assertFalse(U.isPow2(7)); + assertFalse(U.isPow2(9)); + } + + /** + * @throws Exception If failed. + */ + public void testAllLocalIps() throws Exception { + Collection<String> ips = U.allLocalIps(); + + System.out.println("All local IPs: " + ips); + } + + /** + * @throws Exception If failed. + */ + public void testAllLocalMACs() throws Exception { + Collection<String> macs = U.allLocalMACs(); + + System.out.println("All local MACs: " + macs); + } + + /** + * On linux NetworkInterface.getHardwareAddress() returns null from time to time. + * + * @throws Exception If failed. + */ + public void testAllLocalMACsMultiThreaded() throws Exception { + GridTestUtils.runMultiThreaded(new Runnable() { + @Override public void run() { + for (int i = 0; i < 30; i++) { + Collection<String> macs = U.allLocalMACs(); + + assertTrue("Mac address are not defined.", !macs.isEmpty()); + } + } + }, 32, "thread"); + } + + /** + * @throws Exception If failed. + */ + public void testByteArray2String() throws Exception { + assertEquals("{0x0A,0x14,0x1E,0x28,0x32,0x3C,0x46,0x50,0x5A}", + U.byteArray2String(new byte[] {10, 20, 30, 40, 50, 60, 70, 80, 90}, "0x%02X", ",0x%02X")); + } + + /** + * @throws Exception If failed. + */ + public void testFormatMins() throws Exception { + printFormatMins(0); + printFormatMins(1); + printFormatMins(2); + printFormatMins(59); + printFormatMins(60); + printFormatMins(61); + printFormatMins(60 * 24 - 1); + printFormatMins(60 * 24); + printFormatMins(60 * 24 + 1); + printFormatMins(5 * 60 * 24 - 1); + printFormatMins(5 * 60 * 24); + printFormatMins(5 * 60 * 24 + 1); + } + + /** + * Helper method for {@link #testFormatMins()} + * + * @param mins Minutes to test. + */ + private void printFormatMins(long mins) { + System.out.println("For " + mins + " minutes: " + X.formatMins(mins)); + } + + /** + * @throws Exception If failed. + */ + public void testDownloadUrlFromHttp() throws Exception { + GridEmbeddedHttpServer srv = null; + try { + String urlPath = "/testDownloadUrl/"; + srv = GridEmbeddedHttpServer.startHttpServer().withFileDownloadingHandler(urlPath, + GridTestUtils.resolveGridGainPath("/modules/core/src/test/config/tests.properties")); + + File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "url-http.file"); + + file = U.downloadUrl(new URL(srv.getBaseUrl() + urlPath), file); + + assert file.exists(); + assert file.delete(); + } + finally { + if (srv != null) + srv.stop(1); + } + } + + /** + * @throws Exception If failed. + */ + public void testDownloadUrlFromHttps() throws Exception { + GridEmbeddedHttpServer srv = null; + try { + String urlPath = "/testDownloadUrl/"; + srv = GridEmbeddedHttpServer.startHttpsServer().withFileDownloadingHandler(urlPath, + GridTestUtils.resolveGridGainPath("modules/core/src/test/config/tests.properties")); + + File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "url-http.file"); + + file = U.downloadUrl(new URL(srv.getBaseUrl() + urlPath), file); + + assert file.exists(); + assert file.delete(); + } + finally { + if (srv != null) + srv.stop(1); + } + } + + /** + * @throws Exception If failed. + */ + public void testDownloadUrlFromLocalFile() throws Exception { + File file = new File(System.getProperty("java.io.tmpdir") + File.separator + "url-http.file"); + + file = U.downloadUrl( + GridTestUtils.resolveGridGainPath("modules/core/src/test/config/tests.properties").toURI().toURL(), file); + + assert file.exists(); + assert file.delete(); + } + + /** + * @throws Exception If failed. + */ + public void testOs() throws Exception { + System.out.println("OS string: " + U.osString()); + System.out.println("JDK string: " + U.jdkString()); + System.out.println("OS/JDK string: " + U.osJdkString()); + + System.out.println("Is Windows: " + U.isWindows()); + System.out.println("Is Windows 95: " + U.isWindows95()); + System.out.println("Is Windows 98: " + U.isWindows98()); + System.out.println("Is Windows NT: " + U.isWindowsNt()); + System.out.println("Is Windows 2000: " + U.isWindows2k()); + System.out.println("Is Windows 2003: " + U.isWindows2003()); + System.out.println("Is Windows XP: " + U.isWindowsXp()); + System.out.println("Is Windows Vista: " + U.isWindowsVista()); + System.out.println("Is Linux: " + U.isLinux()); + System.out.println("Is Mac OS: " + U.isMacOs()); + System.out.println("Is Netware: " + U.isNetWare()); + System.out.println("Is Solaris: " + U.isSolaris()); + System.out.println("Is Solaris SPARC: " + U.isSolarisSparc()); + System.out.println("Is Solaris x86: " + U.isSolarisX86()); + System.out.println("Is Windows7: " + U.isWindows7()); + System.out.println("Is Sufficiently Tested OS: " + U.isSufficientlyTestedOs()); + } + + /** + * @throws Exception If failed. + */ + public void testJavaSerialization() throws Exception { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + ObjectOutputStream objOut = new ObjectOutputStream(byteOut); + + objOut.writeObject(new byte[] {1, 2, 3, 4, 5, 5}); + + objOut.flush(); + + byte[] sBytes = byteOut.toByteArray(); + + ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(sBytes)); + + in.readObject(); + } + + /** + * + */ + public void testHidePassword() { + Collection<String> uriList = new ArrayList<>(); + + uriList.add("ftp://anonymous:111111;freq=5...@unknown.host:21/pub/gg-test"); + uriList.add("ftp://anonymous:111111;freq=5000@localhost:21/pub/gg-test"); + + uriList.add("http://freq=5000@localhost/tasks"); + uriList.add("http://freq=5...@unknownhost.host/tasks"); + + for (String uri : uriList) + X.println(uri + " -> " + U.hidePassword(uri)); + } + + /** + * Test job to test possible indefinite recursion in detecting peer deploy aware. + */ + @SuppressWarnings({"UnusedDeclaration"}) + private class SelfReferencedJob extends ComputeJobAdapter implements GridPeerDeployAware { + /** */ + private SelfReferencedJob ref; + + /** */ + private SelfReferencedJob[] arr; + + /** */ + private Collection<SelfReferencedJob> col; + + /** */ + private ClusterNode node; + + /** */ + private ClusterGroup subGrid; + + /** + * @param ignite Grid. + */ + private SelfReferencedJob(Ignite ignite) { + node = ignite.cluster().localNode(); + + ref = this; + + arr = new SelfReferencedJob[] {this, this}; + + col = Arrays.asList(this, this, this); + + GridTestKernalContext ctx = newContext(); + + subGrid = ignite.cluster().forNodes(Collections.singleton(node)); + } + + /** {@inheritDoc} */ + @Override public Object execute() { + return null; + } + + /** {@inheritDoc} */ + @Override public Class<?> deployClass() { + return getClass(); + } + + /** {@inheritDoc} */ + @Override public ClassLoader classLoader() { + return getClass().getClassLoader(); + } + } + + /** + * @throws Exception If test fails. + */ + public void testDetectPeerDeployAwareInfiniteRecursion() throws Exception { + Ignite g = startGrid(1); + + try { + final SelfReferencedJob job = new SelfReferencedJob(g); + + GridPeerDeployAware d = U.detectPeerDeployAware(U.peerDeployAware(job)); + + assert d != null; + assert SelfReferencedJob.class == d.deployClass(); + assert d.classLoader() == SelfReferencedJob.class.getClassLoader(); + } + finally { + stopGrid(1); + } + } + + /** + * @param r Runnable. + * @return Job created for given runnable. + */ + private static ComputeJob job(final Runnable r) { + return new ComputeJobAdapter() { + @Nullable @Override public Object execute() { + r.run(); + + return null; + } + }; + } + + /** + * + * @throws Exception If failed. + */ + public void testParseIsoDate() throws Exception { + Calendar cal = U.parseIsoDate("2009-12-08T13:30:44.000Z"); + + assert cal.get(Calendar.YEAR) == 2009; + assert cal.get(Calendar.MONTH) == 11; + assert cal.get(Calendar.DAY_OF_MONTH) == 8; + assert cal.get(Calendar.HOUR_OF_DAY) == 13; + assert cal.get(Calendar.MINUTE) == 30; + assert cal.get(Calendar.SECOND) == 44; + assert cal.get(Calendar.MILLISECOND) == 0; + assert cal.get(Calendar.ZONE_OFFSET) == 0 : + "Unexpected value: " + cal.get(Calendar.ZONE_OFFSET); + + cal = U.parseIsoDate("2009-12-08T13:30:44.000+03:00"); + + assert cal.get(Calendar.YEAR) == 2009; + assert cal.get(Calendar.MONTH) == 11; + assert cal.get(Calendar.DAY_OF_MONTH) == 8; + assert cal.get(Calendar.HOUR_OF_DAY) == 13; + assert cal.get(Calendar.MINUTE) == 30; + assert cal.get(Calendar.SECOND) == 44; + assert cal.get(Calendar.MILLISECOND) == 0; + assert cal.get(Calendar.ZONE_OFFSET) == 3 * 60 * 60 * 1000 : + "Unexpected value: " + cal.get(Calendar.ZONE_OFFSET); + + cal = U.parseIsoDate("2009-12-08T13:30:44.000+0300"); + + assert cal.get(Calendar.YEAR) == 2009; + assert cal.get(Calendar.MONTH) == 11; + assert cal.get(Calendar.DAY_OF_MONTH) == 8; + assert cal.get(Calendar.HOUR_OF_DAY) == 13; + assert cal.get(Calendar.MINUTE) == 30; + assert cal.get(Calendar.SECOND) == 44; + assert cal.get(Calendar.MILLISECOND) == 0; + assert cal.get(Calendar.ZONE_OFFSET) == 3 * 60 * 60 * 1000 : + "Unexpected value: " + cal.get(Calendar.ZONE_OFFSET); + } + + /** + * @throws Exception If test failed. + */ + public void testPeerDeployAware0() throws Exception { + Collection<Object> col = new ArrayList<>(); + + col.add(null); + col.add(null); + col.add(null); + + GridPeerDeployAware pda = U.peerDeployAware0(col); + + assert pda != null; + + col.clear(); + + col.add(null); + + pda = U.peerDeployAware0(col); + + assert pda != null; + + col.clear(); + + pda = U.peerDeployAware0(col); + + assert pda != null; + + col.clear(); + + col.add(null); + col.add("Test"); + col.add(null); + + pda = U.peerDeployAware0(col); + + assert pda != null; + + col.clear(); + + col.add("Test"); + + pda = U.peerDeployAware0(col); + + assert pda != null; + + col.clear(); + + col.add("Test"); + col.add(this); + + pda = U.peerDeployAware0(col); + + assert pda != null; + + col.clear(); + + col.add(null); + col.add("Test"); + col.add(null); + col.add(this); + col.add(null); + + pda = U.peerDeployAware0(col); + + assert pda != null; + } + + /** + * Test UUID to bytes array conversion. + */ + public void testsGetBytes() { + for (int i = 0; i < 100; i++) { + UUID id = UUID.randomUUID(); + + byte[] bytes = IgniteUtils.uuidToBytes(id); + BigInteger n = new BigInteger(bytes); + + assert n.shiftRight(Long.SIZE).longValue() == id.getMostSignificantBits(); + assert n.longValue() == id.getLeastSignificantBits(); + } + } + + /** + * + */ + @SuppressWarnings("ZeroLengthArrayAllocation") + public void testReadByteArray() { + assertTrue(Arrays.equals(new byte[0], U.readByteArray(ByteBuffer.allocate(0)))); + assertTrue(Arrays.equals(new byte[0], U.readByteArray(ByteBuffer.allocate(0), ByteBuffer.allocate(0)))); + + Random rnd = new Random(); + + byte[] bytes = new byte[13]; + + rnd.nextBytes(bytes); + + assertTrue(Arrays.equals(bytes, U.readByteArray(ByteBuffer.wrap(bytes)))); + assertTrue(Arrays.equals(bytes, U.readByteArray(ByteBuffer.wrap(bytes), ByteBuffer.allocate(0)))); + assertTrue(Arrays.equals(bytes, U.readByteArray(ByteBuffer.allocate(0), ByteBuffer.wrap(bytes)))); + + for (int i = 0; i < 1000; i++) { + int n = rnd.nextInt(100); + + bytes = new byte[n]; + + rnd.nextBytes(bytes); + + ByteBuffer[] bufs = new ByteBuffer[1 + rnd.nextInt(10)]; + + int x = 0; + + for (int j = 0; j < bufs.length - 1; j++) { + int size = x == n ? 0 : rnd.nextInt(n - x); + + bufs[j] = (ByteBuffer)ByteBuffer.wrap(bytes).position(x).limit(x += size); + } + + bufs[bufs.length - 1] = (ByteBuffer)ByteBuffer.wrap(bytes).position(x).limit(n); + + assertTrue(Arrays.equals(bytes, U.readByteArray(bufs))); + } + } + + /** + * + */ + @SuppressWarnings("ZeroLengthArrayAllocation") + public void testHashCodeFromBuffers() { + assertEquals(Arrays.hashCode(new byte[0]), U.hashCode(ByteBuffer.allocate(0))); + assertEquals(Arrays.hashCode(new byte[0]), U.hashCode(ByteBuffer.allocate(0), ByteBuffer.allocate(0))); + + Random rnd = new Random(); + + for (int i = 0; i < 1000; i++) { + ByteBuffer[] bufs = new ByteBuffer[1 + rnd.nextInt(15)]; + + for (int j = 0; j < bufs.length; j++) { + byte[] bytes = new byte[rnd.nextInt(25)]; + + rnd.nextBytes(bytes); + + bufs[j] = ByteBuffer.wrap(bytes); + } + + assertEquals(U.hashCode(bufs), Arrays.hashCode(U.readByteArray(bufs))); + } + } + + /** + * Test annotation look up. + */ + public void testGetAnnotations() { + assert U.getAnnotation(A1.class, Ann1.class) != null; + assert U.getAnnotation(A2.class, Ann1.class) != null; + + assert U.getAnnotation(A1.class, Ann2.class) != null; + assert U.getAnnotation(A2.class, Ann2.class) != null; + + assert U.getAnnotation(A3.class, Ann1.class) == null; + assert U.getAnnotation(A3.class, Ann2.class) != null; + } + + /** + * + */ + public void testUnique() { + int[][][] arrays = new int[][][]{ + new int[][]{EMPTY, EMPTY, EMPTY}, + new int[][]{new int[]{1, 2, 3}, EMPTY, new int[]{1, 2, 3}}, + new int[][]{new int[]{1, 2, 3}, new int[]{1, 2, 3}, new int[]{1, 2, 3}}, + new int[][]{new int[]{1, 2, 3}, new int[]{1, 3}, new int[]{1, 2, 3}}, + new int[][]{new int[]{1, 2, 30, 40, 50}, new int[]{2, 40}, new int[]{1, 2, 30, 40, 50}}, + new int[][]{new int[]{-100, -13, 1, 2, 5, 30, 40, 50}, new int[]{1, 2, 6, 100, 113}, + new int[]{-100, -13, 1, 2, 5, 6, 30, 40, 50, 100, 113}} + }; + + for (int[][] a : arrays) { + assertArrayEquals(a[2], U.unique(a[0], a[0].length, a[1], a[1].length)); + + assertArrayEquals(a[2], U.unique(a[1], a[1].length, a[0], a[0].length)); + } + + assertArrayEquals(new int[]{1, 2, 3, 4}, U.unique(new int[]{1, 2, 3, 8}, 3, new int[]{2, 4, 5}, 2)); + assertArrayEquals(new int[]{2, 4}, U.unique(new int[]{1, 2, 3, 8}, 0, new int[]{2, 4, 5}, 2)); + assertArrayEquals(new int[]{1, 2, 4, 5}, U.unique(new int[]{1, 2, 3, 8}, 2, new int[]{2, 4, 5, 6}, 3)); + assertArrayEquals(new int[]{1, 2}, U.unique(new int[]{1, 2, 3, 8}, 2, new int[]{2, 4, 5, 6}, 0)); + } + + /** + * + */ + public void testDifference() { + int[][][] arrays = new int[][][]{ + new int[][]{EMPTY, EMPTY, EMPTY}, + new int[][]{new int[]{1, 2, 3}, EMPTY, new int[]{1, 2, 3}}, + new int[][]{EMPTY, new int[]{1, 2, 3}, EMPTY}, + new int[][]{new int[]{1, 2, 3}, new int[]{1, 2, 3}, EMPTY}, + new int[][]{new int[]{-100, -50, 1, 2, 3}, new int[]{-50, -1, 1, 3}, new int[]{-100, 2}}, + new int[][]{new int[]{-100, 1, 2, 30, 40, 50}, new int[]{2, 40}, new int[]{-100, 1, 30, 50}}, + new int[][]{new int[]{-1, 1, 2, 30, 40, 50}, new int[]{1, 2, 100, 113}, new int[]{-1, 30, 40, 50}} + }; + + for (int[][] a : arrays) + assertArrayEquals(a[2], U.difference(a[0], a[0].length, a[1], a[1].length)); + + assertArrayEquals(new int[]{1, 2}, U.difference(new int[]{1, 2, 30, 40, 50}, 3, new int[]{30, 40}, 2)); + assertArrayEquals(EMPTY, U.difference(new int[]{1, 2, 30, 40, 50}, 0, new int[]{30, 40}, 2)); + assertArrayEquals(new int[]{1, 2, 40}, U.difference(new int[]{1, 2, 30, 40, 50}, 4, new int[]{30, 40}, 1)); + assertArrayEquals(new int[]{1, 2, 30, 40}, U.difference(new int[]{1, 2, 30, 40, 50}, 4, new int[]{30, 40}, 0)); + } + + /** + * + */ + public void testCopyIfExceeded() { + int[][] arrays = new int[][]{new int[]{13, 14, 17, 11}, new int[]{13}, EMPTY}; + + for (int[] a : arrays) { + int[] b = Arrays.copyOf(a, a.length); + + assertEquals(a, U.copyIfExceeded(a, a.length)); + assertArrayEquals(b, U.copyIfExceeded(a, a.length)); + + for (int j = 0; j < a.length - 1; j++) + assertArrayEquals(Arrays.copyOf(b, j), U.copyIfExceeded(a, j)); + } + } + + /** + * + */ + public void testIsIncreasingArray() { + assertTrue(U.isIncreasingArray(EMPTY, 0)); + assertTrue(U.isIncreasingArray(new int[]{Integer.MIN_VALUE, -10, 1, 13, Integer.MAX_VALUE}, 5)); + assertTrue(U.isIncreasingArray(new int[]{1, 2, 3, -1, 5}, 0)); + assertTrue(U.isIncreasingArray(new int[]{1, 2, 3, -1, 5}, 3)); + assertFalse(U.isIncreasingArray(new int[]{1, 2, 3, -1, 5}, 4)); + assertFalse(U.isIncreasingArray(new int[]{1, 2, 3, -1, 5}, 5)); + assertFalse(U.isIncreasingArray(new int[]{1, 2, 3, 3, 5}, 4)); + assertTrue(U.isIncreasingArray(new int[]{1, -1}, 1)); + assertFalse(U.isIncreasingArray(new int[]{1, -1}, 2)); + assertTrue(U.isIncreasingArray(new int[]{13, 13, 13}, 1)); + assertFalse(U.isIncreasingArray(new int[]{13, 13, 13}, 2)); + assertFalse(U.isIncreasingArray(new int[]{13, 13, 13}, 3)); + } + + /** + * + */ + public void testIsNonDecreasingArray() { + assertTrue(U.isNonDecreasingArray(EMPTY, 0)); + assertTrue(U.isNonDecreasingArray(new int[]{Integer.MIN_VALUE, -10, 1, 13, Integer.MAX_VALUE}, 5)); + assertTrue(U.isNonDecreasingArray(new int[]{1, 2, 3, -1, 5}, 0)); + assertTrue(U.isNonDecreasingArray(new int[]{1, 2, 3, -1, 5}, 3)); + assertFalse(U.isNonDecreasingArray(new int[]{1, 2, 3, -1, 5}, 4)); + assertFalse(U.isNonDecreasingArray(new int[]{1, 2, 3, -1, 5}, 5)); + assertTrue(U.isNonDecreasingArray(new int[]{1, 2, 3, 3, 5}, 4)); + assertTrue(U.isNonDecreasingArray(new int[]{1, -1}, 1)); + assertFalse(U.isNonDecreasingArray(new int[]{1, -1}, 2)); + assertTrue(U.isNonDecreasingArray(new int[]{13, 13, 13}, 1)); + assertTrue(U.isNonDecreasingArray(new int[]{13, 13, 13}, 2)); + assertTrue(U.isNonDecreasingArray(new int[]{13, 13, 13}, 3)); + } + + /** + * Test InetAddress Comparator. + */ + public void testInetAddressesComparator() { + List<InetSocketAddress> ips = new ArrayList<InetSocketAddress>() { + { + add(new InetSocketAddress("127.0.0.1", 1)); + add(new InetSocketAddress("10.0.0.1", 1)); + add(new InetSocketAddress("172.16.0.1", 1)); + add(new InetSocketAddress("192.168.0.1", 1)); + add(new InetSocketAddress("100.0.0.1", 1)); + add(new InetSocketAddress("XXX", 1)); + } + }; + + Collections.sort(ips, U.inetAddressesComparator(true)); + + assertTrue(ips.get(0).getAddress().isLoopbackAddress()); + assertTrue(ips.get(ips.size() - 1).isUnresolved()); + + Collections.sort(ips, U.inetAddressesComparator(false)); + + assertTrue(ips.get(ips.size() - 2).getAddress().isLoopbackAddress()); + assertTrue(ips.get(ips.size() - 1).isUnresolved()); + } + + + public void testMD5Calculation() throws Exception { + String md5 = IgniteUtils.calculateMD5(new ByteArrayInputStream("Corrupted information.".getBytes())); + + assertEquals("d7dbe555be2eee7fa658299850169fa1", md5); + } + + /** + * Test enum. + */ + private enum TestEnum { + E1, + E2, + E3 + } + + @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) + private @interface Ann1 {} + + @Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.TYPE) + private @interface Ann2 {} + + private static class A1 implements I3, I5 {} + private static class A2 extends A1 {} + private static class A3 implements I5 {} + + @Ann1 private interface I1 {} + private interface I2 extends I1 {} + private interface I3 extends I2 {} + @Ann2 private interface I4 {} + private interface I5 extends I4 {} +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/lang/GridSetWrapperSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/lang/GridSetWrapperSelfTest.java b/modules/core/src/test/java/org/apache/ignite/lang/GridSetWrapperSelfTest.java index c0c0d66..07a78ea 100644 --- a/modules/core/src/test/java/org/apache/ignite/lang/GridSetWrapperSelfTest.java +++ b/modules/core/src/test/java/org/apache/ignite/lang/GridSetWrapperSelfTest.java @@ -120,7 +120,7 @@ public class GridSetWrapperSelfTest extends GridCommonAbstractTest { set.add("v4"); set.add("v5"); - set.removeAll(GridUtils.addAll(new HashSet<String>(), "v2", "v4", "v5")); + set.removeAll(IgniteUtils.addAll(new HashSet<String>(), "v2", "v4", "v5")); assertEquals(2, set.size()); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java index 87d38b7..6564b6f 100644 --- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java +++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteUtilSelfTestSuite.java @@ -42,7 +42,7 @@ public class IgniteUtilSelfTestSuite extends TestSuite { TestSuite suite = new TestSuite("Ignite Util Test Suite"); suite.addTestSuite(GridThreadPoolExecutorServiceSelfTest.class); - suite.addTestSuite(GridUtilsSelfTest.class); + suite.addTestSuite(IgniteUtilsSelfTest.class); suite.addTestSuite(GridSpinReadWriteLockSelfTest.class); suite.addTestSuite(GridQueueSelfTest.class); suite.addTestSuite(GridStringBuilderFactorySelfTest.class); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala index 4f74794..d983025 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/VisorConsole.scala @@ -18,7 +18,7 @@ package org.apache.ignite.visor.commands import org.apache.ignite.internal.GridProductImpl -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import org.apache.ignite.internal.util.typedef.internal.U import org.apache.ignite.internal.util.scala.impl @@ -94,7 +94,7 @@ object VisorConsole extends App { customizeUI() // Wrap line symbol for user input. - private val wrapLine = if (GridUtils.isWindows) "^" else "\\" + private val wrapLine = if (IgniteUtils.isWindows) "^" else "\\" private val emptyArg = "^([a-zA-z!?]+)$".r private val varArg = "^([a-zA-z!?]+)\\s+(.+)$".r @@ -270,7 +270,7 @@ private[commands] class VisorFileNameCompleter extends Completer { case emptyStr if emptyStr.trim == "" => "" case str => // replace wrong '/' on windows. - val translated = if (GridUtils.isWindows) str.replace('/', '\\') else str + val translated = if (IgniteUtils.isWindows) str.replace('/', '\\') else str // line before cursor. val left = translated.substring(0, cursor) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala index 73c6e83..1899ca4 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/alert/VisorAlertCommand.scala @@ -17,7 +17,7 @@ package org.apache.ignite.visor.commands.alert -import org.apache.ignite.internal.util.{GridUtils => U} +import org.apache.ignite.internal.util.{IgniteUtils => U} import org.apache.ignite.internal.util.lang.{GridFunc => F} import org.apache.ignite._ @@ -278,7 +278,7 @@ class VisorAlertCommand { // Grid-wide metrics (not node specific). case "cc" if v != null => gf = makeGridFilter(v, gf, grid.metrics().getTotalCpus) case "nc" if v != null => gf = makeGridFilter(v, gf, grid.nodes().size) - case "hc" if v != null => gf = makeGridFilter(v, gf, U.neighborhood(grid.nodes()).size) + case "hc" if v != null => gf = makeGridFilter(v, gf, IgniteUtils.neighborhood(grid.nodes()).size) case "cl" if v != null => gf = makeGridFilter(v, gf, () => (grid.metrics().getAverageCpuLoad * 100).toLong) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala index 2221e6b..4df0c35 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/config/VisorConfigurationCommand.scala @@ -17,7 +17,7 @@ package org.apache.ignite.visor.commands.config -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import org.apache.ignite.internal.visor.node.VisorNodeConfigurationCollectorTask import org.apache.ignite._ @@ -104,7 +104,7 @@ class VisorConfigurationCommand { * @return String. */ private def arr2Str[T: ClassTag](arr: Array[T]): String = { - if (arr != null && arr.length > 0) GridUtils.compact(arr.mkString(", ")) else DFLT + if (arr != null && arr.length > 0) IgniteUtils.compact(arr.mkString(", ")) else DFLT } /** @@ -352,7 +352,7 @@ class VisorConfigurationCommand { val evtsT = VisorTextTable() - val inclEvtTypes = Option(cfg.includeEventTypes()).fold(DFLT)(et => arr2Str(et.map(GridUtils.gridEventName))) + val inclEvtTypes = Option(cfg.includeEventTypes()).fold(DFLT)(et => arr2Str(et.map(IgniteUtils.gridEventName))) evtsT += ("Included event types", inclEvtTypes) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommand.scala index 4f189f2..08456d7 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/deploy/VisorDeployCommand.scala @@ -17,7 +17,7 @@ package org.apache.ignite.visor.commands.deploy -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import org.apache.ignite.internal.util.io.GridFilenameUtils import org.apache.ignite.internal.util.typedef.X @@ -184,7 +184,7 @@ private case class VisorCopier( ch.connect() // Added to skip login message. - GridUtils.sleep(1000) + IgniteUtils.sleep(1000) val writer = new PrintStream(ch.getOutputStream, true) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala index 3f9dea0..fc0f35d 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/disco/VisorDiscoveryCommand.scala @@ -17,7 +17,7 @@ package org.apache.ignite.visor.commands.disco -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import org.apache.ignite.internal.util.typedef.internal.U import org.apache.ignite.internal.visor.event.VisorGridDiscoveryEvent import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask @@ -226,7 +226,7 @@ class VisorDiscoveryCommand { val nodeStartTime = node.metrics().getStartTime if (nodeStartTime > System.currentTimeMillis() - tmFrame) { - val root = new VisorGridDiscoveryEvent(EVT_NODE_JOINED, null, GridUtils.gridEventName(EVT_NODE_JOINED), + val root = new VisorGridDiscoveryEvent(EVT_NODE_JOINED, null, IgniteUtils.gridEventName(EVT_NODE_JOINED), node.id(), nodeStartTime, "", "", node.id, node.addresses().head, node.isDaemon) evts = Seq(root) ++ evts http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala index 24b9b94..79a98e5 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/events/VisorEventsCommand.scala @@ -17,7 +17,7 @@ package org.apache.ignite.visor.commands.events -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import org.apache.ignite.internal.util.typedef.internal.U import org.apache.ignite.internal.visor.event.VisorGridEvent import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask @@ -395,7 +395,7 @@ class VisorEventsCommand { all #= ("Timestamp", "Description") sorted.take(cnt).foreach(evt => - all += (formatDateTime(evt.timestamp()), GridUtils.compact(evt.shortDisplay)) + all += (formatDateTime(evt.timestamp()), IgniteUtils.compact(evt.shortDisplay)) ) all.render() http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala index 8083ce9..475f916 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/node/VisorNodeCommand.scala @@ -18,7 +18,7 @@ package org.apache.ignite.visor.commands.node import org.apache.ignite.internal.GridNodeAttributes -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import org.apache.ignite.internal.util.typedef.internal.U import GridNodeAttributes._ import org.apache.ignite.internal.util.lang.{GridFunc => F} @@ -175,7 +175,7 @@ class VisorNodeCommand { val gridName: String = node.attribute(ATTR_GRID_NAME) - val ver = GridUtils.productVersion(node) + val ver = IgniteUtils.productVersion(node) val verStr = ver.major() + "." + ver.minor() + "." + ver.maintenance() + (if (F.isEmpty(ver.stage())) "" else "-" + ver.stage()) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala index 7f4ab1f..e91dd26 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/start/VisorStartCommand.scala @@ -22,7 +22,7 @@ import org.apache.ignite._ import java.io._ import java.util.concurrent._ -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import org.apache.ignite.internal.util.typedef.internal.U import org.apache.ignite.visor.VisorTag import org.apache.ignite.visor.commands.{VisorConsoleCommand, VisorTextTable} @@ -311,7 +311,7 @@ class VisorStartCommand { errT #= ("Host", "Error") - res.filter(!_.ok) foreach (r => { errT += (r.host, r.errMsg.replace("\t", " ").split(GridUtils.nl()).toSeq) }) + res.filter(!_.ok) foreach (r => { errT += (r.host, r.errMsg.replace("\t", " ").split(IgniteUtils.nl()).toSeq) }) errT.render() } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala index be1b9f1..3486b95 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/tasks/VisorTasksCommand.scala @@ -17,7 +17,7 @@ package org.apache.ignite.visor.commands.tasks -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import org.apache.ignite.internal.util.typedef.internal.U import org.apache.ignite.internal.visor.event.{VisorGridEvent, VisorGridJobEvent, VisorGridTaskEvent} import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask @@ -76,7 +76,7 @@ private case class VisorExecution( * ID8 form of task execution ID. */ lazy val id8: String = - GridUtils.id8(id) + IgniteUtils.id8(id) /** * ID8 of the task execution + its associated variable. http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala index 7648ea1..9f6b637 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/top/VisorTopologyCommand.scala @@ -18,7 +18,7 @@ package org.apache.ignite.visor.commands.top import org.apache.ignite.internal.GridNodeAttributes -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import GridNodeAttributes._ import org.apache.ignite.internal.util.typedef._ @@ -275,7 +275,7 @@ class VisorTopologyCommand { nl() } - val neighborhood = GridUtils.neighborhood(nodes) + val neighborhood = IgniteUtils.neighborhood(nodes) val hostsT = VisorTextTable() @@ -336,7 +336,7 @@ class VisorTopologyCommand { val sumT = VisorTextTable() - sumT += ("Total hosts", GridUtils.neighborhood(grid.nodes()).size) + sumT += ("Total hosts", IgniteUtils.neighborhood(grid.nodes()).size) sumT += ("Total nodes", grid.nodes().size) sumT += ("Total CPUs", m.getTotalCpus) sumT += ("Avg. CPU load", safePercent(m.getAverageCpuLoad * 100)) http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala index 733cfee..a36762a 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/commands/vvm/VisorVvmCommand.scala @@ -18,7 +18,7 @@ package org.apache.ignite.visor.commands.vvm import org.apache.ignite.internal.GridNodeAttributes -import org.apache.ignite.internal.util.GridUtils +import org.apache.ignite.internal.util.IgniteUtils import org.apache.ignite.internal.util.typedef.internal.U import GridNodeAttributes._ import org.apache.ignite.internal.visor.util.{VisorTaskUtils => TU} @@ -120,7 +120,7 @@ class VisorVvmCommand { var vvmCmd: String = null - val ext = if (GridUtils.isWindows) ".exe" else "" + val ext = if (IgniteUtils.isWindows) ".exe" else "" val fs = File.separator @@ -195,7 +195,7 @@ class VisorVvmCommand { val neighbors = grid.forHost(grid.localNode).nodes() - if (GridUtils.isWindows) + if (IgniteUtils.isWindows) vvmCmd = "cmd /c \"%s\"".format(vvmCmd) for (node <- nodes if !neighbors.contains(node)) { @@ -236,7 +236,7 @@ class VisorVvmCommand { * @param vvmCmd VisualVM command. */ private def vvmCommandArray(vvmCmd: String): Array[String] = { - if (GridUtils.isWindows) Array("cmd", "/c", vvmCmd) else Array(vvmCmd) + if (IgniteUtils.isWindows) Array("cmd", "/c", vvmCmd) else Array(vvmCmd) } /** http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/fc768b83/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala ---------------------------------------------------------------------- diff --git a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala index cb7ce1b..764a347 100644 --- a/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala +++ b/modules/visor-console/src/main/scala/org/apache/ignite/visor/visor.scala @@ -33,7 +33,7 @@ import org.apache.ignite.internal.GridNodeAttributes._ import org.apache.ignite.internal.processors.spring.IgniteSpringProcessor import org.apache.ignite.internal.util.lang.{GridFunc => F} import org.apache.ignite.internal.util.typedef._ -import org.apache.ignite.internal.util.{GridConfigurationFinder, GridUtils} +import org.apache.ignite.internal.util.{GridConfigurationFinder, IgniteUtils} import org.apache.ignite.internal.visor.VisorTaskArgument import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask import org.apache.ignite.internal.visor.node.VisorNodeEventsCollectorTask.VisorNodeEventsCollectorTaskArg @@ -1475,7 +1475,7 @@ object visor extends VisorTag { new URL(path) catch { case e: Exception => - val url = GridUtils.resolveGridGainUrl(path) + val url = IgniteUtils.resolveGridGainUrl(path) if (url == null) throw new IgniteCheckedException("GridGain configuration path is invalid: " + path, e) @@ -1486,7 +1486,7 @@ object visor extends VisorTag { // Add no-op logger to remove no-appender warning. val log4jTup = if (classOf[Ignition].getClassLoader.getResource("org/apache/log4j/Appender.class") != null) - GridUtils.addLog4jNoOpLogger() + IgniteUtils.addLog4jNoOpLogger() else null @@ -1499,7 +1499,7 @@ object visor extends VisorTag { "drSenderHubConfiguration", "drReceiverHubConfiguration").get1() finally { if (log4jTup != null) - GridUtils.removeLog4jNoOpLogger(log4jTup) + IgniteUtils.removeLog4jNoOpLogger(log4jTup) } if (cfgs == null || cfgs.isEmpty) @@ -1903,7 +1903,7 @@ object visor extends VisorTag { t #= ("#", "Int./Ext. IPs", "Node ID8(@)", "OS", "CPUs", "MACs", "CPU Load") - val neighborhood = GridUtils.neighborhood(grid.nodes()).values().toIndexedSeq + val neighborhood = IgniteUtils.neighborhood(grid.nodes()).values().toIndexedSeq if (neighborhood.isEmpty) { warn("Topology is empty.") @@ -2355,7 +2355,7 @@ object visor extends VisorTag { val folder = Option(f.getParent).getOrElse("") val fileName = f.getName - logFile = new File(GridUtils.resolveWorkDirectory(folder, false), fileName) + logFile = new File(IgniteUtils.resolveWorkDirectory(folder, false), fileName) logFile.createNewFile() @@ -2449,7 +2449,7 @@ object visor extends VisorTag { out, formatDateTime(e.timestamp), nodeId8Addr(e.nid()), - GridUtils.compact(e.shortDisplay()) + IgniteUtils.compact(e.shortDisplay()) ) if (EVTS_DISCOVERY.contains(e.typeId())) @@ -2457,7 +2457,7 @@ object visor extends VisorTag { }) } finally { - GridUtils.close(out, null) + IgniteUtils.close(out, null) } } } @@ -2522,7 +2522,7 @@ object visor extends VisorTag { } logText("H/N/C" + pipe + - GridUtils.neighborhood(grid.nodes()).size.toString.padTo(4, ' ') + pipe + + IgniteUtils.neighborhood(grid.nodes()).size.toString.padTo(4, ' ') + pipe + grid.nodes().size().toString.padTo(4, ' ') + pipe + m.getTotalCpus.toString.padTo(4, ' ') + pipe + bar(m.getAverageCpuLoad, m.getHeapMemoryUsed / m.getHeapMemoryMaximum) + pipe @@ -2554,7 +2554,7 @@ object visor extends VisorTag { case e: IOException => () } finally { - GridUtils.close(out, null) + IgniteUtils.close(out, null) } } }