http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpTask.java deleted file mode 100644 index 6f0e362..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpTask.java +++ /dev/null @@ -1,73 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; - -import java.util.*; - -import static org.apache.ignite.compute.ComputeJobResultPolicy.*; - -/** - * Test task summarizes length of all strings in the arguments list. - * <p> - * The argument of the task is a collection of objects to calculate string length sum of. - */ -public class ClientTcpTask extends ComputeTaskSplitAdapter<List<Object>, Integer> { - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(int gridSize, List<Object> list) - throws IgniteCheckedException { - Collection<ComputeJobAdapter> jobs = new ArrayList<>(); - - if (list != null) - for (final Object val : list) - jobs.add(new ComputeJobAdapter() { - @Override public Object execute() { - try { - Thread.sleep(5); - } - catch (InterruptedException ignored) { - Thread.currentThread().interrupt(); - } - - return val == null ? 0 : val.toString().length(); - } - }); - - return jobs; - } - - /** {@inheritDoc} */ - @Override public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - int sum = 0; - - for (ComputeJobResult res : results) - sum += res.<Integer>getData(); - - return sum; - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteCheckedException { - if (res.getException() != null) - return FAILOVER; - - return WAIT; - } -}
http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpTaskExecutionAfterTopologyRestartSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpTaskExecutionAfterTopologyRestartSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpTaskExecutionAfterTopologyRestartSelfTest.java deleted file mode 100644 index e11dbfd..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTcpTaskExecutionAfterTopologyRestartSelfTest.java +++ /dev/null @@ -1,76 +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.client; - -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.client.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.*; - -/** - * Ensures - */ -public class ClientTcpTaskExecutionAfterTopologyRestartSelfTest extends GridCommonAbstractTest { - /** Port. */ - private static final int PORT = 11211; - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setLocalHost("127.0.0.1"); - - assert cfg.getClientConnectionConfiguration() == null; - - ClientConnectionConfiguration clientCfg = new ClientConnectionConfiguration(); - - clientCfg.setRestTcpPort(PORT); - - cfg.setClientConnectionConfiguration(clientCfg); - - return cfg; - } - - /** {@inheritDoc} */ - @Override protected void afterTest() throws Exception { - stopAllGrids(); - } - - /** - * @throws Exception If failed. - */ - public void testTaskAfterRestart() throws Exception { - startGrids(1); - - GridClientConfiguration cfg = new GridClientConfiguration(); - - cfg.setProtocol(GridClientProtocol.TCP); - cfg.setServers(Collections.singleton("127.0.0.1:" + PORT)); - - GridClient cli = GridClientFactory.start(cfg); - - cli.compute().execute(ClientTcpTask.class.getName(), Collections.singletonList("arg")); - - stopAllGrids(); - - startGrid(); - - cli.compute().execute(ClientTcpTask.class.getName(), Collections.singletonList("arg")); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortable.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortable.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortable.java deleted file mode 100644 index 2b6e192..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortable.java +++ /dev/null @@ -1,490 +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.client; - -import org.apache.ignite.portables.*; -import org.apache.ignite.internal.util.typedef.internal.*; - -import java.io.*; -import java.util.*; - -/** - * Test portable object. - */ -@SuppressWarnings("PublicField") -public class ClientTestPortable implements PortableMarshalAware, Serializable { - /** */ - public byte b; - - /** */ - public byte bRaw; - - /** */ - public short s; - - /** */ - public short sRaw; - - /** */ - public int i; - - /** */ - public int iRaw; - - /** */ - public long l; - - /** */ - public long lRaw; - - /** */ - public float f; - - /** */ - public float fRaw; - - /** */ - public double d; - - /** */ - public double dRaw; - - /** */ - public char c; - - /** */ - public char cRaw; - - /** */ - public boolean bool; - - /** */ - public boolean boolRaw; - - /** */ - public String str; - - /** */ - public String strRaw; - - /** */ - public UUID uuid; - - /** */ - public UUID uuidRaw; - - /** */ - public Date date; - - /** */ - public Date dateRaw; - - /** */ - public TestEnum e; - - /** */ - public TestEnum eRaw; - - /** */ - public byte[] bArr; - - /** */ - public byte[] bArrRaw; - - /** */ - public short[] sArr; - - /** */ - public short[] sArrRaw; - - /** */ - public int[] iArr; - - /** */ - public int[] iArrRaw; - - /** */ - public long[] lArr; - - /** */ - public long[] lArrRaw; - - /** */ - public float[] fArr; - - /** */ - public float[] fArrRaw; - - /** */ - public double[] dArr; - - /** */ - public double[] dArrRaw; - - /** */ - public char[] cArr; - - /** */ - public char[] cArrRaw; - - /** */ - public boolean[] boolArr; - - /** */ - public boolean[] boolArrRaw; - - /** */ - public String[] strArr; - - /** */ - public String[] strArrRaw; - - /** */ - public UUID[] uuidArr; - - /** */ - public UUID[] uuidArrRaw; - - /** */ - public Date[] dateArr; - - /** */ - public Date[] dateArrRaw; - - /** */ - public TestEnum[] eArr; - - /** */ - public TestEnum[] eArrRaw; - - /** */ - public Object[] objArr; - - /** */ - public Object[] objArrRaw; - - /** */ - public Collection<String> col; - - /** */ - public Collection<String> colRaw; - - /** */ - public Map<Integer, String> map; - - /** */ - public Map<Integer, String> mapRaw; - - /** */ - public ClientTestPortable portable1; - - /** */ - public ClientTestPortable portable2; - - /** */ - public ClientTestPortable portableRaw1; - - /** */ - public ClientTestPortable portableRaw2; - - /** - */ - public ClientTestPortable() { - // No-op. - } - - /** - * @param val Value. - * @param createInner If {@code true} creates nested object. - */ - public ClientTestPortable(int val, boolean createInner) { - b = (byte)val; - bRaw = (byte)(val + 1); - - s = (short)val; - sRaw = (short)(val + 1); - - i = val; - iRaw = i + 1; - - l = val; - lRaw = i + 1; - - f = val + 0.5f; - fRaw = f + 1; - - d = val + 0.5f; - dRaw = d + 1; - - c = (char)val; - cRaw = (char)(val + 1); - - bool = true; - boolRaw = false; - - str = String.valueOf(i); - strRaw = String.valueOf(iRaw); - - uuid = new UUID(i, i); - uuidRaw = new UUID(iRaw, iRaw); - - date = new Date(i); - dateRaw = new Date(iRaw); - - e = enumValue(i); - eRaw = enumValue(iRaw); - - bArr = new byte[]{b, (byte)(b + 1)}; - bArrRaw = new byte[]{bRaw, (byte)(bRaw + 1)}; - - sArr = new short[]{s, (short)(s + 1)}; - sArrRaw = new short[]{sRaw, (short)(sRaw + 1)}; - - iArr = new int[]{i, i + 1}; - iArrRaw = new int[]{iRaw, iRaw + 1}; - - lArr = new long[]{l, l + 1}; - lArrRaw = new long[]{lRaw, lRaw + 1}; - - fArr = new float[]{f, f + 1}; - fArrRaw = new float[]{fRaw, fRaw + 1}; - - dArr = new double[]{d, d + 1}; - dArrRaw = new double[]{dRaw, dRaw + 1}; - - cArr = new char[]{c, (char)(c + 1)}; - cArrRaw = new char[]{cRaw, (char)(cRaw + 1)}; - - boolArr = new boolean[]{true, true}; - boolArrRaw = new boolean[]{true, true}; - - strArr = new String[]{str, str + "1"}; - strArrRaw = new String[]{strRaw, strRaw + "1"}; - - uuidArr = new UUID[]{uuid, new UUID(uuid.getMostSignificantBits() + 1, uuid.getLeastSignificantBits() + 1)}; - uuidArrRaw = new UUID[]{uuidRaw, - new UUID(uuidRaw.getMostSignificantBits() + 1, uuidRaw.getLeastSignificantBits() + 1)}; - - dateArr = new Date[]{date, new Date(date.getTime() + 1)}; - dateArrRaw = new Date[]{dateRaw, new Date(dateRaw.getTime() + 1)}; - - eArr = new TestEnum[]{enumValue(i), enumValue(i + 1)}; - eArrRaw = new TestEnum[]{enumValue(iRaw), enumValue(iRaw + 1)}; - - objArr = new Object[]{uuid, new UUID(uuid.getMostSignificantBits() + 1, uuid.getLeastSignificantBits() + 1)}; - objArrRaw = new Object[]{uuidRaw, - new UUID(uuidRaw.getMostSignificantBits() + 1, uuidRaw.getLeastSignificantBits() + 1)}; - - col = Arrays.asList(str, str + "1"); - colRaw = Arrays.asList(strRaw, strRaw + "1"); - - map = new HashMap<>(); - map.put(1, str); - map.put(2, str + "1"); - - mapRaw = new HashMap<>(); - mapRaw.put(1, strRaw); - mapRaw.put(2, strRaw + "1"); - - if (createInner) { - portable1 = new ClientTestPortable(val + 1, false); - portable2 = portable1; - - portableRaw1 = new ClientTestPortable(val + 2, false); - portableRaw2 = portableRaw1; - } - } - - /** {@inheritDoc} */ - @Override public void writePortable(PortableWriter writer) throws PortableException { - writer.writeByte("_b", b); - writer.writeShort("_s", s); - writer.writeInt("_i", i); - writer.writeLong("_l", l); - writer.writeFloat("_f", f); - writer.writeDouble("_d", d); - writer.writeChar("_c", c); - writer.writeBoolean("_bool", bool); - writer.writeString("_str", str); - writer.writeUuid("_uuid", uuid); - writer.writeDate("_date", date); - writer.writeEnum("_enum", e); - writer.writeByteArray("_bArr", bArr); - writer.writeShortArray("_sArr", sArr); - writer.writeIntArray("_iArr", iArr); - writer.writeLongArray("_lArr", lArr); - writer.writeFloatArray("_fArr", fArr); - writer.writeDoubleArray("_dArr", dArr); - writer.writeCharArray("_cArr", cArr); - writer.writeBooleanArray("_boolArr", boolArr); - writer.writeStringArray("_strArr", strArr); - writer.writeUuidArray("_uuidArr", uuidArr); - writer.writeDateArray("_dateArr", dateArr); - writer.writeEnumArray("_eArr", eArr); - writer.writeObjectArray("_objArr", objArr); - writer.writeCollection("_col", col); - writer.writeMap("_map", map); - writer.writeObject("_portable1", portable1); - writer.writeObject("_portable2", portable2); - - PortableRawWriter raw = writer.rawWriter(); - - raw.writeByte(bRaw); - raw.writeShort(sRaw); - raw.writeInt(iRaw); - raw.writeLong(lRaw); - raw.writeFloat(fRaw); - raw.writeDouble(dRaw); - raw.writeChar(cRaw); - raw.writeBoolean(boolRaw); - raw.writeString(strRaw); - raw.writeUuid(uuidRaw); - raw.writeDate(dateRaw); - raw.writeEnum(eRaw); - raw.writeByteArray(bArrRaw); - raw.writeShortArray(sArrRaw); - raw.writeIntArray(iArrRaw); - raw.writeLongArray(lArrRaw); - raw.writeFloatArray(fArrRaw); - raw.writeDoubleArray(dArrRaw); - raw.writeCharArray(cArrRaw); - raw.writeBooleanArray(boolArrRaw); - raw.writeStringArray(strArrRaw); - raw.writeUuidArray(uuidArrRaw); - raw.writeDateArray(dateArrRaw); - raw.writeEnumArray(eArrRaw); - raw.writeObjectArray(objArrRaw); - raw.writeCollection(colRaw); - raw.writeMap(mapRaw); - raw.writeObject(portableRaw1); - raw.writeObject(portableRaw2); - } - - /** {@inheritDoc} */ - @Override public void readPortable(PortableReader reader) throws PortableException { - b = reader.readByte("_b"); - s = reader.readShort("_s"); - i = reader.readInt("_i"); - l = reader.readLong("_l"); - f = reader.readFloat("_f"); - d = reader.readDouble("_d"); - c = reader.readChar("_c"); - bool = reader.readBoolean("_bool"); - str = reader.readString("_str"); - uuid = reader.readUuid("_uuid"); - date = reader.readDate("_date"); - e = reader.readEnum("_enum", TestEnum.class); - bArr = reader.readByteArray("_bArr"); - sArr = reader.readShortArray("_sArr"); - iArr = reader.readIntArray("_iArr"); - lArr = reader.readLongArray("_lArr"); - fArr = reader.readFloatArray("_fArr"); - dArr = reader.readDoubleArray("_dArr"); - cArr = reader.readCharArray("_cArr"); - boolArr = reader.readBooleanArray("_boolArr"); - strArr = reader.readStringArray("_strArr"); - uuidArr = reader.readUuidArray("_uuidArr"); - dateArr = reader.readDateArray("_dateArr"); - eArr = reader.readEnumArray("_eArr", TestEnum.class); - objArr = reader.readObjectArray("_objArr"); - col = reader.readCollection("_col"); - map = reader.readMap("_map"); - portable1 = (ClientTestPortable)reader.readObject("_portable1"); - portable2 = (ClientTestPortable)reader.readObject("_portable2"); - - PortableRawReader raw = reader.rawReader(); - - bRaw = raw.readByte(); - sRaw = raw.readShort(); - iRaw = raw.readInt(); - lRaw = raw.readLong(); - fRaw = raw.readFloat(); - dRaw = raw.readDouble(); - cRaw = raw.readChar(); - boolRaw = raw.readBoolean(); - strRaw = raw.readString(); - uuidRaw = raw.readUuid(); - dateRaw = raw.readDate(); - eRaw = raw.readEnum(TestEnum.class); - bArrRaw = raw.readByteArray(); - sArrRaw = raw.readShortArray(); - iArrRaw = raw.readIntArray(); - lArrRaw = raw.readLongArray(); - fArrRaw = raw.readFloatArray(); - dArrRaw = raw.readDoubleArray(); - cArrRaw = raw.readCharArray(); - boolArrRaw = raw.readBooleanArray(); - strArrRaw = raw.readStringArray(); - uuidArrRaw = raw.readUuidArray(); - dateArrRaw = raw.readDateArray(); - eArrRaw = raw.readEnumArray(TestEnum.class); - objArrRaw = raw.readObjectArray(); - colRaw = raw.readCollection(); - mapRaw = raw.readMap(); - portableRaw1 = (ClientTestPortable)raw.readObject(); - portableRaw2 = (ClientTestPortable)raw.readObject(); - } - - /** - * @param idx Value index. - * @return Enum value. - */ - static TestEnum enumValue(int idx) { - return TestEnum.values()[idx % TestEnum.values().length]; - } - - /** - * Test enum. - */ - private enum TestEnum { - /** */ - VAL1, - - /** */ - VAL2, - - /** */ - VAl3, - - /** */ - VAL4, - - /** */ - VAL5, - - /** */ - VAL6, - - /** */ - VAL7, - - /** */ - VAL8, - - /** */ - VAL9, - - /** */ - VAL10 - } - - /** {@inheritDoc} */ - @Override public String toString() { - return S.toString(ClientTestPortable.class, this); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortableAffinityKeyTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortableAffinityKeyTask.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortableAffinityKeyTask.java deleted file mode 100644 index 855c3d2..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestPortableAffinityKeyTask.java +++ /dev/null @@ -1,85 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.cluster.*; -import org.apache.ignite.compute.*; -import org.apache.ignite.portables.*; -import org.apache.ignite.resources.*; -import org.jetbrains.annotations.*; - -import java.util.*; - -/** - * Task used to test portable affinity key. - */ -public class ClientTestPortableAffinityKeyTask extends ComputeTaskAdapter<Object, Boolean> { - /** */ - @IgniteInstanceResource - private Ignite ignite; - - /** {@inheritDoc} */ - @Nullable @Override public Map<? extends ComputeJob, ClusterNode> map(List<ClusterNode> clusterNodes, - @Nullable final Object arg) throws IgniteCheckedException { - for (ClusterNode node : clusterNodes) { - if (node.isLocal()) - return Collections.singletonMap(new ComputeJobAdapter() { - @Override public Object execute() throws IgniteCheckedException { - return executeJob(arg); - } - }, node); - } - - throw new IgniteCheckedException("Failed to find local node in task topology: " + clusterNodes); - } - - /** {@inheritDoc} */ - @Nullable @Override public Boolean reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - return results.get(0).getData(); - } - - /** - * @param arg Argument. - * @return Execution result. - * @throws IgniteCheckedException If failed. - */ - protected Boolean executeJob(Object arg) throws IgniteCheckedException { - Collection args = (Collection)arg; - - Iterator<Object> it = args.iterator(); - - assert args.size() == 3 : args.size(); - - PortableObject obj = (PortableObject)it.next(); - - String cacheName = (String)it.next(); - - String expAffKey = (String)it.next(); - - Object affKey = ignite.cache(cacheName).affinity().affinityKey(obj); - - if (!expAffKey.equals(affKey)) - throw new IgniteCheckedException("Unexpected affinity key: " + affKey); - - if (!ignite.cache(cacheName).affinity().mapKeyToNode(obj).isLocal()) - throw new IgniteCheckedException("Job is not run on primary node."); - - return true; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientTestRestServer.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestRestServer.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTestRestServer.java deleted file mode 100644 index d25120e..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTestRestServer.java +++ /dev/null @@ -1,275 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.internal.client.marshaller.*; -import org.apache.ignite.internal.client.marshaller.optimized.*; -import org.apache.ignite.internal.processors.rest.client.message.*; -import org.apache.ignite.internal.processors.rest.protocols.tcp.*; -import org.apache.ignite.internal.util.nio.*; -import org.jetbrains.annotations.*; - -import java.net.*; -import java.nio.*; -import java.util.*; -import java.util.concurrent.*; -import java.util.concurrent.atomic.*; - -/** - * - */ -public class ClientTestRestServer { - /** */ - public static final int FIRST_SERVER_PORT = 11000; - - /** */ - public static final int SERVERS_CNT = 5; - - /** */ - private static final byte[] EMPTY_SES_TOKEN = new byte[] {}; - - /** */ - private static final Collection<GridClientNodeBean> top = new ArrayList<>(); - - /** - * - */ - static { - for (int port = FIRST_SERVER_PORT; port < FIRST_SERVER_PORT + SERVERS_CNT; port++) { - GridClientNodeBean node = new GridClientNodeBean(); - - node.setNodeId(UUID.randomUUID()); - node.setConsistentId("127.0.0.1:" + port); - node.setTcpPort(port); - node.setTcpAddresses(Arrays.asList("127.0.0.1")); - - top.add(node); - } - } - - /** */ - private final int port; - - /** */ - private volatile boolean failOnConnect; - - /** */ - private final IgniteLogger log; - - /** */ - private final AtomicInteger connCnt = new AtomicInteger(); - - /** */ - private final AtomicInteger succConnCnt = new AtomicInteger(); - - /** */ - private final AtomicInteger disconnCnt = new AtomicInteger(); - - /** */ - private GridNioServer<GridClientMessage> srv; - - /** */ - private volatile GridNioSession lastSes; - - /** - * @param port Port to listen on. - * @param failOnConnect If {@code true} than server will close connection immediately after connect. - * @param log Log. - */ - public ClientTestRestServer(int port, boolean failOnConnect, IgniteLogger log) { - this.port = port; - this.failOnConnect = failOnConnect; - this.log = log; - } - - /** - * @return Port number. - */ - public int getPort() { - return port; - } - - /** - * Starts the server. - * - * @throws IgniteCheckedException If failed. - */ - public void start() throws IgniteCheckedException { - try { - String gridName = "test"; - - srv = GridNioServer.<GridClientMessage>builder() - .address(InetAddress.getByName("127.0.0.1")) - .port(port) - .listener(new TestListener()) - .logger(log) - .selectorCount(2) - .gridName(gridName) - .byteOrder(ByteOrder.nativeOrder()) - .tcpNoDelay(true) - .directBuffer(false) - .filters( - new GridNioAsyncNotifyFilter(gridName, Executors.newFixedThreadPool(2), log), - new GridNioCodecFilter(new TestParser(), log, false) - ) - .build(); - } - catch (UnknownHostException e) { - throw new IgniteCheckedException("Failed to determine localhost address.", e); - } - - srv.start(); - } - - /** - * Stops the server. - */ - public void stop() { - assert srv != null; - - srv.stop(); - } - - /** - * @return Number of connections opened to this server. - */ - public int getConnectCount() { - return connCnt.get(); - } - - /** - * @return Number of successful connections opened to this server. - */ - public int getSuccessfulConnectCount() { - return succConnCnt.get(); - } - - /** - * @return Number of connections with this server closed by clients. - */ - public int getDisconnectCount() { - return disconnCnt.get(); - } - - /** - * Closes all opened connections. - */ - public void fail() { - assert lastSes != null; - - lastSes.close(); - - failOnConnect = true; - - resetCounters(); - } - - /** - * - */ - public void repair() { - failOnConnect = false; - } - - /** - * Resets all counters. - */ - public void resetCounters() { - connCnt.set(0); - succConnCnt.set(0); - disconnCnt.set(0); - } - - /** - * Prepares response stub. - * @param msg Mesage to respond to. - * @return Response. - */ - private static GridClientResponse makeResponseFor(GridClientMessage msg) { - GridClientResponse res = new GridClientResponse(); - - res.clientId(msg.clientId()); - res.requestId(msg.requestId()); - res.successStatus(GridClientResponse.STATUS_SUCCESS); - res.sessionToken(EMPTY_SES_TOKEN); - - return res; - } - - /** - * Test listener. - */ - private class TestListener extends GridNioServerListenerAdapter<GridClientMessage> { - /** {@inheritDoc} */ - @Override public void onConnected(GridNioSession ses) { - lastSes = ses; - - connCnt.incrementAndGet(); - - if (failOnConnect) - ses.close(); - else - succConnCnt.incrementAndGet(); - } - - /** {@inheritDoc} */ - @Override public void onDisconnected(GridNioSession ses, @Nullable Exception e) { - disconnCnt.incrementAndGet(); - } - - /** {@inheritDoc} */ - @Override public void onMessage(GridNioSession ses, GridClientMessage msg) { - if (msg == GridClientPingPacket.PING_MESSAGE) - ses.send(GridClientPingPacket.PING_MESSAGE); - else if (msg instanceof GridClientAuthenticationRequest) - ses.send(makeResponseFor(msg)); - else if (msg instanceof GridClientTopologyRequest) { - GridClientResponse res = makeResponseFor(msg); - - res.result(top); - - ses.send(res); - } - else if (msg instanceof GridClientHandshakeRequest) - ses.send(GridClientHandshakeResponse.OK); - } - - /** {@inheritDoc} */ - @Override public void onSessionWriteTimeout(GridNioSession ses) { - ses.close(); - } - - /** {@inheritDoc} */ - @Override public void onSessionIdleTimeout(GridNioSession ses) { - ses.close(); - } - } - - /** - */ - private static class TestParser extends GridTcpRestParser { - /** */ - private final GridClientMarshaller marsh = new GridClientOptimizedMarshaller(); - - /** {@inheritDoc} */ - @Override protected GridClientMarshaller marshaller(GridNioSession ses) { - return marsh; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/ClientTopologyCacheSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/ClientTopologyCacheSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/ClientTopologyCacheSelfTest.java deleted file mode 100644 index 8c02c01..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/ClientTopologyCacheSelfTest.java +++ /dev/null @@ -1,290 +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.client; - -import org.apache.ignite.cache.*; -import org.apache.ignite.configuration.*; -import org.apache.ignite.internal.client.*; -import org.apache.ignite.spi.discovery.tcp.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.*; -import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.*; - -import static org.apache.ignite.IgniteSystemProperties.*; -import static org.apache.ignite.cache.CacheMode.*; -import static org.apache.ignite.cache.CacheWriteSynchronizationMode.*; - -/** - * Tests topology caching. - */ -public class ClientTopologyCacheSelfTest extends GridCommonAbstractTest { - static { - // Override default port. - System.setProperty(IGNITE_JETTY_PORT, Integer.toString(8081)); - } - - /** Host. */ - public static final String HOST = "127.0.0.1"; - - /** Port. */ - public static final int BINARY_PORT = 11212; - - /** Cache name. */ - private static final String CACHE_NAME = "cache"; - - /** */ - private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true); - - /** {@inheritDoc} */ - @Override protected void beforeTestsStarted() throws Exception { - startGrid(); - } - - /** {@inheritDoc} */ - @Override protected void afterTestsStopped() throws Exception { - stopGrid(); - } - - /** - * @throws Exception If failed. - */ - public void testTopologyCache() throws Exception { - testTopologyCache( - true, // metricsCache - true, // attrsCache - false,// autoFetchMetrics - false,// autoFetchAttrs - false,// metricsBeforeRefresh - false,// attrsBeforeRefresh - true, // metricsAfterRefresh - true);// attrsAfterRefresh - - testTopologyCache( - false, // metricsCache - false, // attrsCache - false,// autoFetchMetrics - false,// autoFetchAttrs - false, // metricsBeforeRefresh - false, // attrsBeforeRefresh - false, // metricsAfterRefresh - false);// attrsAfterRefresh - - testTopologyCache( - true, // metricsCache - false, // attrsCache - false, // autoFetchMetrics - false, // autoFetchAttrs - false, // metricsBeforeRefresh - false, // attrsBeforeRefresh - true, // metricsAfterRefresh - false);// attrsAfterRefresh - - testTopologyCache( - false, // metricsCache - true, // attrsCache - false, // autoFetchMetrics - false, // autoFetchAttrs - false, // metricsBeforeRefresh - false, // attrsBeforeRefresh - false, // metricsAfterRefresh - true); // attrsAfterRefresh - } - - public void testAutofetch() throws Exception { - testTopologyCache( - true, // metricsCache - true, // attrsCache - true, // autoFetchMetrics - true, // autoFetchAttrs - true, // metricsBeforeRefresh - true, // attrsBeforeRefresh - true, // metricsAfterRefresh - true);// attrsAfterRefresh - - testTopologyCache( - true, // metricsCache - true, // attrsCache - false,// autoFetchMetrics - true, // autoFetchAttrs - false,// metricsBeforeRefresh - true, // attrsBeforeRefresh - true, // metricsAfterRefresh - true);// attrsAfterRefresh - - testTopologyCache( - true, // metricsCache - true, // attrsCache - true, // autoFetchMetrics - false,// autoFetchAttrs - true, // metricsBeforeRefresh - false,// attrsBeforeRefresh - true, // metricsAfterRefresh - true);// attrsAfterRefresh - - testTopologyCache( - true, // metricsCache - true, // attrsCache - false,// autoFetchMetrics - false,// autoFetchAttrs - false,// metricsBeforeRefresh - false,// attrsBeforeRefresh - true, // metricsAfterRefresh - true);// attrsAfterRefresh - } - - /** - * Starts new client with the given caching configuration and refreshes topology, - * Checks node metrics and attributes availability according to the given flags - * before and after refresh. - * - * @param metricsCache Should metrics be cached? - * @param attrsCache Should attributes be cached? - * @param autoFetchMetrics Should metrics be fetched automatically? - * @param autoFetchAttrs Should attributes be fetched automatically? - * @param metricsBeforeRefresh Should metrics be available before topology refresh? - * @param attrsBeforeRefresh Should attributes be available before topology refresh? - * @param metricsAfterRefresh Should metrics be available after topology refresh? - * @param attrsAfterRefresh Should attributes be available after topology refresh? - * @throws Exception If failed. - */ - private void testTopologyCache(boolean metricsCache, boolean attrsCache, - boolean autoFetchMetrics, boolean autoFetchAttrs, - boolean metricsBeforeRefresh, boolean attrsBeforeRefresh, - boolean metricsAfterRefresh, boolean attrsAfterRefresh) throws Exception { - GridClient client = client(metricsCache, attrsCache, autoFetchMetrics, autoFetchAttrs); - - try { - // Exclude cache metrics because there is no background refresh for them. - assertEquals(metricsBeforeRefresh, metricsAvailable(client, false)); - assertEquals(attrsBeforeRefresh, attrsAvailable(client)); - - client.compute().refreshTopology(true, true); - client.data(CACHE_NAME).metrics(); - - assertEquals(metricsAfterRefresh, metricsAvailable(client, true)); - assertEquals(attrsAfterRefresh, attrsAvailable(client)); - } - finally { - GridClientFactory.stop(client.id(), false); - } - } - - /** - * @param client Client instance. - * @param includeCache If {@code true} then cache metrics should be considered - * and their consistency with node metrics should be asserted, otherwise consider only node metrics. - * @return {@code true} if node metrics available through this client, - * {@code false} otherwise. - * @throws GridClientException If data projection is not available. - */ - private boolean metricsAvailable(GridClient client, boolean includeCache) throws GridClientException { - if (includeCache) { - boolean node = nodeMetricsAvailable(client); - boolean cache = client.data(CACHE_NAME).cachedMetrics() != null; - - assertTrue("Inconsistency between cache and node metrics cache.", node == cache); - - return node && cache; - } - else - return nodeMetricsAvailable(client); - } - - /** - * @param client Client instance. - * @return {@code true} if node node metrics available through this client, - * {@code false} otherwise. - */ - private boolean nodeMetricsAvailable(GridClient client) throws GridClientException { - for (GridClientNode node : client.compute().nodes()) - if (node.metrics() != null) - return true; - - return false; - } - - /** - * @param client Client instance. - * @return {@code true} if node attributes available through this client, - * {@code false} otherwise. - */ - private boolean attrsAvailable(GridClient client) throws GridClientException { - for (GridClientNode node : client.compute().nodes()) - if (node.attributes() != null && !node.attributes().isEmpty()) - return true; - - return false; - } - - /** - * @param metricsCache Should metrics cache be enabled? - * @param attrsCache Should attributes cache be enabled? - * @return Client. - * @throws GridClientException In case of error. - */ - private GridClient client(boolean metricsCache, boolean attrsCache, - boolean autoFetchMetrics, boolean autoFetchAttrs) throws GridClientException { - GridClientDataConfiguration cache = new GridClientDataConfiguration(); - - cache.setName(CACHE_NAME); - - GridClientConfiguration cfg = new GridClientConfiguration(); - - cfg.setServers(Arrays.asList(HOST + ":" + BINARY_PORT)); - cfg.setEnableMetricsCache(metricsCache); - cfg.setEnableAttributesCache(attrsCache); - cfg.setAutoFetchMetrics(autoFetchMetrics); - cfg.setAutoFetchAttributes(autoFetchAttrs); - cfg.setDataConfigurations(Collections.singleton(cache)); - - return GridClientFactory.start(cfg); - } - - /** {@inheritDoc} */ - @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { - CacheConfiguration cacheCfg = defaultCacheConfiguration(); - - cacheCfg.setCacheMode(LOCAL); - cacheCfg.setName(CACHE_NAME); - cacheCfg.setWriteSynchronizationMode(FULL_SYNC); - cacheCfg.setSwapEnabled(false); - - TcpDiscoverySpi disco = new TcpDiscoverySpi(); - - disco.setIpFinder(IP_FINDER); - - IgniteConfiguration cfg = super.getConfiguration(gridName); - - cfg.setLocalHost(HOST); - - assert cfg.getClientConnectionConfiguration() == null; - - ClientConnectionConfiguration clientCfg = new ClientConnectionConfiguration(); - - clientCfg.setRestTcpPort(BINARY_PORT); - - cfg.setClientConnectionConfiguration(clientCfg); - - cfg.setCacheConfiguration(cacheCfg); - cfg.setDiscoverySpi(disco); - - return cfg; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/HashMapStore.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/HashMapStore.java b/modules/clients/src/test/java/org/apache/ignite/client/HashMapStore.java deleted file mode 100644 index 6ed392c..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/HashMapStore.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.apache.ignite.client; - -import org.apache.ignite.cache.store.*; -import org.apache.ignite.lang.*; - -import javax.cache.*; -import java.util.*; - -/** - * Simple HashMap based cache store emulation. - */ -public class HashMapStore extends CacheStoreAdapter { - /** Map for cache store. */ - private final Map<Object, Object> map = new HashMap<>(); - - /** {@inheritDoc} */ - @Override public void loadCache(IgniteBiInClosure c, Object... args) { - for (Map.Entry e : map.entrySet()) - c.apply(e.getKey(), e.getValue()); - } - - /** {@inheritDoc} */ - @Override public Object load(Object key) { - return map.get(key); - } - - /** {@inheritDoc} */ - @Override public void write(Cache.Entry e) { - map.put(e.getKey(), e.getValue()); - } - - /** {@inheritDoc} */ - @Override public void delete(Object key) { - map.remove(key); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/SleepTestTask.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/SleepTestTask.java b/modules/clients/src/test/java/org/apache/ignite/client/SleepTestTask.java deleted file mode 100644 index f59d16e..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/SleepTestTask.java +++ /dev/null @@ -1,68 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; - -import java.util.*; - -import static org.apache.ignite.compute.ComputeJobResultPolicy.*; - -/** - * Test task, that sleeps for 10 seconds in split and returns - * the length of an argument. - */ -public class SleepTestTask extends ComputeTaskSplitAdapter<String, Integer> { - /** {@inheritDoc} */ - @Override public Collection<? extends ComputeJob> split(int gridSize, String arg) - throws IgniteCheckedException { - return Collections.singleton(new ComputeJobAdapter(arg) { - @Override public Object execute() { - try { - Thread.sleep(10000); - - String val = argument(0); - - return val == null ? 0 : val.length(); - } - catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - }); - } - - /** {@inheritDoc} */ - @Override public Integer reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - int sum = 0; - - for (ComputeJobResult res : results) - sum += res.<Integer>getData(); - - return sum; - } - - /** {@inheritDoc} */ - @Override public ComputeJobResultPolicy result(ComputeJobResult res, List<ComputeJobResult> rcvd) throws IgniteCheckedException { - if (res.getException() != null) - return FAILOVER; - - return WAIT; - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/TaskSingleJobSplitAdapter.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/TaskSingleJobSplitAdapter.java b/modules/clients/src/test/java/org/apache/ignite/client/TaskSingleJobSplitAdapter.java deleted file mode 100644 index 13b0687..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/TaskSingleJobSplitAdapter.java +++ /dev/null @@ -1,75 +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.client; - -import org.apache.ignite.*; -import org.apache.ignite.compute.*; - -import java.util.*; - -/** - * Adapter for {@link org.apache.ignite.compute.ComputeTaskSplitAdapter} - * overriding {@code split(...)} method to return singleton with self instance. - * This adapter should be used for tasks that always splits to a single task. - * @param <T> Type of the task execution argument. - * @param <R> Type of the task result returning from {@link org.apache.ignite.compute.ComputeTask#reduce(List)} method. - */ -public abstract class TaskSingleJobSplitAdapter<T, R> extends ComputeTaskSplitAdapter<T, R> { - /** Empty constructor. */ - protected TaskSingleJobSplitAdapter() { - // No-op. - } - - /** {@inheritDoc} */ - @Override protected Collection<? extends ComputeJob> split(final int gridSize, final T arg) throws IgniteCheckedException { - return Collections.singleton(new ComputeJobAdapter() { - @Override public Object execute() throws IgniteCheckedException { - return executeJob(gridSize, arg); - } - }); - } - - /** {@inheritDoc} */ - @Override public R reduce(List<ComputeJobResult> results) throws IgniteCheckedException { - assert results.size() == 1; - - ComputeJobResult res = results.get(0); - - if (res.isCancelled()) - throw new IgniteCheckedException("Reduce receives failed job."); - - return res.getData(); - } - - /** - * Executes this task's job. - * - * @param gridSize Number of available grid nodes. Note that returned number of - * jobs can be less, equal or greater than this grid size. - * @param arg Task execution argument. Can be {@code null}. - * @return Job execution result (possibly {@code null}). This result will be returned - * in {@link org.apache.ignite.compute.ComputeJobResult#getData()} method passed into - * {@link org.apache.ignite.compute.ComputeTask#result(org.apache.ignite.compute.ComputeJobResult, List)} method into task on caller node. - * @throws IgniteCheckedException If job execution caused an exception. This exception will be - * returned in {@link org.apache.ignite.compute.ComputeJobResult#getException()} method passed into - * {@link org.apache.ignite.compute.ComputeTask#result(org.apache.ignite.compute.ComputeJobResult, List)} method into task on caller node. - * If execution produces a {@link RuntimeException} or {@link Error}, then - * it will be wrapped into {@link IgniteCheckedException}. - */ - protected abstract Object executeJob(int gridSize, T arg) throws IgniteCheckedException; -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientCacheFlagsCodecTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientCacheFlagsCodecTest.java b/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientCacheFlagsCodecTest.java deleted file mode 100644 index 8e31476..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientCacheFlagsCodecTest.java +++ /dev/null @@ -1,83 +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.client.impl; - -import junit.framework.*; -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.client.impl.connection.*; -import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.processors.rest.handlers.cache.*; -import org.apache.ignite.internal.util.typedef.*; - -import java.util.*; - -import static org.apache.ignite.internal.client.GridClientCacheFlag.*; - -/** - * Tests conversions between GridClientCacheFlag and CacheFlag. - */ -public class ClientCacheFlagsCodecTest extends TestCase { - /** - * Tests that each client flag will be correctly converted to server flag. - */ - public void testEncodingDecodingFullness() { - for (GridClientCacheFlag f : GridClientCacheFlag.values()) { - if (f == KEEP_PORTABLES) - continue; - - int bits = GridClientConnection.encodeCacheFlags(Collections.singleton(f)); - - assertTrue(bits != 0); - - CacheFlag[] out = GridCacheCommandHandler.parseCacheFlags(bits); - assertEquals(1, out.length); - - assertEquals(f.name(), out[0].name()); - } - } - - /** - * Tests that groups of client flags can be correctly converted to corresponding server flag groups. - */ - public void testGroupEncodingDecoding() { - // all - doTestGroup(GridClientCacheFlag.values()); - // none - doTestGroup(); - // some - doTestGroup(GridClientCacheFlag.INVALIDATE); - } - - /** - * @param flags Client flags to be encoded, decoded and checked. - */ - private void doTestGroup(GridClientCacheFlag... flags) { - EnumSet<GridClientCacheFlag> flagSet = F.isEmpty(flags) ? EnumSet.noneOf(GridClientCacheFlag.class) : - EnumSet.copyOf(Arrays.asList(flags)); - - int bits = GridClientConnection.encodeCacheFlags(flagSet); - - CacheFlag[] out = GridCacheCommandHandler.parseCacheFlags(bits); - - assertEquals(flagSet.contains(KEEP_PORTABLES) ? flagSet.size() - 1 : flagSet.size(), out.length); - - for (CacheFlag f : out) { - assertTrue(flagSet.contains(GridClientCacheFlag.valueOf(f.name()))); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientComputeImplSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientComputeImplSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientComputeImplSelfTest.java deleted file mode 100644 index f3bc0a9..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientComputeImplSelfTest.java +++ /dev/null @@ -1,168 +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.client.impl; - -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.client.impl.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.*; -import java.util.concurrent.*; - -import static org.apache.ignite.testframework.GridTestUtils.*; - -/** - * Simple unit test for GridClientComputeImpl which checks method parameters. - * It tests only those methods that can produce assertion underneath upon incorrect arguments. - */ -public class ClientComputeImplSelfTest extends GridCommonAbstractTest { - /** Mocked client compute. */ - private GridClientCompute compute = allocateInstance0(GridClientComputeImpl.class); - - /** - * @throws Exception If failed. - */ - public void testProjection_byGridClientNode() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.projection((GridClientNode)null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: node"); - } - - /** - * @throws Exception If failed. - */ - public void testExecute() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.execute(null, null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: taskName"); - } - - /** - * @throws Exception If failed. - */ - public void testExecuteAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.executeAsync(null, null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: taskName"); - } - - /** - * @throws Exception If failed. - */ - public void testAffinityExecute() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.affinityExecute(null, "cache", "key", null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: taskName"); - } - - /** - * @throws Exception If failed. - */ - public void testAffinityExecuteAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.affinityExecute(null, "cache", "key", null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: taskName"); - } - - /** - * @throws Exception If failed. - */ - public void testNode() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.node(null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: id"); - } - - /** - * @throws Exception If failed. - */ - public void testNodesByIds() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.nodes((Collection<UUID>)null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: ids"); - } - - /** - * @throws Exception If failed. - */ - public void testNodesByFilter() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.nodes((GridClientPredicate<GridClientNode>)null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: filter"); - } - - /** - * @throws Exception If failed. - */ - public void testRefreshNodeById() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.refreshNode((UUID)null, false, false); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: id"); - } - - /** - * @throws Exception If failed. - */ - public void testRefreshNodeByIdAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.refreshNodeAsync((UUID)null, false, false); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: id"); - } - - /** - * @throws Exception If failed. - */ - public void testRefreshNodeByIp() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.refreshNode((String)null, false, false); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: ip"); - } - - /** - * @throws Exception If failed. - */ - public void testRefreshNodeByIpAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return compute.refreshNode((String)null, false, false); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: ip"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientDataImplSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientDataImplSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientDataImplSelfTest.java deleted file mode 100644 index fbdfe3c..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientDataImplSelfTest.java +++ /dev/null @@ -1,269 +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.client.impl; - -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.client.impl.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.concurrent.*; - -import static org.apache.ignite.testframework.GridTestUtils.*; - -/** - * Simple unit test for GridClientDataImpl which checks method parameters. - */ -public class ClientDataImplSelfTest extends GridCommonAbstractTest { - /** Mocked client data. */ - private GridClientData data = allocateInstance0(GridClientDataImpl.class); - - /** - * @throws Exception If failed. - */ - public void testPut() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.put(null, "val"); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.put("key", null); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: val"); - } - - /** - * @throws Exception If failed. - */ - public void testPutAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.putAsync(null, "val"); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.putAsync("key", null); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: val"); - } - - /** - * @throws Exception If failed. - */ - public void testPutAll() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.putAll(null); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: entries"); - } - - /** - * @throws Exception If failed. - */ - public void testPutAllAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.putAllAsync(null); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: entries"); - } - - /** - * @throws Exception If failed. - */ - public void testGet() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return data.get(null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - } - - /** - * @throws Exception If failed. - */ - public void testGetAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return data.getAsync(null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - } - - /** - * @throws Exception If failed. - */ - public void testGetAll() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return data.getAll(null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: keys"); - } - - /** - * @throws Exception If failed. - */ - public void testGetAllAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return data.getAllAsync(null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: keys"); - } - - /** - * @throws Exception If failed. - */ - public void testRemove() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.remove(null); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - } - - /** - * @throws Exception If failed. - */ - public void testRemoveAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return data.removeAsync(null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - } - - /** - * @throws Exception If failed. - */ - public void testRemoveAll() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.removeAll(null); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: keys"); - } - - /** - * @throws Exception If failed. - */ - public void testRemoveAllAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.removeAllAsync(null); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: keys"); - } - - /** - * @throws Exception If failed. - */ - public void testReplace() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.replace(null, "val"); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.replace("key", null); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: val"); - } - - /** - * @throws Exception If failed. - */ - public void testReplaceAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return data.replaceAsync(null, "val"); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return data.replaceAsync("key", null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: val"); - } - - /** - * @throws Exception If failed. - */ - public void testCas() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - data.cas(null, "val1", "val2"); - - return null; - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - } - - /** - * @throws Exception If failed. - */ - public void testCasAsync() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return data.casAsync(null, "val1", "val2"); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - } - - /** - * @throws Exception If failed. - */ - public void testAffinity() throws Exception { - assertThrows(log, new Callable<Object>() { - @Override public Object call() throws Exception { - return data.affinity(null); - } - }, NullPointerException.class, "Ouch! Argument cannot be null: key"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/756034f3/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientFutureAdapterSelfTest.java ---------------------------------------------------------------------- diff --git a/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientFutureAdapterSelfTest.java b/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientFutureAdapterSelfTest.java deleted file mode 100644 index 5aac9bf..0000000 --- a/modules/clients/src/test/java/org/apache/ignite/client/impl/ClientFutureAdapterSelfTest.java +++ /dev/null @@ -1,116 +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.client.impl; - -import org.apache.ignite.internal.client.*; -import org.apache.ignite.internal.client.impl.*; -import org.apache.ignite.testframework.junits.common.*; - -import java.util.*; -import java.util.concurrent.*; - -/** - * Grid client future implementation self test. - */ -public class ClientFutureAdapterSelfTest extends GridCommonAbstractTest { - /** - * Test finished futures. - */ - public void testFinished() { - GridClientFutureAdapter<Integer> fut = new GridClientFutureAdapter<>(); - - assertFalse(fut.isDone()); - - fut.onDone(0); - - assertTrue(fut.isDone()); - assertTrue(new GridClientFutureAdapter<>(0).isDone()); - assertTrue(new GridClientFutureAdapter<Integer>(new GridClientException("Test grid exception.")).isDone()); - assertTrue(new GridClientFutureAdapter<Integer>(new RuntimeException("Test runtime exception.")).isDone()); - } - - /** - * Test chained futures behaviour. - * - * @throws org.apache.ignite.internal.client.GridClientException On any exception. - */ - public void testChains() throws GridClientException { - // Synchronous notifications. - testChains(1, 100); - testChains(10, 10); - testChains(100, 1); - testChains(1000, 0); - } - - /** - * Test chained future in certain conditions. - * - * @param chainSize Futures chain size. - * @param waitDelay Delay to wait each future in the chain becomes done. - * @throws GridClientException In case of any exception - */ - private void testChains(int chainSize, long waitDelay) throws GridClientException { - /* Base future to chain from. */ - GridClientFutureAdapter<Integer> fut = new GridClientFutureAdapter<>(); - - /* Collection of chained futures: fut->chained[0]->chained[1]->...->chained[chainSize - 1] */ - List<GridClientFutureAdapter<Integer>> chained = new ArrayList<>(); - - GridClientFutureAdapter<Integer> cur = fut; - - for (int i = 0; i < chainSize; i++) { - cur = cur.chain(new GridClientFutureCallback<Integer, Integer>() { - @Override public Integer onComplete(GridClientFuture<Integer> f) throws GridClientException { - assertTrue("Expects callback future is finished.", f.isDone()); - - return f.get() + 1; - } - }); - - chained.add(cur); - } - - long start; - - /* Validate not-finished futures in chain. */ - for (GridClientFuture<Integer> f : chained) { - assertFalse(f.isDone()); - - start = System.currentTimeMillis(); - - try { - f.get(waitDelay, TimeUnit.MILLISECONDS); - - fail("Expects chained future not finished yet."); - } - catch (GridClientFutureTimeoutException ignore) { - /* No op: expects chained future not finished yet. */ - } - - assertTrue(System.currentTimeMillis() - start >= waitDelay); - } - - /* Calculate 'count' chained futures time consumption. */ - start = System.currentTimeMillis(); - - fut.onDone(0); - assertEquals("Check chain-based increment value.", chainSize, chained.get(chainSize - 1).get().intValue()); - - info("Time consumption for " + chainSize + " chained futures: " + (System.currentTimeMillis() - start)); - } -}