You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2021/08/13 16:48:02 UTC

[GitHub] [ignite-3] ptupitsyn opened a new pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

ptupitsyn opened a new pull request #283:
URL: https://github.com/apache/ignite-3/pull/283


   Start client-handler module when the node starts.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] ptupitsyn commented on a change in pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #283:
URL: https://github.com/apache/ignite-3/pull/283#discussion_r690440277



##########
File path: modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ITThinClientConnectionTest.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.runner.app;
+
+import java.lang.reflect.Field;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import com.google.common.collect.Lists;
+import org.apache.ignite.app.Ignite;
+import org.apache.ignite.app.IgnitionManager;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.handler.ClientHandlerModule;
+import org.apache.ignite.internal.app.IgnitionImpl;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.schema.ColumnType;
+import org.apache.ignite.schema.SchemaBuilders;
+import org.apache.ignite.schema.SchemaTable;
+import org.apache.ignite.table.Table;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests thin client connecting to a real server node.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+public class ITThinClientConnectionTest extends IgniteAbstractTest {
+    /** */
+    private static final String SCHEMA_NAME = "PUB";
+
+    /** */
+    private static final String TABLE_NAME = "tbl1";
+
+    /** Nodes bootstrap configuration. */
+    private static final Map<String, String> nodesBootstrapCfg = new LinkedHashMap<>() {{
+        put("node0", "{\n" +
+                "  \"node\": {\n" +
+                "    \"metastorageNodes\":[ \"node0\" ]\n" +
+                "  },\n" +
+                "  \"network\": {\n" +
+                "    \"port\":3344,\n" +
+                "    \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\" ]\n" +
+                "  }\n" +
+                "}");
+
+        put("node1", "{\n" +
+                "  \"node\": {\n" +
+                "    \"metastorageNodes\":[ \"node0\" ]\n" +
+                "  },\n" +
+                "  \"network\": {\n" +
+                "    \"port\":3345,\n" +
+                "    \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\" ]\n" +
+                "  }\n" +
+                "}");
+        }};
+
+    /** */
+    private final List<Ignite> startedNodes = new ArrayList<>();
+
+    /** */
+    @AfterEach
+    void tearDown() throws Exception {
+        IgniteUtils.closeAll(Lists.reverse(startedNodes));
+    }
+
+    /**
+     * Check that thin client can connect to any server node and work with table API.
+     */
+    @Test
+    void testThinClientConnectsToServerNodesAndExecutesBasicTableOperations() throws Exception {
+        nodesBootstrapCfg.forEach((nodeName, configStr) ->
+                startedNodes.add(IgnitionManager.start(nodeName, configStr, workDir.resolve(nodeName)))
+        );
+
+        var keyCol = "key";
+        var valCol = "val";
+
+        SchemaTable schTbl = SchemaBuilders.tableBuilder(SCHEMA_NAME, TABLE_NAME).columns(
+                SchemaBuilders.column(keyCol, ColumnType.INT32).asNonNull().build(),
+                SchemaBuilders.column(valCol, ColumnType.string()).asNullable().build()
+        ).withPrimaryKey(keyCol).build();
+
+        startedNodes.get(0).tables().createTable(schTbl.canonicalName(), tblCh ->
+                SchemaConfigurationConverter.convert(schTbl, tblCh)
+                        .changeReplicas(1)
+                        .changePartitions(10)
+        );
+
+        var addrs = new String[]{"127.0.0.1:" + getClientPort("node0"), "127.0.0.1:" + getClientPort("node1")};
+
+        for (var addr : addrs) {
+            try (var client = IgniteClient.builder().addresses(addr).build()) {
+                List<Table> tables = client.tables().tables();
+                assertEquals(1, tables.size());
+
+                Table table = tables.get(0);
+                assertEquals(String.format("%s.%s", SCHEMA_NAME, TABLE_NAME), table.tableName());
+
+                var tuple = table.tupleBuilder().set(keyCol, 1).set(valCol, "Hello").build();
+                var keyTuple = table.tupleBuilder().set(keyCol, 1).build();
+
+                table.upsert(tuple);
+                assertEquals("Hello", table.get(keyTuple).stringValue(valCol));
+
+                assertTrue(table.delete(keyTuple));
+            }
+        }
+    }
+
+    /**
+     * Gets the client listener port.
+     *
+     * @param nodeName Node name.
+     * @return Port number.
+     * @throws Exception When failed.
+     */
+    private static int getClientPort(String nodeName) throws Exception {
+        InetSocketAddress addr = (InetSocketAddress) getClientHandlerModule(nodeName).localAddress();
+        assertNotNull(addr);
+
+        return addr.getPort();
+    }
+
+    /**
+     * Gets the client handler module for the give node.
+     *
+     * @param nodeName Node name.
+     * @return Client handler module.
+     * @throws Exception When failed.
+     */
+    private static ClientHandlerModule getClientHandlerModule(String nodeName) throws Exception {
+        Field field = IgnitionImpl.class.getDeclaredField("nodesStartedComponents");

Review comment:
       There is no guarantee that the server will bind to the given port.
   
   I've actually used a hardcoded port initially and then spent some time debugging test hangs on TeamCity, where `10800` turned out to be occupied by something else.
   
   Client handled has `port` + `portRange` and will bind to the first available port. The only way to ensure stable tests is to retrieve the actual bound port from the module.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] agura commented on a change in pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

Posted by GitBox <gi...@apache.org>.
agura commented on a change in pull request #283:
URL: https://github.com/apache/ignite-3/pull/283#discussion_r690296804



##########
File path: modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java
##########
@@ -27,55 +28,76 @@
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
-import org.apache.ignite.app.Ignite;
 import org.apache.ignite.client.proto.ClientMessageDecoder;
 import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration;
 import org.apache.ignite.internal.configuration.ConfigurationRegistry;
+import org.apache.ignite.internal.manager.IgniteComponent;
 import org.apache.ignite.lang.IgniteException;
-import org.slf4j.Logger;
+import org.apache.ignite.lang.IgniteLogger;
+import org.apache.ignite.table.manager.IgniteTables;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Client handler module maintains TCP endpoint for thin client connections.
- *
  */
-public class ClientHandlerModule {
+public class ClientHandlerModule implements IgniteComponent {
+    /** The logger. */
+    private static final IgniteLogger LOG = IgniteLogger.forClass(ClientHandlerModule.class);
+
     /** Configuration registry. */
-    private ConfigurationRegistry registry;
+    private final ConfigurationRegistry registry;
 
-    /** Ignite API entry poiny. */
-    private final Ignite ignite;
+    /** Ignite tables API. */
+    private final IgniteTables igniteTables;
 
-    /** Logger. */
-    private final Logger log;
+    /** Netty channel. */
+    private Channel channel;
 
     /**
      * Constructor.
      *
-     * @param ignite Ignite.
-     * @param log Logger.
+     * @param igniteTables Ignite.
+     * @param registry Configuration registry.
      */
-    public ClientHandlerModule(Ignite ignite, Logger log) {
-        this.ignite = ignite;
-        this.log = log;
+    public ClientHandlerModule(

Review comment:
       Redundant reformat code. Both parameters could be easily placed on one line.

##########
File path: modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java
##########
@@ -27,55 +28,76 @@
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
-import org.apache.ignite.app.Ignite;
 import org.apache.ignite.client.proto.ClientMessageDecoder;
 import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration;
 import org.apache.ignite.internal.configuration.ConfigurationRegistry;
+import org.apache.ignite.internal.manager.IgniteComponent;
 import org.apache.ignite.lang.IgniteException;
-import org.slf4j.Logger;
+import org.apache.ignite.lang.IgniteLogger;
+import org.apache.ignite.table.manager.IgniteTables;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Client handler module maintains TCP endpoint for thin client connections.
- *
  */
-public class ClientHandlerModule {
+public class ClientHandlerModule implements IgniteComponent {
+    /** The logger. */
+    private static final IgniteLogger LOG = IgniteLogger.forClass(ClientHandlerModule.class);
+
     /** Configuration registry. */
-    private ConfigurationRegistry registry;
+    private final ConfigurationRegistry registry;
 
-    /** Ignite API entry poiny. */
-    private final Ignite ignite;
+    /** Ignite tables API. */
+    private final IgniteTables igniteTables;
 
-    /** Logger. */
-    private final Logger log;
+    /** Netty channel. */
+    private Channel channel;
 
     /**
      * Constructor.
      *
-     * @param ignite Ignite.
-     * @param log Logger.
+     * @param igniteTables Ignite.
+     * @param registry Configuration registry.
      */
-    public ClientHandlerModule(Ignite ignite, Logger log) {
-        this.ignite = ignite;
-        this.log = log;
+    public ClientHandlerModule(
+            IgniteTables igniteTables,
+            ConfigurationRegistry registry
+    ) {
+        assert igniteTables != null;
+        assert registry != null;
+
+        this.igniteTables = igniteTables;
+        this.registry = registry;
     }
 
-    /**
-     * Prepares to start the module.
-     *
-     * @param sysCfg Configuration registry.
-     */
-    public void prepareStart(ConfigurationRegistry sysCfg) {
-        registry = sysCfg;
+    /** {@inheritDoc} */
+    @Override public void start() {
+        if (channel != null)
+            throw new IgniteException("ClientHandlerModule is already started.");
+
+        try {
+            channel = startEndpoint().channel();
+        } catch (InterruptedException e) {
+            throw new IgniteException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() throws Exception {
+        if (channel != null) {
+            channel.close().await();
+
+            channel = null;
+        }
     }
 
     /**
-     * Starts the module.
+     * Returns the local address where this handler is bound to.
      *
-     * @return channel future.
-     * @throws InterruptedException If thread has been interrupted during the start.
+     * @return the local address of this module, or {@code null} if this module is not started.
      */
-    public ChannelFuture start() throws InterruptedException {
-        return startEndpoint();
+    public @Nullable SocketAddress localAddress() {

Review comment:
       `@Nullable` should be placed before access modifier.
   See https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines#CodingGuidelines-@Annotations

##########
File path: modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java
##########
@@ -27,55 +28,76 @@
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
-import org.apache.ignite.app.Ignite;
 import org.apache.ignite.client.proto.ClientMessageDecoder;
 import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration;
 import org.apache.ignite.internal.configuration.ConfigurationRegistry;
+import org.apache.ignite.internal.manager.IgniteComponent;
 import org.apache.ignite.lang.IgniteException;
-import org.slf4j.Logger;
+import org.apache.ignite.lang.IgniteLogger;
+import org.apache.ignite.table.manager.IgniteTables;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Client handler module maintains TCP endpoint for thin client connections.
- *
  */
-public class ClientHandlerModule {
+public class ClientHandlerModule implements IgniteComponent {
+    /** The logger. */
+    private static final IgniteLogger LOG = IgniteLogger.forClass(ClientHandlerModule.class);
+
     /** Configuration registry. */
-    private ConfigurationRegistry registry;
+    private final ConfigurationRegistry registry;
 
-    /** Ignite API entry poiny. */
-    private final Ignite ignite;
+    /** Ignite tables API. */
+    private final IgniteTables igniteTables;
 
-    /** Logger. */
-    private final Logger log;
+    /** Netty channel. */
+    private Channel channel;
 
     /**
      * Constructor.
      *
-     * @param ignite Ignite.
-     * @param log Logger.
+     * @param igniteTables Ignite.
+     * @param registry Configuration registry.
      */
-    public ClientHandlerModule(Ignite ignite, Logger log) {
-        this.ignite = ignite;
-        this.log = log;
+    public ClientHandlerModule(
+            IgniteTables igniteTables,
+            ConfigurationRegistry registry
+    ) {
+        assert igniteTables != null;
+        assert registry != null;
+
+        this.igniteTables = igniteTables;
+        this.registry = registry;
     }
 
-    /**
-     * Prepares to start the module.
-     *
-     * @param sysCfg Configuration registry.
-     */
-    public void prepareStart(ConfigurationRegistry sysCfg) {
-        registry = sysCfg;
+    /** {@inheritDoc} */
+    @Override public void start() {
+        if (channel != null)
+            throw new IgniteException("ClientHandlerModule is already started.");
+
+        try {
+            channel = startEndpoint().channel();
+        } catch (InterruptedException e) {

Review comment:
       Break line before `catch`.

##########
File path: modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java
##########
@@ -46,7 +45,7 @@
 
     protected static ConfigurationRegistry configurationRegistry;
 
-    protected static ChannelFuture serverFuture;
+    protected static ClientHandlerModule serverModule;

Review comment:
       `protected static` fields confuse me. How is it possible to create multi node test in one JVM with static fields? 




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] ptupitsyn merged pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

Posted by GitBox <gi...@apache.org>.
ptupitsyn merged pull request #283:
URL: https://github.com/apache/ignite-3/pull/283


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] kgusakov commented on a change in pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

Posted by GitBox <gi...@apache.org>.
kgusakov commented on a change in pull request #283:
URL: https://github.com/apache/ignite-3/pull/283#discussion_r690301854



##########
File path: modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ITThinClientConnectionTest.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.runner.app;
+
+import java.lang.reflect.Field;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import com.google.common.collect.Lists;
+import org.apache.ignite.app.Ignite;
+import org.apache.ignite.app.IgnitionManager;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.handler.ClientHandlerModule;
+import org.apache.ignite.internal.app.IgnitionImpl;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.schema.ColumnType;
+import org.apache.ignite.schema.SchemaBuilders;
+import org.apache.ignite.schema.SchemaTable;
+import org.apache.ignite.table.Table;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests thin client connecting to a real server node.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+public class ITThinClientConnectionTest extends IgniteAbstractTest {
+    /** */
+    private static final String SCHEMA_NAME = "PUB";
+
+    /** */
+    private static final String TABLE_NAME = "tbl1";
+
+    /** Nodes bootstrap configuration. */
+    private static final Map<String, String> nodesBootstrapCfg = new LinkedHashMap<>() {{
+        put("node0", "{\n" +
+                "  \"node\": {\n" +
+                "    \"metastorageNodes\":[ \"node0\" ]\n" +
+                "  },\n" +
+                "  \"network\": {\n" +
+                "    \"port\":3344,\n" +
+                "    \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\" ]\n" +
+                "  }\n" +
+                "}");
+
+        put("node1", "{\n" +
+                "  \"node\": {\n" +
+                "    \"metastorageNodes\":[ \"node0\" ]\n" +
+                "  },\n" +
+                "  \"network\": {\n" +
+                "    \"port\":3345,\n" +
+                "    \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\" ]\n" +
+                "  }\n" +
+                "}");
+        }};
+
+    /** */
+    private final List<Ignite> startedNodes = new ArrayList<>();
+
+    /** */
+    @AfterEach
+    void tearDown() throws Exception {
+        IgniteUtils.closeAll(Lists.reverse(startedNodes));
+    }
+
+    /**
+     * Check that thin client can connect to any server node and work with table API.
+     */
+    @Test
+    void testThinClientConnectsToServerNodesAndExecutesBasicTableOperations() throws Exception {
+        nodesBootstrapCfg.forEach((nodeName, configStr) ->
+                startedNodes.add(IgnitionManager.start(nodeName, configStr, workDir.resolve(nodeName)))
+        );
+
+        var keyCol = "key";
+        var valCol = "val";
+
+        SchemaTable schTbl = SchemaBuilders.tableBuilder(SCHEMA_NAME, TABLE_NAME).columns(
+                SchemaBuilders.column(keyCol, ColumnType.INT32).asNonNull().build(),
+                SchemaBuilders.column(valCol, ColumnType.string()).asNullable().build()
+        ).withPrimaryKey(keyCol).build();
+
+        startedNodes.get(0).tables().createTable(schTbl.canonicalName(), tblCh ->
+                SchemaConfigurationConverter.convert(schTbl, tblCh)
+                        .changeReplicas(1)
+                        .changePartitions(10)
+        );
+
+        var addrs = new String[]{"127.0.0.1:" + getClientPort("node0"), "127.0.0.1:" + getClientPort("node1")};
+
+        for (var addr : addrs) {
+            try (var client = IgniteClient.builder().addresses(addr).build()) {
+                List<Table> tables = client.tables().tables();
+                assertEquals(1, tables.size());
+
+                Table table = tables.get(0);
+                assertEquals(String.format("%s.%s", SCHEMA_NAME, TABLE_NAME), table.tableName());
+
+                var tuple = table.tupleBuilder().set(keyCol, 1).set(valCol, "Hello").build();
+                var keyTuple = table.tupleBuilder().set(keyCol, 1).build();
+
+                table.upsert(tuple);
+                assertEquals("Hello", table.get(keyTuple).stringValue(valCol));
+
+                assertTrue(table.delete(keyTuple));
+            }
+        }
+    }
+
+    /**
+     * Gets the client listener port.
+     *
+     * @param nodeName Node name.
+     * @return Port number.
+     * @throws Exception When failed.
+     */
+    private static int getClientPort(String nodeName) throws Exception {
+        InetSocketAddress addr = (InetSocketAddress) getClientHandlerModule(nodeName).localAddress();
+        assertNotNull(addr);
+
+        return addr.getPort();
+    }
+
+    /**
+     * Gets the client handler module for the give node.
+     *
+     * @param nodeName Node name.
+     * @return Client handler module.
+     * @throws Exception When failed.
+     */
+    private static ClientHandlerModule getClientHandlerModule(String nodeName) throws Exception {
+        Field field = IgnitionImpl.class.getDeclaredField("nodesStartedComponents");

Review comment:
       Why just didn't you set the client port in node config? As I see, other network ports are hardcoded in config already.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] ptupitsyn commented on a change in pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #283:
URL: https://github.com/apache/ignite-3/pull/283#discussion_r690443400



##########
File path: modules/client/src/test/java/org/apache/ignite/client/AbstractClientTest.java
##########
@@ -46,7 +45,7 @@
 
     protected static ConfigurationRegistry configurationRegistry;
 
-    protected static ChannelFuture serverFuture;
+    protected static ClientHandlerModule serverModule;

Review comment:
       Maybe I'm missing something (not much experience with JUnit), but `@BeforeAll` requires a static method: https://junit.org/junit5/docs/5.0.0/api/org/junit/jupiter/api/BeforeAll.html.
   
   What is a better way to achieve a similar behavior - start the server once, run many client tests?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] ptupitsyn commented on a change in pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #283:
URL: https://github.com/apache/ignite-3/pull/283#discussion_r690444625



##########
File path: modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java
##########
@@ -27,55 +28,76 @@
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
-import org.apache.ignite.app.Ignite;
 import org.apache.ignite.client.proto.ClientMessageDecoder;
 import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration;
 import org.apache.ignite.internal.configuration.ConfigurationRegistry;
+import org.apache.ignite.internal.manager.IgniteComponent;
 import org.apache.ignite.lang.IgniteException;
-import org.slf4j.Logger;
+import org.apache.ignite.lang.IgniteLogger;
+import org.apache.ignite.table.manager.IgniteTables;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Client handler module maintains TCP endpoint for thin client connections.
- *
  */
-public class ClientHandlerModule {
+public class ClientHandlerModule implements IgniteComponent {
+    /** The logger. */
+    private static final IgniteLogger LOG = IgniteLogger.forClass(ClientHandlerModule.class);
+
     /** Configuration registry. */
-    private ConfigurationRegistry registry;
+    private final ConfigurationRegistry registry;
 
-    /** Ignite API entry poiny. */
-    private final Ignite ignite;
+    /** Ignite tables API. */
+    private final IgniteTables igniteTables;
 
-    /** Logger. */
-    private final Logger log;
+    /** Netty channel. */
+    private Channel channel;
 
     /**
      * Constructor.
      *
-     * @param ignite Ignite.
-     * @param log Logger.
+     * @param igniteTables Ignite.
+     * @param registry Configuration registry.
      */
-    public ClientHandlerModule(Ignite ignite, Logger log) {
-        this.ignite = ignite;
-        this.log = log;
+    public ClientHandlerModule(
+            IgniteTables igniteTables,
+            ConfigurationRegistry registry
+    ) {
+        assert igniteTables != null;
+        assert registry != null;
+
+        this.igniteTables = igniteTables;
+        this.registry = registry;
     }
 
-    /**
-     * Prepares to start the module.
-     *
-     * @param sysCfg Configuration registry.
-     */
-    public void prepareStart(ConfigurationRegistry sysCfg) {
-        registry = sysCfg;
+    /** {@inheritDoc} */
+    @Override public void start() {
+        if (channel != null)
+            throw new IgniteException("ClientHandlerModule is already started.");
+
+        try {
+            channel = startEndpoint().channel();
+        } catch (InterruptedException e) {

Review comment:
       Fixed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] ptupitsyn commented on a change in pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #283:
URL: https://github.com/apache/ignite-3/pull/283#discussion_r690445382



##########
File path: modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java
##########
@@ -27,55 +28,76 @@
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
-import org.apache.ignite.app.Ignite;
 import org.apache.ignite.client.proto.ClientMessageDecoder;
 import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration;
 import org.apache.ignite.internal.configuration.ConfigurationRegistry;
+import org.apache.ignite.internal.manager.IgniteComponent;
 import org.apache.ignite.lang.IgniteException;
-import org.slf4j.Logger;
+import org.apache.ignite.lang.IgniteLogger;
+import org.apache.ignite.table.manager.IgniteTables;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Client handler module maintains TCP endpoint for thin client connections.
- *
  */
-public class ClientHandlerModule {
+public class ClientHandlerModule implements IgniteComponent {
+    /** The logger. */
+    private static final IgniteLogger LOG = IgniteLogger.forClass(ClientHandlerModule.class);
+
     /** Configuration registry. */
-    private ConfigurationRegistry registry;
+    private final ConfigurationRegistry registry;
 
-    /** Ignite API entry poiny. */
-    private final Ignite ignite;
+    /** Ignite tables API. */
+    private final IgniteTables igniteTables;
 
-    /** Logger. */
-    private final Logger log;
+    /** Netty channel. */
+    private Channel channel;
 
     /**
      * Constructor.
      *
-     * @param ignite Ignite.
-     * @param log Logger.
+     * @param igniteTables Ignite.
+     * @param registry Configuration registry.
      */
-    public ClientHandlerModule(Ignite ignite, Logger log) {
-        this.ignite = ignite;
-        this.log = log;
+    public ClientHandlerModule(
+            IgniteTables igniteTables,
+            ConfigurationRegistry registry
+    ) {
+        assert igniteTables != null;
+        assert registry != null;
+
+        this.igniteTables = igniteTables;
+        this.registry = registry;
     }
 
-    /**
-     * Prepares to start the module.
-     *
-     * @param sysCfg Configuration registry.
-     */
-    public void prepareStart(ConfigurationRegistry sysCfg) {
-        registry = sysCfg;
+    /** {@inheritDoc} */
+    @Override public void start() {
+        if (channel != null)
+            throw new IgniteException("ClientHandlerModule is already started.");
+
+        try {
+            channel = startEndpoint().channel();
+        } catch (InterruptedException e) {
+            throw new IgniteException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void stop() throws Exception {
+        if (channel != null) {
+            channel.close().await();
+
+            channel = null;
+        }
     }
 
     /**
-     * Starts the module.
+     * Returns the local address where this handler is bound to.
      *
-     * @return channel future.
-     * @throws InterruptedException If thread has been interrupted during the start.
+     * @return the local address of this module, or {@code null} if this module is not started.
      */
-    public ChannelFuture start() throws InterruptedException {
-        return startEndpoint();
+    public @Nullable SocketAddress localAddress() {

Review comment:
       Fixed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] ptupitsyn commented on a change in pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #283:
URL: https://github.com/apache/ignite-3/pull/283#discussion_r690444235



##########
File path: modules/client-handler/src/main/java/org/apache/ignite/client/handler/ClientHandlerModule.java
##########
@@ -27,55 +28,76 @@
 import io.netty.channel.EventLoopGroup;
 import io.netty.channel.nio.NioEventLoopGroup;
 import io.netty.channel.socket.nio.NioServerSocketChannel;
-import org.apache.ignite.app.Ignite;
 import org.apache.ignite.client.proto.ClientMessageDecoder;
 import org.apache.ignite.configuration.schemas.clientconnector.ClientConnectorConfiguration;
 import org.apache.ignite.internal.configuration.ConfigurationRegistry;
+import org.apache.ignite.internal.manager.IgniteComponent;
 import org.apache.ignite.lang.IgniteException;
-import org.slf4j.Logger;
+import org.apache.ignite.lang.IgniteLogger;
+import org.apache.ignite.table.manager.IgniteTables;
+import org.jetbrains.annotations.Nullable;
 
 /**
  * Client handler module maintains TCP endpoint for thin client connections.
- *
  */
-public class ClientHandlerModule {
+public class ClientHandlerModule implements IgniteComponent {
+    /** The logger. */
+    private static final IgniteLogger LOG = IgniteLogger.forClass(ClientHandlerModule.class);
+
     /** Configuration registry. */
-    private ConfigurationRegistry registry;
+    private final ConfigurationRegistry registry;
 
-    /** Ignite API entry poiny. */
-    private final Ignite ignite;
+    /** Ignite tables API. */
+    private final IgniteTables igniteTables;
 
-    /** Logger. */
-    private final Logger log;
+    /** Netty channel. */
+    private Channel channel;
 
     /**
      * Constructor.
      *
-     * @param ignite Ignite.
-     * @param log Logger.
+     * @param igniteTables Ignite.
+     * @param registry Configuration registry.
      */
-    public ClientHandlerModule(Ignite ignite, Logger log) {
-        this.ignite = ignite;
-        this.log = log;
+    public ClientHandlerModule(

Review comment:
       Fixed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [ignite-3] ptupitsyn commented on a change in pull request #283: IGNITE-15236 Thin 3.0: Start client-handler module

Posted by GitBox <gi...@apache.org>.
ptupitsyn commented on a change in pull request #283:
URL: https://github.com/apache/ignite-3/pull/283#discussion_r690440277



##########
File path: modules/runner/src/integrationTest/java/org/apache/ignite/internal/runner/app/ITThinClientConnectionTest.java
##########
@@ -0,0 +1,173 @@
+/*
+ * 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.runner.app;
+
+import java.lang.reflect.Field;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import com.google.common.collect.Lists;
+import org.apache.ignite.app.Ignite;
+import org.apache.ignite.app.IgnitionManager;
+import org.apache.ignite.client.IgniteClient;
+import org.apache.ignite.client.handler.ClientHandlerModule;
+import org.apache.ignite.internal.app.IgnitionImpl;
+import org.apache.ignite.internal.manager.IgniteComponent;
+import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
+import org.apache.ignite.internal.testframework.IgniteAbstractTest;
+import org.apache.ignite.internal.testframework.WorkDirectoryExtension;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.schema.ColumnType;
+import org.apache.ignite.schema.SchemaBuilders;
+import org.apache.ignite.schema.SchemaTable;
+import org.apache.ignite.table.Table;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Tests thin client connecting to a real server node.
+ */
+@ExtendWith(WorkDirectoryExtension.class)
+public class ITThinClientConnectionTest extends IgniteAbstractTest {
+    /** */
+    private static final String SCHEMA_NAME = "PUB";
+
+    /** */
+    private static final String TABLE_NAME = "tbl1";
+
+    /** Nodes bootstrap configuration. */
+    private static final Map<String, String> nodesBootstrapCfg = new LinkedHashMap<>() {{
+        put("node0", "{\n" +
+                "  \"node\": {\n" +
+                "    \"metastorageNodes\":[ \"node0\" ]\n" +
+                "  },\n" +
+                "  \"network\": {\n" +
+                "    \"port\":3344,\n" +
+                "    \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\" ]\n" +
+                "  }\n" +
+                "}");
+
+        put("node1", "{\n" +
+                "  \"node\": {\n" +
+                "    \"metastorageNodes\":[ \"node0\" ]\n" +
+                "  },\n" +
+                "  \"network\": {\n" +
+                "    \"port\":3345,\n" +
+                "    \"netClusterNodes\":[ \"localhost:3344\", \"localhost:3345\" ]\n" +
+                "  }\n" +
+                "}");
+        }};
+
+    /** */
+    private final List<Ignite> startedNodes = new ArrayList<>();
+
+    /** */
+    @AfterEach
+    void tearDown() throws Exception {
+        IgniteUtils.closeAll(Lists.reverse(startedNodes));
+    }
+
+    /**
+     * Check that thin client can connect to any server node and work with table API.
+     */
+    @Test
+    void testThinClientConnectsToServerNodesAndExecutesBasicTableOperations() throws Exception {
+        nodesBootstrapCfg.forEach((nodeName, configStr) ->
+                startedNodes.add(IgnitionManager.start(nodeName, configStr, workDir.resolve(nodeName)))
+        );
+
+        var keyCol = "key";
+        var valCol = "val";
+
+        SchemaTable schTbl = SchemaBuilders.tableBuilder(SCHEMA_NAME, TABLE_NAME).columns(
+                SchemaBuilders.column(keyCol, ColumnType.INT32).asNonNull().build(),
+                SchemaBuilders.column(valCol, ColumnType.string()).asNullable().build()
+        ).withPrimaryKey(keyCol).build();
+
+        startedNodes.get(0).tables().createTable(schTbl.canonicalName(), tblCh ->
+                SchemaConfigurationConverter.convert(schTbl, tblCh)
+                        .changeReplicas(1)
+                        .changePartitions(10)
+        );
+
+        var addrs = new String[]{"127.0.0.1:" + getClientPort("node0"), "127.0.0.1:" + getClientPort("node1")};
+
+        for (var addr : addrs) {
+            try (var client = IgniteClient.builder().addresses(addr).build()) {
+                List<Table> tables = client.tables().tables();
+                assertEquals(1, tables.size());
+
+                Table table = tables.get(0);
+                assertEquals(String.format("%s.%s", SCHEMA_NAME, TABLE_NAME), table.tableName());
+
+                var tuple = table.tupleBuilder().set(keyCol, 1).set(valCol, "Hello").build();
+                var keyTuple = table.tupleBuilder().set(keyCol, 1).build();
+
+                table.upsert(tuple);
+                assertEquals("Hello", table.get(keyTuple).stringValue(valCol));
+
+                assertTrue(table.delete(keyTuple));
+            }
+        }
+    }
+
+    /**
+     * Gets the client listener port.
+     *
+     * @param nodeName Node name.
+     * @return Port number.
+     * @throws Exception When failed.
+     */
+    private static int getClientPort(String nodeName) throws Exception {
+        InetSocketAddress addr = (InetSocketAddress) getClientHandlerModule(nodeName).localAddress();
+        assertNotNull(addr);
+
+        return addr.getPort();
+    }
+
+    /**
+     * Gets the client handler module for the give node.
+     *
+     * @param nodeName Node name.
+     * @return Client handler module.
+     * @throws Exception When failed.
+     */
+    private static ClientHandlerModule getClientHandlerModule(String nodeName) throws Exception {
+        Field field = IgnitionImpl.class.getDeclaredField("nodesStartedComponents");

Review comment:
       There is no guarantee that the server will bind to the given port.
   
   I've actually used a hardcoded port initially and then spent some time debugging test hangs on TeamCity, where `10800` turned out to be occupied by something else.
   
   Client handler has `port` + `portRange` and will bind to the first available port. The only way to ensure stable tests is to retrieve the actual bound port from the module.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org