http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToValueTargetInterface.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToValueTargetInterface.java b/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToValueTargetInterface.java deleted file mode 100644 index a25442e..0000000 --- a/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToValueTargetInterface.java +++ /dev/null @@ -1,100 +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.gridgain.grid.gridify; - -import org.apache.ignite.compute.gridify.*; - -import java.util.*; - -/** - * Test set-to-value target interface. - */ -public interface GridifySetToValueTargetInterface { - /** - * Find maximum value in collection. - * - * @param input Input collection. - * @return Maximum value. - */ - @GridifySetToValue(gridName = "GridifySetToValueTarget", threshold = 2, splitSize = 2) - public Long findMaximum(Collection<Long> input); - - /** - * Find maximum value in collection. - * - * @param input Input collection. - * @return Maximum value. - */ - @GridifySetToValue(gridName = "GridifySetToValueTarget") - public Long findMaximumInList(List<Long> input); - - /** - * Find maximum value in collection. - * - * @param input Input collection. - * @return Maximum value. - */ - @GridifySetToValue(gridName = "GridifySetToValueTarget", threshold = 2) - public Long findMaximumWithoutSplitSize(Collection<Long> input); - - /** - * Find maximum value in collection. - * - * @param input Input collection. - * @return Maximum value. - */ - @GridifySetToValue(gridName = "GridifySetToValueTarget") - public Long findMaximumWithoutSplitSizeAndThreshold(Collection<Long> input); - - /** - * Find maximum in array. - * - * @param input Input array. - * @return Maximum value. - */ - @GridifySetToValue(gridName = "GridifySetToValueTarget", threshold = 2, splitSize = 2) - public Long findPrimesInArray(Long[] input); - - /** - * Find maximum in primitive array. - * - * @param input Input array. - * @return Maximum value. - */ - @GridifySetToValue(gridName = "GridifySetToValueTarget", threshold = 2, splitSize = 2) - public long findMaximumInPrimitiveArray(long[] input); - - /** - * Find maximum value in Iterator. - * - * @param input Input collection. - * @return Maximum value. - */ - @GridifySetToValue(gridName = "GridifySetToValueTarget", threshold = 2, splitSize = 2) - public long findMaximumInIterator(Iterator<Long> input); - - - /** - * Find maximum value in Enumeration. - * - * @param input Input collection. - * @return Maximum value. - */ - @GridifySetToValue(gridName = "GridifySetToValueTarget", threshold = 2, splitSize = 2) - public long findMaximumInEnumeration(Enumeration<Long> input); -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToXXXNonSpringAopSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToXXXNonSpringAopSelfTest.java b/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToXXXNonSpringAopSelfTest.java deleted file mode 100644 index e1f9205..0000000 --- a/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToXXXNonSpringAopSelfTest.java +++ /dev/null @@ -1,203 +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.gridgain.grid.gridify; - -import org.gridgain.testframework.junits.common.*; -import java.util.*; - -/** - * To run this test with JBoss AOP make sure of the following: - * - * 1. The JVM is started with following parameters to enable jboss online weaving - * (replace ${GRIDGAIN_HOME} to you $GRIDGAIN_HOME): - * -javaagent:${GRIDGAIN_HOME}libs/jboss-aop-jdk50-4.0.4.jar - * -Djboss.aop.class.path=[path to grid compiled classes (Idea out folder) or path to gridgain.jar] - * -Djboss.aop.exclude=org,com -Djboss.aop.include=org.gridgain - * - * 2. The following jars should be in a classpath: - * ${GRIDGAIN_HOME}libs/javassist-3.x.x.jar - * ${GRIDGAIN_HOME}libs/jboss-aop-jdk50-4.0.4.jar - * ${GRIDGAIN_HOME}libs/jboss-aspect-library-jdk50-4.0.4.jar - * ${GRIDGAIN_HOME}libs/jboss-common-4.2.2.jar - * ${GRIDGAIN_HOME}libs/trove-1.0.2.jar - * - * To run this test with AspectJ APO make sure of the following: - * - * 1. The JVM is started with following parameters for enable AspectJ online weaving - * (replace ${GRIDGAIN_HOME} to you $GRIDGAIN_HOME): - * -javaagent:${GRIDGAIN_HOME}/libs/aspectjweaver-1.7.2.jar - * - * 2. Classpath should contains the ${GRIDGAIN_HOME}/modules/tests/config/aop/aspectj folder. - */ -@GridCommonTest(group="AOP") -public class GridifySetToXXXNonSpringAopSelfTest extends GridCommonAbstractTest { - /** - * @throws Exception If failed. - */ - public void testGridifySetToSet() throws Exception { - try { - startGrid("GridifySetToSetTarget"); - startGrid("GridifySetToSetTarget2"); - startGrid("GridifySetToSetTarget3"); - - GridifySetToSetTarget target = new GridifySetToSetTarget(); - - Collection<Long> primesInSet = target.findPrimes(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Prime numbers in set '" + primesInSet + "'."); - - primesInSet = target.findPrimesWithoutSplitSize(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Prime numbers w/o splitsize in set '" + primesInSet + "'."); - - primesInSet = target.findPrimesWithoutSplitSizeAndThreshold(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Prime numbers w/o splitsize and threshold in set '" + primesInSet + "'."); - - primesInSet = target.findPrimesInListWithoutSplitSizeAndThreshold(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Prime numbers in list w/o splitsize and threshold in set '" + primesInSet + "'."); - - primesInSet = target.findPrimesInArrayListWithoutSplitSizeAndThreshold( - new ArrayList<>(Arrays.asList(2L, 3L, 4L, 6L))); - - info(">>> Prime numbers in arraylist w/o splitsize and threshold in set '" + primesInSet + "'."); - - Long[] primesInArr = target.findPrimesInArray(new Long[]{2L, 3L, 4L, 6L}); - - info(">>> Prime numbers in array '" + Arrays.asList(primesInArr) + "'."); - - long[] primesInPrimArr = target.findPrimesInPrimitiveArray(new long[]{2L, 3L, 4L, 6L}); - - info(">>> Prime numbers in primitive array '" + primesInPrimArr + "'."); - - Iterator<Long> primesInIter = target.findPrimesWithIterator(Arrays.asList(2L, 3L, 4L, 6L).iterator()); - - info(">>> Prime numbers in iterator '" + convert(primesInIter) + "'."); - - Enumeration<Long> primesInEnum = target.findPrimesWithEnumeration( - new MathEnumerationAdapter<>(Arrays.asList(2L, 3L, 4L, 6L))); - - info(">>> Prime numbers in enumeration '" + convert(primesInEnum) + "'."); - } - finally { - stopGrid("GridifySetToSetTarget"); - stopGrid("GridifySetToSetTarget2"); - stopGrid("GridifySetToSetTarget3"); - } - } - - /** - * @throws Exception If failed. - */ - public void testGridifySetToValue() throws Exception { - try { - startGrid("GridifySetToValueTarget"); - startGrid("GridifySetToValueTarget2"); - startGrid("GridifySetToValueTarget3"); - - GridifySetToValueTarget target = new GridifySetToValueTarget(); - - Long max = target.findMaximum(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Maximum in collection '" + max + "'."); - - max = target.findMaximumInList(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Maximum in list '" + max + "'."); - - max = target.findMaximumWithoutSplitSize(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Maximum w/o splitsize in collection '" + max + "'."); - - max = target.findMaximumWithoutSplitSizeAndThreshold(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Maximum w/o splitsize and threshold in collection '" + max + "'."); - - max = target.findMaximumInIterator(Arrays.asList(2L, 3L, 4L, 6L).iterator()); - - info(">>> Maximum in iterator '" + max + "'."); - - max = target.findMaximumInEnumeration(new MathEnumerationAdapter<>(Arrays.asList(2L, 3L, 4L, 6L))); - - info(">>> Maximum in enumeration '" + max + "'."); - } - finally { - stopGrid("GridifySetToValueTarget"); - stopGrid("GridifySetToValueTarget2"); - stopGrid("GridifySetToValueTarget3"); - } - } - - /** - * Convert data to collection. - * - * @param iter Iterator. - * @return Collection. - */ - private <T> Collection<T> convert(Iterator<T> iter) { - List<T> list = new ArrayList<>(); - - while (iter.hasNext()) - list.add(iter.next()); - - return list; - } - - /** - * Convert data to collection. - * - * @param iter Iterator. - * @return Collection. - */ - private <T> Collection<T> convert(Enumeration<T> iter) { - List<T> list = new ArrayList<>(); - - while (iter.hasMoreElements()) - list.add(iter.nextElement()); - - return list; - } - - /** - * Enumeration adapter. - */ - private static class MathEnumerationAdapter<T> implements Enumeration<T> { - /** */ - private Iterator<T> iter; - - /** - * Creates Enumeration. - * - * @param col Input collection. - */ - MathEnumerationAdapter(Collection<T> col) { - iter = col.iterator(); - } - - /** {@inheritDoc} */ - @Override public boolean hasMoreElements() { - return iter.hasNext(); - } - - /** {@inheritDoc} */ - @Override public T nextElement() { - return iter.next(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToXXXSpringAopSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToXXXSpringAopSelfTest.java b/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToXXXSpringAopSelfTest.java deleted file mode 100644 index 07dc000..0000000 --- a/modules/aop/src/test/java/org/gridgain/grid/gridify/GridifySetToXXXSpringAopSelfTest.java +++ /dev/null @@ -1,204 +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.gridgain.grid.gridify; - -import org.gridgain.grid.compute.gridify.aop.spring.*; -import org.gridgain.testframework.junits.common.*; -import java.util.*; - -/** - * To run this test with JBoss AOP make sure of the following: - * - * 1. The JVM is started with following parameters to enable jboss online weaving - * (replace ${GRIDGAIN_HOME} to you $GRIDGAIN_HOME): - * -javaagent:${GRIDGAIN_HOME}libs/jboss-aop-jdk50-4.0.4.jar - * -Djboss.aop.class.path=[path to grid compiled classes (Idea out folder) or path to gridgain.jar] - * -Djboss.aop.exclude=org,com -Djboss.aop.include=org.gridgain - * - * 2. The following jars should be in a classpath: - * ${GRIDGAIN_HOME}libs/javassist-3.x.x.jar - * ${GRIDGAIN_HOME}libs/jboss-aop-jdk50-4.0.4.jar - * ${GRIDGAIN_HOME}libs/jboss-aspect-library-jdk50-4.0.4.jar - * ${GRIDGAIN_HOME}libs/jboss-common-4.2.2.jar - * ${GRIDGAIN_HOME}libs/trove-1.0.2.jar - * - * To run this test with AspectJ APO make sure of the following: - * - * 1. The JVM is started with following parameters for enable AspectJ online weaving - * (replace ${GRIDGAIN_HOME} to you $GRIDGAIN_HOME): - * -javaagent:${GRIDGAIN_HOME}/libs/aspectjweaver-1.7.2.jar - * - * 2. Classpath should contains the ${GRIDGAIN_HOME}/modules/tests/config/aop/aspectj folder. - */ -@GridCommonTest(group="AOP") -public class GridifySetToXXXSpringAopSelfTest extends GridCommonAbstractTest { - /** - * @throws Exception If failed. - */ - public void testGridifySetToSet() throws Exception { - try { - startGrid("GridifySetToSetTarget"); - startGrid("GridifySetToSetTarget2"); - startGrid("GridifySetToSetTarget3"); - - GridifySetToSetTargetInterface target = GridifySpringEnhancer.enhance(new GridifySetToSetTarget()); - - Collection<Long> primesInSet = target.findPrimes(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Prime numbers in set '" + primesInSet + "'."); - - primesInSet = target.findPrimesWithoutSplitSize(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Prime numbers w/o 'splitsize' in set '" + primesInSet + "'."); - - primesInSet = target.findPrimesWithoutSplitSizeAndThreshold(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Prime numbers w/o 'splitsize' and 'threshold' in set '" + primesInSet + "'."); - - primesInSet = target.findPrimesInListWithoutSplitSizeAndThreshold(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Prime numbers in list w/o 'splitsize' and 'threshold' in set '" + primesInSet + "'."); - - primesInSet = target.findPrimesInArrayListWithoutSplitSizeAndThreshold( - new ArrayList<>(Arrays.asList(2L, 3L, 4L, 6L))); - - info(">>> Prime numbers in 'arraylist' w/o 'splitsize' and threshold in set '" + primesInSet + "'."); - - Long[] primesInArr = target.findPrimesInArray(new Long[]{2L, 3L, 4L, 6L}); - - info(">>> Prime numbers in array '" + Arrays.asList(primesInArr) + "'."); - - long[] primesInPrimArr = target.findPrimesInPrimitiveArray(new long[]{2L, 3L, 4L, 6L}); - - info(">>> Prime numbers in primitive array '" + primesInPrimArr + "'."); - - Iterator<Long> primesInIter = target.findPrimesWithIterator(Arrays.asList(2L, 3L, 4L, 6L).iterator()); - - info(">>> Prime numbers in iterator '" + convert(primesInIter) + "'."); - - Enumeration<Long> primesInEnum = target.findPrimesWithEnumeration( - new MathEnumerationAdapter<>(Arrays.asList(2L, 3L, 4L, 6L))); - - info(">>> Prime numbers in enumeration '" + convert(primesInEnum) + "'."); - } - finally { - stopGrid("GridifySetToSetTarget"); - stopGrid("GridifySetToSetTarget2"); - stopGrid("GridifySetToSetTarget3"); - } - } - - /** - * @throws Exception If failed. - */ - public void testGridifySetToValue() throws Exception { - try { - startGrid("GridifySetToValueTarget"); - startGrid("GridifySetToValueTarget2"); - startGrid("GridifySetToValueTarget3"); - - GridifySetToValueTargetInterface target = GridifySpringEnhancer.enhance(new GridifySetToValueTarget()); - - Long max = target.findMaximum(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Maximum in collection '" + max + "'."); - - max = target.findMaximumInList(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Maximum in list '" + max + "'."); - - max = target.findMaximumWithoutSplitSize(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Maximum w/o splitsize in collection '" + max + "'."); - - max = target.findMaximumWithoutSplitSizeAndThreshold(Arrays.asList(2L, 3L, 4L, 6L)); - - info(">>> Maximum w/o splitsize and threshold in collection '" + max + "'."); - - max = target.findMaximumInIterator(Arrays.asList(2L, 3L, 4L, 6L).iterator()); - - info(">>> Maximum in iterator '" + max + "'."); - - max = target.findMaximumInEnumeration(new MathEnumerationAdapter<>(Arrays.asList(2L, 3L, 4L, 6L))); - - info(">>> Maximum in enumeration '" + max + "'."); - } - finally { - stopGrid("GridifySetToValueTarget"); - stopGrid("GridifySetToValueTarget2"); - stopGrid("GridifySetToValueTarget3"); - } - } - - /** - * Convert data to collection. - * - * @param iter Iterator. - * @return Collection. - */ - private <T> Collection<T> convert(Iterator<T> iter) { - List<T> list = new ArrayList<>(); - - while (iter.hasNext()) - list.add(iter.next()); - - return list; - } - - /** - * Convert data to collection. - * - * @param iter Iterator. - * @return Collection. - */ - private <T> Collection<T> convert(Enumeration<T> iter) { - List<T> list = new ArrayList<>(); - - while (iter.hasMoreElements()) - list.add(iter.nextElement()); - - return list; - } - - /** - * Enumeration adapter. - */ - private static class MathEnumerationAdapter<T> implements Enumeration<T> { - /** */ - private Iterator<T> iter; - - /** - * Creates Enumeration. - * - * @param col Input collection. - */ - MathEnumerationAdapter(Collection<T> col) { - iter = col.iterator(); - } - - /** {@inheritDoc} */ - @Override public boolean hasMoreElements() { - return iter.hasNext(); - } - - /** {@inheritDoc} */ - @Override public T nextElement() { - return iter.next(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridSuperTarget.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridSuperTarget.java b/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridSuperTarget.java deleted file mode 100644 index 92f490c..0000000 --- a/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridSuperTarget.java +++ /dev/null @@ -1,53 +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.gridgain.grid.gridify.hierarchy; - -import org.apache.ignite.compute.gridify.*; - -/** - * Target base class. - */ -public abstract class GridSuperTarget { - /** - * @return Always returns "GridSuperTarget.methodA()". - */ - @Gridify(gridName = "GridifyHierarchyTest") - protected String methodA() { - System.out.println(">>> Called GridSuperTarget.methodA()"); - - return "GridSuperTarget.methodA()"; - } - - /** - * @return "GridSuperTarget.methodC()" string. - */ - protected String methodB() { - return methodC(); - } - - /** - * @return "GridSuperTarget.methodC()" string. - */ - @Gridify(gridName = "GridifyHierarchyTest") - private String methodC() { - System.out.println(">>> Called GridSuperTarget.methodC()"); - - return "GridSuperTarget.methodC()"; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridTarget.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridTarget.java b/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridTarget.java deleted file mode 100644 index 564608d..0000000 --- a/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridTarget.java +++ /dev/null @@ -1,45 +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.gridgain.grid.gridify.hierarchy; - -/** - * Target. - */ -public class GridTarget extends GridSuperTarget { - /** {@inheritDoc} */ - @Override protected String methodA() { - System.out.println(">>> Called GridTarget.methodA()"); - - String res = super.methodA(); - - assert "GridSuperTarget.methodA()".equals(res) == true : - "Unexpected GridSuperTarget.methodA() apply result [res=" + res + ']'; - - return "GridTarget.MethodA()"; - } - - /** {@inheritDoc} */ - @Override protected String methodB() { - String res = super.methodB(); - - assert "GridSuperTarget.methodC()".equals(res) == true: - "Unexpected GridSuperTarget.methodB() apply result [res=" + res + ']'; - - return res; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridifyHierarchyTest.java ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridifyHierarchyTest.java b/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridifyHierarchyTest.java deleted file mode 100644 index 14db6af..0000000 --- a/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/GridifyHierarchyTest.java +++ /dev/null @@ -1,51 +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.gridgain.grid.gridify.hierarchy; - -import org.gridgain.testframework.junits.common.*; - -/** - * Gridify hierarchy test. - */ -public class GridifyHierarchyTest extends GridCommonAbstractTest { - /** */ - public GridifyHierarchyTest() { - super(true); - } - - /** */ - public void noneTestGridifyHierarchyProtected() { - GridTarget target = new GridTarget(); - - target.methodA(); - } - - /** - * @throws Exception If failed. - */ - public void testGridifyHierarchyPrivate() throws Exception { - GridTarget target = new GridTarget(); - - target.methodB(); - } - - /** {@inheritDoc} */ - @Override public String getTestGridName() { - return "GridifyHierarchyTest"; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/package.html ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/package.html b/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/package.html deleted file mode 100644 index 89e4866..0000000 --- a/modules/aop/src/test/java/org/gridgain/grid/gridify/hierarchy/package.html +++ /dev/null @@ -1,23 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<!-- - 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. - --> -<html> -<body> - <!-- Package description. --> - Contains internal tests or test related classes and interfaces. -</body> -</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/aop/src/test/java/org/gridgain/grid/gridify/package.html ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/gridgain/grid/gridify/package.html b/modules/aop/src/test/java/org/gridgain/grid/gridify/package.html deleted file mode 100644 index 89e4866..0000000 --- a/modules/aop/src/test/java/org/gridgain/grid/gridify/package.html +++ /dev/null @@ -1,23 +0,0 @@ -<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> -<!-- - 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. - --> -<html> -<body> - <!-- Package description. --> - Contains internal tests or test related classes and interfaces. -</body> -</html> http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/aop/src/test/java/org/gridgain/grid/gridify/test_resource.properties ---------------------------------------------------------------------- diff --git a/modules/aop/src/test/java/org/gridgain/grid/gridify/test_resource.properties b/modules/aop/src/test/java/org/gridgain/grid/gridify/test_resource.properties deleted file mode 100644 index 15b218e..0000000 --- a/modules/aop/src/test/java/org/gridgain/grid/gridify/test_resource.properties +++ /dev/null @@ -1,18 +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. -# - -param1=1 http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/clients/src/test/java/org/apache/ignite/internal/GridTaskEventSubjectIdSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/internal/GridTaskEventSubjectIdSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/internal/GridTaskEventSubjectIdSelfTest.java new file mode 100644 index 0000000..2d33be2 --- /dev/null +++ b/modules/clients/src/test/java/org/apache/ignite/internal/GridTaskEventSubjectIdSelfTest.java @@ -0,0 +1,392 @@ +/* + * 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; + +import org.apache.ignite.*; +import org.apache.ignite.compute.*; +import org.apache.ignite.configuration.*; +import org.apache.ignite.events.*; +import org.apache.ignite.lang.*; +import org.apache.ignite.client.*; +import org.gridgain.testframework.*; +import org.gridgain.testframework.junits.common.*; +import org.jetbrains.annotations.*; + +import java.util.*; +import java.util.concurrent.*; + +import static java.util.concurrent.TimeUnit.*; +import static org.apache.ignite.events.IgniteEventType.*; + +/** + * Tests for security subject ID in task events. + */ +public class GridTaskEventSubjectIdSelfTest extends GridCommonAbstractTest { + /** */ + private static final Collection<IgniteTaskEvent> evts = new ArrayList<>(); + + /** */ + private static CountDownLatch latch; + + /** */ + private static UUID nodeId; + + /** */ + private static GridClient client; + + /** {@inheritDoc} */ + @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { + IgniteConfiguration cfg = super.getConfiguration(gridName); + + cfg.setRestEnabled(true); + + return cfg; + } + + /** {@inheritDoc} */ + @Override protected void beforeTestsStarted() throws Exception { + Ignite g = startGrid(); + + g.events().localListen(new IgnitePredicate<IgniteEvent>() { + @Override public boolean apply(IgniteEvent evt) { + assert evt instanceof IgniteTaskEvent; + + evts.add((IgniteTaskEvent)evt); + + latch.countDown(); + + return true; + } + }, EVTS_TASK_EXECUTION); + + nodeId = g.cluster().localNode().id(); + + GridClientConfiguration cfg = new GridClientConfiguration(); + + cfg.setServers(Collections.singleton("127.0.0.1:11211")); + + client = GridClientFactory.start(cfg); + } + + /** {@inheritDoc} */ + @Override protected void afterTestsStopped() throws Exception { + GridClientFactory.stop(client.id()); + + stopGrid(); + } + + /** {@inheritDoc} */ + @Override protected void beforeTest() throws Exception { + evts.clear(); + } + + /** + * @throws Exception If failed. + */ + public void testSimpleTask() throws Exception { + latch = new CountDownLatch(3); + + grid().compute().execute(new SimpleTask(), null); + + assert latch.await(1000, MILLISECONDS); + + assertEquals(3, evts.size()); + + Iterator<IgniteTaskEvent> it = evts.iterator(); + + assert it.hasNext(); + + IgniteTaskEvent evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_STARTED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert it.hasNext(); + + evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_REDUCED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert it.hasNext(); + + evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_FINISHED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert !it.hasNext(); + } + + /** + * @throws Exception If failed. + */ + public void testFailedTask() throws Exception { + latch = new CountDownLatch(2); + + GridTestUtils.assertThrows( + log, + new Callable<Object>() { + @Override public Object call() throws Exception { + grid().compute().execute(new FailedTask(), null); + + return null; + } + }, + IgniteCheckedException.class, + null + ); + + assert latch.await(1000, MILLISECONDS); + + assertEquals(2, evts.size()); + + Iterator<IgniteTaskEvent> it = evts.iterator(); + + assert it.hasNext(); + + IgniteTaskEvent evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_STARTED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert it.hasNext(); + + evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_FAILED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert !it.hasNext(); + } + + /** + * @throws Exception If failed. + */ + public void testTimedOutTask() throws Exception { + latch = new CountDownLatch(2); + + GridTestUtils.assertThrows( + log, + new Callable<Object>() { + @Override public Object call() throws Exception { + grid().compute().withTimeout(100).execute(new TimedOutTask(), null); + + return null; + } + }, + ComputeTaskTimeoutException.class, + null + ); + + assert latch.await(1000, MILLISECONDS); + + assertEquals(3, evts.size()); + + Iterator<IgniteTaskEvent> it = evts.iterator(); + + assert it.hasNext(); + + IgniteTaskEvent evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_STARTED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert it.hasNext(); + + evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_TIMEDOUT, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert it.hasNext(); + + evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_FAILED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert !it.hasNext(); + } + + /** + * @throws Exception If failed. + */ + public void testClosure() throws Exception { + latch = new CountDownLatch(3); + + grid().compute().run(new IgniteRunnable() { + @Override public void run() { + // No-op. + } + }); + + assert latch.await(1000, MILLISECONDS); + + assertEquals(3, evts.size()); + + Iterator<IgniteTaskEvent> it = evts.iterator(); + + assert it.hasNext(); + + IgniteTaskEvent evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_STARTED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert it.hasNext(); + + evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_REDUCED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert it.hasNext(); + + evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_FINISHED, evt.type()); + assertEquals(nodeId, evt.subjectId()); + + assert !it.hasNext(); + } + + /** + * @throws Exception If failed. + */ + public void testClient() throws Exception { + latch = new CountDownLatch(3); + + client.compute().execute(SimpleTask.class.getName(), null); + + assert latch.await(1000, MILLISECONDS); + + assertEquals(3, evts.size()); + + Iterator<IgniteTaskEvent> it = evts.iterator(); + + assert it.hasNext(); + + IgniteTaskEvent evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_STARTED, evt.type()); + assertEquals(client.id(), evt.subjectId()); + + assert it.hasNext(); + + evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_REDUCED, evt.type()); + assertEquals(client.id(), evt.subjectId()); + + assert it.hasNext(); + + evt = it.next(); + + assert evt != null; + + assertEquals(EVT_TASK_FINISHED, evt.type()); + assertEquals(client.id(), evt.subjectId()); + + assert !it.hasNext(); + } + + /** */ + private static class SimpleTask extends ComputeTaskSplitAdapter<Object, Object> { + /** {@inheritDoc} */ + @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { + return Collections.singleton(new ComputeJobAdapter() { + @Nullable @Override public Object execute() { + return null; + } + }); + } + + /** {@inheritDoc} */ + @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { + return null; + } + } + + /** */ + private static class FailedTask extends ComputeTaskSplitAdapter<Object, Object> { + /** {@inheritDoc} */ + @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { + return Collections.singleton(new ComputeJobAdapter() { + @Nullable @Override public Object execute() { + return null; + } + }); + } + + /** {@inheritDoc} */ + @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { + throw new IgniteCheckedException("Task failed."); + } + } + + /** */ + private static class TimedOutTask extends ComputeTaskSplitAdapter<Object, Object> { + /** {@inheritDoc} */ + @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { + return Collections.singleton(new ComputeJobAdapter() { + @Nullable @Override public Object execute() { + try { + Thread.sleep(10000); + } + catch (InterruptedException ignored) { + // No-op. + } + + return null; + } + }); + } + + /** {@inheritDoc} */ + @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { + return null; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientCacheBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientCacheBenchmark.java b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientCacheBenchmark.java new file mode 100644 index 0000000..2d850d6 --- /dev/null +++ b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientCacheBenchmark.java @@ -0,0 +1,259 @@ +/* + * 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.loadtests.client; + +import org.apache.ignite.*; +import org.apache.ignite.client.*; +import org.apache.ignite.internal.util.typedef.*; +import org.apache.ignite.internal.util.typedef.internal.*; +import org.gridgain.testframework.*; + +import java.io.*; +import java.util.*; + +/** + * Use {@code modules/core/src/test/config/benchmark/spring-cache-client-benchmark-*.xml} + * configurations for servers. + */ +public class GridClientCacheBenchmark { + /** Number of keys, used in PUT/GET operations. */ + private static final int KEY_COUNT = 1000; + + /** Size of arrays used as stored values. */ + private static final int VALUE_LENGTH = 1024*4; + + /** Cached values for store. */ + private static final byte[][] values = new byte[KEY_COUNT][]; + + /** Probability of put operation. */ + private static final double WRITE_PROB = 0.2; + + /** Random generator. */ + private final Random rnd = new Random(); + + /** Number of submitting threads for current test. */ + private final int threadCnt; + + /** Number of operations per thread. */ + private final int iterationCnt; + + /** Test client. */ + private GridClient client; + + /** Resulting number of iterations per second. */ + private double itersPerSec; + + /** + * @param threadCnt Number of submitting threads. + * @param iterationCnt Number of operations per thread. + */ + public GridClientCacheBenchmark(int threadCnt, int iterationCnt) { + this.threadCnt = threadCnt; + this.iterationCnt = iterationCnt; + + initValues(); + } + + /** + * Initiates the values cache. + */ + private void initValues() { + for (int i = 0; i < KEY_COUNT; i++) { + values[i] = new byte[VALUE_LENGTH]; + + rnd.nextBytes(values[i]); + } + } + + /** + * Performs test, + * + * @param printResults Whether to print results. + * @throws GridClientException If failed. + */ + @SuppressWarnings("NullableProblems") + public void run(boolean printResults) throws GridClientException { + Collection<TestThread> workers = new ArrayList<>(threadCnt); + + client = GridClientFactory.start(configuration()); + + long startTime = System.currentTimeMillis(); + + for(int i = 0; i < threadCnt; i++) { + TestThread th = new TestThread(); + workers.add(th); + th.start(); + } + + U.joinThreads(workers, null); + + if (printResults) + countAndPrintSummary(workers, startTime); + + GridClientFactory.stopAll(); + } + + /** + * @return Resulting iterations per second. + */ + public double getItersPerSec() { + return itersPerSec; + } + + /** + * Counts and prints tests summary, + * + * @param workers Collection of test worker threads. + * @param startTime Time when test eas started. + */ + private void countAndPrintSummary(Collection<TestThread> workers, long startTime) { + long total = 0; + + int thCnt = workers.size(); + + for (TestThread t : workers) { total += t.iters; } + + double timeSpent = ((double)(System.currentTimeMillis() - startTime)) / 1000; + + itersPerSec = total/timeSpent; + + System.out.printf("%8s, %12.0f, %12.0f, %12s\n", thCnt, itersPerSec, total/timeSpent/thCnt, total); + } + + /** + * @return Test client configuration. + */ + private GridClientConfiguration configuration() { + GridClientConfiguration cfg = new GridClientConfiguration(); + + cfg.setServers(Collections.singleton("localhost:11211")); + + GridClientDataConfiguration cacheCfg = new GridClientDataConfiguration(); + + cacheCfg.setName("partitioned"); + + cacheCfg.setAffinity(new GridClientPartitionAffinity()); + + cfg.setDataConfigurations(Collections.singletonList(cacheCfg)); + + return cfg; + } + + /** + * Test thread. + */ + private class TestThread extends Thread { + /* Thread private random generator. */ + private final Random rnd = new Random(); + + /** Number of iterations to perform. */ + private long iters; + + /** {@inheritDoc} */ + @Override public void run() { + try { + GridClientData data = client.data("partitioned"); + + for (int i = 0; i < iterationCnt; i++) + performIteration(data); + } + catch (GridClientException e) { + e.printStackTrace(); + } + } + + /** + * Performs test iteration. + * @param data client data to operate on. + * @throws GridClientException If failed. + */ + private void performIteration(GridClientData data) throws GridClientException { + if (rnd.nextDouble() <= WRITE_PROB) + data.put(rnd.nextInt(KEY_COUNT), values[rnd.nextInt(KEY_COUNT)]); + else + data.get(rnd.nextInt(KEY_COUNT)); + + iters++; + } + } + + /** + * Runs benchmark. + * @param args Command-line arguments. + * @throws GridClientException If failed. + */ + public static void main(String[] args) throws GridClientException, IgniteCheckedException { + GridFileLock fileLock = GridLoadTestUtils.fileLock(); + + fileLock.lock(); + + try { + System.out.printf("%8s, %12s, %12s, %12s\n", "Threads", "It./s.", "It./s.*th.", "Iters."); + + if (args.length == 0) { + for (int i = 1; i <= 16; i *= 2) { + GridClientCacheBenchmark benchmark = new GridClientCacheBenchmark(i, 10000); + + benchmark.run(false); + + System.gc(); + } + + for (int i = 1; i <= 64; i *= 2) { + GridClientCacheBenchmark benchmark = new GridClientCacheBenchmark(i, 10000); + + benchmark.run(true); + + System.gc(); + } + } + else { + int nThreads = Integer.parseInt(args[0]); + String outputFileName = (args.length >= 2 ? args[1] : null); + + GridClientCacheBenchmark benchmark = null; + + for (int i = 0; i < 2; i++) { + benchmark = new GridClientCacheBenchmark(nThreads, 10000); + + benchmark.run(true); + } + + if (outputFileName != null) { + X.println("Writing test results to a file: " + outputFileName); + + assert benchmark != null; + + try { + GridLoadTestUtils.appendLineToFile( + outputFileName, + "%s,%d", + GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), + Math.round(benchmark.getItersPerSec())); + } + catch (IOException e) { + X.error("Failed to output to a file", e); + } + } + } + } + finally { + fileLock.close(); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientMarshallerBenchmarkTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientMarshallerBenchmarkTest.java b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientMarshallerBenchmarkTest.java new file mode 100644 index 0000000..623a08b --- /dev/null +++ b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientMarshallerBenchmarkTest.java @@ -0,0 +1,156 @@ +/* + * 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.loadtests.client; + +import org.apache.ignite.client.marshaller.*; +import org.apache.ignite.client.marshaller.jdk.*; +import org.apache.ignite.client.marshaller.optimized.*; +import org.apache.ignite.internal.processors.rest.client.message.*; +import org.apache.ignite.internal.util.typedef.*; +import org.gridgain.testframework.junits.common.*; + +import java.io.*; +import java.nio.*; +import java.util.*; + +import static org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*; + +/** + * Tests basic performance of marshallers. + */ +public class GridClientMarshallerBenchmarkTest extends GridCommonAbstractTest { + /** Marshallers to test. */ + private GridClientMarshaller[] marshallers; + + /** + */ + public GridClientMarshallerBenchmarkTest() { + marshallers = new GridClientMarshaller[] { + new GridClientJdkMarshaller(), + new GridClientOptimizedMarshaller() + }; + } + + /** + * @throws Exception If failed. + */ + public void testCacheRequestTime() throws Exception { + GridClientCacheRequest req = new GridClientCacheRequest(CAS); + + req.clientId(UUID.randomUUID()); + req.cacheName("CacheName"); + req.requestId(1024); + req.key("key"); + req.value(1L); + req.value2(2L); + + Map<Object, Object> additional = new HashMap<>(); + + for (int i = 0; i < 1000; i++) + additional.put("key" + i, (long)i); + + req.values(additional); + + // Warm up. + for (GridClientMarshaller marshaller : marshallers) { + GridClientCacheRequest res = runMarshallUnmarshalLoop(req, 1, marshaller); + + assertEquals(req.operation(), res.operation()); + assertEquals(0, res.requestId()); // requestId is not marshalled. + assertEquals(null, res.clientId()); // clientId is not marshalled. + assertEquals(null, res.destinationId()); // destinationId is not marshalled. + assertEquals(req.cacheName(), res.cacheName()); + assertEquals(req.key(), res.key()); + assertEquals(req.value(), res.value()); + assertEquals(req.value2(), res.value2()); + + for (Map.Entry<Object, Object> e : req.values().entrySet()) + assertEquals(e.getValue(), res.values().get(e.getKey())); + } + + // Now real test. + for (GridClientMarshaller marshaller : marshallers) + runMarshallUnmarshalLoop(req, 1000, marshaller); + } + + /** + * Runs marshal/unmarshal loop and prints statistics. + * + * @param obj Object to marshal. + * @param iterCnt Iteration count. + * @param marshaller Marshaller to use. + * @throws IOException If marshalling failed. + * @return Unmarshalled object in last iteration + */ + @SuppressWarnings("unchecked") + private <T> T runMarshallUnmarshalLoop(T obj, int iterCnt, GridClientMarshaller marshaller) + throws IOException { + if (iterCnt == 1) { + // Warm-up, will not print statistics. + ByteBuffer buf = marshaller.marshal(obj, 0); + + byte[] arr = new byte[buf.remaining()]; + + buf.get(arr); + + Object res = marshaller.unmarshal(arr); + + assertNotNull("Failed for marshaller: " + marshaller.getClass().getSimpleName(), res); + + return (T)res; + } + + long marshallingTime = 0, unmarshallingTime = 0; + + long start = System.currentTimeMillis(); + + Object res = null; + + for (int i = 0; i < iterCnt; i++) { + ByteBuffer buf = marshaller.marshal(obj, 0); + + byte[] raw = new byte[buf.remaining()]; + + buf.get(raw); + + long end = System.currentTimeMillis(); + + marshallingTime += (end - start); + + start = end; + + res = marshaller.unmarshal(raw); + + assertNotNull(res); + + end = System.currentTimeMillis(); + + unmarshallingTime += (end - start); + + start = end; + } + + X.println("Marshalling statistics gathered [marshallerClass=" + marshaller.getClass().getSimpleName() + + ", objClass=" + obj.getClass().getSimpleName() + ", marshallingTime=" + marshallingTime + + ", unmarshallingTime=" + unmarshallingTime + "]"); + + assert res != null; + + return (T)res; + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientTcpSslLoadTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientTcpSslLoadTest.java b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientTcpSslLoadTest.java new file mode 100644 index 0000000..27b5767 --- /dev/null +++ b/modules/clients/src/test/java/org/apache/ignite/loadtests/client/GridClientTcpSslLoadTest.java @@ -0,0 +1,83 @@ +/* + * 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.loadtests.client; + +import org.apache.ignite.client.*; +import org.apache.ignite.internal.util.typedef.internal.*; + +/** + * Makes a long run to ensure stability and absence of memory leaks. + */ +public class GridClientTcpSslLoadTest extends GridClientTcpSslMultiThreadedSelfTest { + /** Test duration. */ + private static final long TEST_RUN_TIME = 8 * 60 * 60 * 1000; + + /** Statistics output interval. */ + private static final long STATISTICS_PRINT_INTERVAL = 5 * 60 * 1000; + + /** Time to let connections closed by idle. */ + private static final long RELAX_INTERVAL = 60 * 1000; + + /** + * @throws Exception If failed. + */ + public void testLongRun() throws Exception { + long start = System.currentTimeMillis(); + + long lastPrint = start; + + do { + clearCaches(); + + testMultithreadedTaskRun(); + + testMultithreadedCachePut(); + + long now = System.currentTimeMillis(); + + if (now - lastPrint > STATISTICS_PRINT_INTERVAL) { + info(">>>>>>> Running test for " + ((now - start) / 1000) + " seconds."); + + lastPrint = now; + } + + // Let idle check work. + U.sleep(RELAX_INTERVAL); + } + while (System.currentTimeMillis() - start < TEST_RUN_TIME); + } + + /** {@inheritDoc} */ + @Override protected int topologyRefreshFrequency() { + return 5000; + } + + /** {@inheritDoc} */ + @Override protected int maxConnectionIdleTime() { + return topologyRefreshFrequency() / 5; + } + + /** + * Clears caches on all nodes. + */ + @SuppressWarnings("ConstantConditions") + private void clearCaches() { + for (int i = 0; i < NODES_CNT; i++) + grid(i).cache(PARTITIONED_CACHE_NAME).clearAll(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/clients/src/test/java/org/gridgain/grid/kernal/GridTaskEventSubjectIdSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/grid/kernal/GridTaskEventSubjectIdSelfTest.java b/modules/clients/src/test/java/org/gridgain/grid/kernal/GridTaskEventSubjectIdSelfTest.java deleted file mode 100644 index 51eb10a..0000000 --- a/modules/clients/src/test/java/org/gridgain/grid/kernal/GridTaskEventSubjectIdSelfTest.java +++ /dev/null @@ -1,392 +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.gridgain.grid.kernal; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.events.*; -import org.apache.ignite.lang.*; -import org.apache.ignite.client.*; -import org.gridgain.testframework.*; -import org.gridgain.testframework.junits.common.*; -import org.jetbrains.annotations.*; - -import java.util.*; -import java.util.concurrent.*; - -import static java.util.concurrent.TimeUnit.*; -import static org.apache.ignite.events.IgniteEventType.*; - -/** - * Tests for security subject ID in task events. - */ -public class GridTaskEventSubjectIdSelfTest extends GridCommonAbstractTest { - /** */ - private static final Collection<IgniteTaskEvent> evts = new ArrayList<>(); - - /** */ - private static CountDownLatch latch; - - /** */ - private static UUID nodeId; - - /** */ - private static GridClient client; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setRestEnabled(true); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - Ignite g = startGrid(); - - g.events().localListen(new IgnitePredicate<IgniteEvent>() { - @Override public boolean apply(IgniteEvent evt) { - assert evt instanceof IgniteTaskEvent; - - evts.add((IgniteTaskEvent)evt); - - latch.countDown(); - - return true; - } - }, EVTS_TASK_EXECUTION); - - nodeId = g.cluster().localNode().id(); - - GridClientConfiguration cfg = new GridClientConfiguration(); - - cfg.setServers(Collections.singleton("127.0.0.1:11211")); - - client = GridClientFactory.start(cfg); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - GridClientFactory.stop(client.id()); - - stopGrid(); - } - - /** {@inheritDoc} */ - @Override protected void beforeTest() throws Exception { - evts.clear(); - } - - /** - * @throws Exception If failed. - */ - public void testSimpleTask() throws Exception { - latch = new CountDownLatch(3); - - grid().compute().execute(new SimpleTask(), null); - - assert latch.await(1000, MILLISECONDS); - - assertEquals(3, evts.size()); - - Iterator<IgniteTaskEvent> it = evts.iterator(); - - assert it.hasNext(); - - IgniteTaskEvent evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_STARTED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert it.hasNext(); - - evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_REDUCED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert it.hasNext(); - - evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_FINISHED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert !it.hasNext(); - } - - /** - * @throws Exception If failed. - */ - public void testFailedTask() throws Exception { - latch = new CountDownLatch(2); - - GridTestUtils.assertThrows( - log, - new Callable<Object>() { - @Override public Object call() throws Exception { - grid().compute().execute(new FailedTask(), null); - - return null; - } - }, - IgniteCheckedException.class, - null - ); - - assert latch.await(1000, MILLISECONDS); - - assertEquals(2, evts.size()); - - Iterator<IgniteTaskEvent> it = evts.iterator(); - - assert it.hasNext(); - - IgniteTaskEvent evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_STARTED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert it.hasNext(); - - evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_FAILED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert !it.hasNext(); - } - - /** - * @throws Exception If failed. - */ - public void testTimedOutTask() throws Exception { - latch = new CountDownLatch(2); - - GridTestUtils.assertThrows( - log, - new Callable<Object>() { - @Override public Object call() throws Exception { - grid().compute().withTimeout(100).execute(new TimedOutTask(), null); - - return null; - } - }, - ComputeTaskTimeoutException.class, - null - ); - - assert latch.await(1000, MILLISECONDS); - - assertEquals(3, evts.size()); - - Iterator<IgniteTaskEvent> it = evts.iterator(); - - assert it.hasNext(); - - IgniteTaskEvent evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_STARTED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert it.hasNext(); - - evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_TIMEDOUT, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert it.hasNext(); - - evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_FAILED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert !it.hasNext(); - } - - /** - * @throws Exception If failed. - */ - public void testClosure() throws Exception { - latch = new CountDownLatch(3); - - grid().compute().run(new IgniteRunnable() { - @Override public void run() { - // No-op. - } - }); - - assert latch.await(1000, MILLISECONDS); - - assertEquals(3, evts.size()); - - Iterator<IgniteTaskEvent> it = evts.iterator(); - - assert it.hasNext(); - - IgniteTaskEvent evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_STARTED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert it.hasNext(); - - evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_REDUCED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert it.hasNext(); - - evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_FINISHED, evt.type()); - assertEquals(nodeId, evt.subjectId()); - - assert !it.hasNext(); - } - - /** - * @throws Exception If failed. - */ - public void testClient() throws Exception { - latch = new CountDownLatch(3); - - client.compute().execute(SimpleTask.class.getName(), null); - - assert latch.await(1000, MILLISECONDS); - - assertEquals(3, evts.size()); - - Iterator<IgniteTaskEvent> it = evts.iterator(); - - assert it.hasNext(); - - IgniteTaskEvent evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_STARTED, evt.type()); - assertEquals(client.id(), evt.subjectId()); - - assert it.hasNext(); - - evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_REDUCED, evt.type()); - assertEquals(client.id(), evt.subjectId()); - - assert it.hasNext(); - - evt = it.next(); - - assert evt != null; - - assertEquals(EVT_TASK_FINISHED, evt.type()); - assertEquals(client.id(), evt.subjectId()); - - assert !it.hasNext(); - } - - /** */ - private static class SimpleTask extends ComputeTaskSplitAdapter<Object, Object> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { - return Collections.singleton(new ComputeJobAdapter() { - @Nullable @Override public Object execute() { - return null; - } - }); - } - - /** {@inheritDoc} */ - @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return null; - } - } - - /** */ - private static class FailedTask extends ComputeTaskSplitAdapter<Object, Object> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { - return Collections.singleton(new ComputeJobAdapter() { - @Nullable @Override public Object execute() { - return null; - } - }); - } - - /** {@inheritDoc} */ - @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - throw new IgniteCheckedException("Task failed."); - } - } - - /** */ - private static class TimedOutTask extends ComputeTaskSplitAdapter<Object, Object> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, Object arg) throws IgniteCheckedException { - return Collections.singleton(new ComputeJobAdapter() { - @Nullable @Override public Object execute() { - try { - Thread.sleep(10000); - } - catch (InterruptedException ignored) { - // No-op. - } - - return null; - } - }); - } - - /** {@inheritDoc} */ - @Nullable @Override public Object reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return null; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientCacheBenchmark.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientCacheBenchmark.java b/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientCacheBenchmark.java deleted file mode 100644 index 84dd369..0000000 --- a/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientCacheBenchmark.java +++ /dev/null @@ -1,259 +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.gridgain.loadtests.client; - -import org.apache.ignite.*; -import org.apache.ignite.client.*; -import org.apache.ignite.internal.util.typedef.*; -import org.apache.ignite.internal.util.typedef.internal.*; -import org.gridgain.testframework.*; - -import java.io.*; -import java.util.*; - -/** - * Use {@code modules/core/src/test/config/benchmark/spring-cache-client-benchmark-*.xml} - * configurations for servers. - */ -public class GridClientCacheBenchmark { - /** Number of keys, used in PUT/GET operations. */ - private static final int KEY_COUNT = 1000; - - /** Size of arrays used as stored values. */ - private static final int VALUE_LENGTH = 1024*4; - - /** Cached values for store. */ - private static final byte[][] values = new byte[KEY_COUNT][]; - - /** Probability of put operation. */ - private static final double WRITE_PROB = 0.2; - - /** Random generator. */ - private final Random rnd = new Random(); - - /** Number of submitting threads for current test. */ - private final int threadCnt; - - /** Number of operations per thread. */ - private final int iterationCnt; - - /** Test client. */ - private GridClient client; - - /** Resulting number of iterations per second. */ - private double itersPerSec; - - /** - * @param threadCnt Number of submitting threads. - * @param iterationCnt Number of operations per thread. - */ - public GridClientCacheBenchmark(int threadCnt, int iterationCnt) { - this.threadCnt = threadCnt; - this.iterationCnt = iterationCnt; - - initValues(); - } - - /** - * Initiates the values cache. - */ - private void initValues() { - for (int i = 0; i < KEY_COUNT; i++) { - values[i] = new byte[VALUE_LENGTH]; - - rnd.nextBytes(values[i]); - } - } - - /** - * Performs test, - * - * @param printResults Whether to print results. - * @throws GridClientException If failed. - */ - @SuppressWarnings("NullableProblems") - public void run(boolean printResults) throws GridClientException { - Collection<TestThread> workers = new ArrayList<>(threadCnt); - - client = GridClientFactory.start(configuration()); - - long startTime = System.currentTimeMillis(); - - for(int i = 0; i < threadCnt; i++) { - TestThread th = new TestThread(); - workers.add(th); - th.start(); - } - - U.joinThreads(workers, null); - - if (printResults) - countAndPrintSummary(workers, startTime); - - GridClientFactory.stopAll(); - } - - /** - * @return Resulting iterations per second. - */ - public double getItersPerSec() { - return itersPerSec; - } - - /** - * Counts and prints tests summary, - * - * @param workers Collection of test worker threads. - * @param startTime Time when test eas started. - */ - private void countAndPrintSummary(Collection<TestThread> workers, long startTime) { - long total = 0; - - int thCnt = workers.size(); - - for (TestThread t : workers) { total += t.iters; } - - double timeSpent = ((double)(System.currentTimeMillis() - startTime)) / 1000; - - itersPerSec = total/timeSpent; - - System.out.printf("%8s, %12.0f, %12.0f, %12s\n", thCnt, itersPerSec, total/timeSpent/thCnt, total); - } - - /** - * @return Test client configuration. - */ - private GridClientConfiguration configuration() { - GridClientConfiguration cfg = new GridClientConfiguration(); - - cfg.setServers(Collections.singleton("localhost:11211")); - - GridClientDataConfiguration cacheCfg = new GridClientDataConfiguration(); - - cacheCfg.setName("partitioned"); - - cacheCfg.setAffinity(new GridClientPartitionAffinity()); - - cfg.setDataConfigurations(Collections.singletonList(cacheCfg)); - - return cfg; - } - - /** - * Test thread. - */ - private class TestThread extends Thread { - /* Thread private random generator. */ - private final Random rnd = new Random(); - - /** Number of iterations to perform. */ - private long iters; - - /** {@inheritDoc} */ - @Override public void run() { - try { - GridClientData data = client.data("partitioned"); - - for (int i = 0; i < iterationCnt; i++) - performIteration(data); - } - catch (GridClientException e) { - e.printStackTrace(); - } - } - - /** - * Performs test iteration. - * @param data client data to operate on. - * @throws GridClientException If failed. - */ - private void performIteration(GridClientData data) throws GridClientException { - if (rnd.nextDouble() <= WRITE_PROB) - data.put(rnd.nextInt(KEY_COUNT), values[rnd.nextInt(KEY_COUNT)]); - else - data.get(rnd.nextInt(KEY_COUNT)); - - iters++; - } - } - - /** - * Runs benchmark. - * @param args Command-line arguments. - * @throws GridClientException If failed. - */ - public static void main(String[] args) throws GridClientException, IgniteCheckedException { - GridFileLock fileLock = GridLoadTestUtils.fileLock(); - - fileLock.lock(); - - try { - System.out.printf("%8s, %12s, %12s, %12s\n", "Threads", "It./s.", "It./s.*th.", "Iters."); - - if (args.length == 0) { - for (int i = 1; i <= 16; i *= 2) { - GridClientCacheBenchmark benchmark = new GridClientCacheBenchmark(i, 10000); - - benchmark.run(false); - - System.gc(); - } - - for (int i = 1; i <= 64; i *= 2) { - GridClientCacheBenchmark benchmark = new GridClientCacheBenchmark(i, 10000); - - benchmark.run(true); - - System.gc(); - } - } - else { - int nThreads = Integer.parseInt(args[0]); - String outputFileName = (args.length >= 2 ? args[1] : null); - - GridClientCacheBenchmark benchmark = null; - - for (int i = 0; i < 2; i++) { - benchmark = new GridClientCacheBenchmark(nThreads, 10000); - - benchmark.run(true); - } - - if (outputFileName != null) { - X.println("Writing test results to a file: " + outputFileName); - - assert benchmark != null; - - try { - GridLoadTestUtils.appendLineToFile( - outputFileName, - "%s,%d", - GridLoadTestUtils.DATE_TIME_FORMAT.format(new Date()), - Math.round(benchmark.getItersPerSec())); - } - catch (IOException e) { - X.error("Failed to output to a file", e); - } - } - } - } - finally { - fileLock.close(); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e1d8f69b/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientMarshallerBenchmarkTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientMarshallerBenchmarkTest.java b/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientMarshallerBenchmarkTest.java deleted file mode 100644 index 4802d4f..0000000 --- a/modules/clients/src/test/java/org/gridgain/loadtests/client/GridClientMarshallerBenchmarkTest.java +++ /dev/null @@ -1,156 +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.gridgain.loadtests.client; - -import org.apache.ignite.client.marshaller.*; -import org.apache.ignite.client.marshaller.jdk.*; -import org.apache.ignite.client.marshaller.optimized.*; -import org.apache.ignite.internal.processors.rest.client.message.*; -import org.apache.ignite.internal.util.typedef.*; -import org.gridgain.testframework.junits.common.*; - -import java.io.*; -import java.nio.*; -import java.util.*; - -import static org.apache.ignite.internal.processors.rest.client.message.GridClientCacheRequest.GridCacheOperation.*; - -/** - * Tests basic performance of marshallers. - */ -public class GridClientMarshallerBenchmarkTest extends GridCommonAbstractTest { - /** Marshallers to test. */ - private GridClientMarshaller[] marshallers; - - /** - */ - public GridClientMarshallerBenchmarkTest() { - marshallers = new GridClientMarshaller[] { - new GridClientJdkMarshaller(), - new GridClientOptimizedMarshaller() - }; - } - - /** - * @throws Exception If failed. - */ - public void testCacheRequestTime() throws Exception { - GridClientCacheRequest req = new GridClientCacheRequest(CAS); - - req.clientId(UUID.randomUUID()); - req.cacheName("CacheName"); - req.requestId(1024); - req.key("key"); - req.value(1L); - req.value2(2L); - - Map<Object, Object> additional = new HashMap<>(); - - for (int i = 0; i < 1000; i++) - additional.put("key" + i, (long)i); - - req.values(additional); - - // Warm up. - for (GridClientMarshaller marshaller : marshallers) { - GridClientCacheRequest res = runMarshallUnmarshalLoop(req, 1, marshaller); - - assertEquals(req.operation(), res.operation()); - assertEquals(0, res.requestId()); // requestId is not marshalled. - assertEquals(null, res.clientId()); // clientId is not marshalled. - assertEquals(null, res.destinationId()); // destinationId is not marshalled. - assertEquals(req.cacheName(), res.cacheName()); - assertEquals(req.key(), res.key()); - assertEquals(req.value(), res.value()); - assertEquals(req.value2(), res.value2()); - - for (Map.Entry<Object, Object> e : req.values().entrySet()) - assertEquals(e.getValue(), res.values().get(e.getKey())); - } - - // Now real test. - for (GridClientMarshaller marshaller : marshallers) - runMarshallUnmarshalLoop(req, 1000, marshaller); - } - - /** - * Runs marshal/unmarshal loop and prints statistics. - * - * @param obj Object to marshal. - * @param iterCnt Iteration count. - * @param marshaller Marshaller to use. - * @throws IOException If marshalling failed. - * @return Unmarshalled object in last iteration - */ - @SuppressWarnings("unchecked") - private <T> T runMarshallUnmarshalLoop(T obj, int iterCnt, GridClientMarshaller marshaller) - throws IOException { - if (iterCnt == 1) { - // Warm-up, will not print statistics. - ByteBuffer buf = marshaller.marshal(obj, 0); - - byte[] arr = new byte[buf.remaining()]; - - buf.get(arr); - - Object res = marshaller.unmarshal(arr); - - assertNotNull("Failed for marshaller: " + marshaller.getClass().getSimpleName(), res); - - return (T)res; - } - - long marshallingTime = 0, unmarshallingTime = 0; - - long start = System.currentTimeMillis(); - - Object res = null; - - for (int i = 0; i < iterCnt; i++) { - ByteBuffer buf = marshaller.marshal(obj, 0); - - byte[] raw = new byte[buf.remaining()]; - - buf.get(raw); - - long end = System.currentTimeMillis(); - - marshallingTime += (end - start); - - start = end; - - res = marshaller.unmarshal(raw); - - assertNotNull(res); - - end = System.currentTimeMillis(); - - unmarshallingTime += (end - start); - - start = end; - } - - X.println("Marshalling statistics gathered [marshallerClass=" + marshaller.getClass().getSimpleName() + - ", objClass=" + obj.getClass().getSimpleName() + ", marshallingTime=" + marshallingTime + - ", unmarshallingTime=" + unmarshallingTime + "]"); - - assert res != null; - - return (T)res; - } -}