You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vk...@apache.org on 2021/10/09 21:51:05 UTC
[ignite-3] 01/01: IGNITE-15719 - Fixed multiple issues in the
'examples' module
This is an automated email from the ASF dual-hosted git repository.
vkulichenko pushed a commit to branch ignite-15719
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
commit 8be0f45d637f4f4c2175bb5e73dea646d2ab43e0
Author: Valentin Kulichenko <va...@gmail.com>
AuthorDate: Sat Oct 9 14:50:42 2021 -0700
IGNITE-15719 - Fixed multiple issues in the 'examples' module
---
assembly/assembly.xml | 2 +-
examples/.gitignore | 2 +
examples/README.md | 2 +
examples/config/java.util.logging.properties | 23 ++
.../example/client/ClientKeyValueViewExample.java | 121 -------
.../example/client/ClientRecordViewExample.java | 122 -------
.../ignite/example/rebalance/RebalanceExample.java | 158 +++++----
.../ignite/example/sql/jdbc/SqlJdbcExample.java | 360 +++++++++++----------
.../ignite/example/table/KeyValueViewExample.java | 110 ++++---
.../ignite/example/table/RecordViewExample.java | 115 ++++---
.../ignite/example/client/ClientExamplesTest.java | 75 -----
.../ignite/example/sql/jdbc/SqlExamplesTest.java | 24 +-
.../ignite/example/table/TableExamplesTest.java | 8 +-
13 files changed, 486 insertions(+), 636 deletions(-)
diff --git a/assembly/assembly.xml b/assembly/assembly.xml
index 4987f17..e10c872 100644
--- a/assembly/assembly.xml
+++ b/assembly/assembly.xml
@@ -65,7 +65,7 @@
<outputDirectory>./examples</outputDirectory>
<includes>
<include>config/**</include>
- <include>src/**</include>
+ <include>src/main/**</include>
<include>README.md</include>
</includes>
</fileSet>
diff --git a/examples/.gitignore b/examples/.gitignore
new file mode 100644
index 0000000..02e7b03
--- /dev/null
+++ b/examples/.gitignore
@@ -0,0 +1,2 @@
+work*
+ignite.log*
diff --git a/examples/README.md b/examples/README.md
index fa843c0..42efd2c 100644
--- a/examples/README.md
+++ b/examples/README.md
@@ -8,6 +8,8 @@ to import provided `pom.xml` file into your favourite IDE.
The following examples are included:
* `RecordViewExample` - demonstrates the usage of the `org.apache.ignite.table.RecordView` API
* `KeyValueViewExample` - demonstrates the usage of the `org.apache.ignite.table.KeyValueView` API
+* `SqlJdbcExample` - demonstrates the usage of the Apache Ignite JDBC driver.
+* `RebalanceExample` - demonstrates the data rebalancing process.
To run an example, do the following:
1. Import the examples project into you IDE.
diff --git a/examples/config/java.util.logging.properties b/examples/config/java.util.logging.properties
new file mode 100644
index 0000000..ab67713
--- /dev/null
+++ b/examples/config/java.util.logging.properties
@@ -0,0 +1,23 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# 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.
+#
+
+.level=INFO
+
+handlers=java.util.logging.FileHandler
+
+java.util.logging.FileHandler.formatter = org.apache.ignite.lang.JavaLoggerFormatter
+java.util.logging.FileHandler.pattern = ignite.log
diff --git a/examples/src/main/java/org/apache/ignite/example/client/ClientKeyValueViewExample.java b/examples/src/main/java/org/apache/ignite/example/client/ClientKeyValueViewExample.java
deleted file mode 100644
index beb53df..0000000
--- a/examples/src/main/java/org/apache/ignite/example/client/ClientKeyValueViewExample.java
+++ /dev/null
@@ -1,121 +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.example.client;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgnitionManager;
-import org.apache.ignite.client.IgniteClient;
-import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
-import org.apache.ignite.schema.SchemaBuilders;
-import org.apache.ignite.schema.definition.ColumnType;
-import org.apache.ignite.table.KeyValueView;
-import org.apache.ignite.table.Tuple;
-
-/**
- * This example demonstrates the usage of the {@link KeyValueView} API of Java client.
- * <p>
- * To run the example, do the following:
- * <ol>
- * <li>Import the examples project into you IDE.</li>
- * <li>
- * (optional) Run one or more standalone nodes using the CLI tool:<br>
- * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-1}<br>
- * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-2}<br>
- * {@code ...}<br>
-* {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-n}<br>
- * </li>
- * <li>Run the example in the IDE.</li>
- * </ol>
- */
-public class ClientKeyValueViewExample {
- public static void main(String[] args) throws Exception {
- try (Ignite ignite = IgnitionManager.start(
- "node-0",
- Files.readString(Path.of("config", "ignite-config.json")),
- Path.of("work")
- )) {
-
- //---------------------------------------------------------------------------------
- //
- // Creating a table. The API call below is the equivalent of the following DDL:
- //
- // CREATE TABLE accounts (
- // accountNumber INT PRIMARY KEY,
- // firstName VARCHAR,
- // lastName VARCHAR,
- // balance DOUBLE
- // )
- //
- //---------------------------------------------------------------------------------
-
- ignite.tables().createTable("PUBLIC.accounts", tbl ->
- SchemaConfigurationConverter.convert(
- SchemaBuilders.tableBuilder("PUBLIC", "accounts")
- .columns(
- SchemaBuilders.column("accountNumber", ColumnType.INT32).asNonNull().build(),
- SchemaBuilders.column("firstName", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("lastName", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("balance", ColumnType.DOUBLE).asNullable().build()
- )
- .withPrimaryKey("accountNumber")
- .build(), tbl)
- .changeReplicas(1)
- .changePartitions(10)
- );
-
- try (IgniteClient client = IgniteClient.builder()
- .addresses("127.0.0.1:10800")
- .build()
- ) {
- KeyValueView<Tuple, Tuple> kvView = client.tables().table("PUBLIC.accounts").keyValueView();
-
- //---------------------------------------------------------------------------------
- //
- // Tuple API: insert operation.
- //
- //---------------------------------------------------------------------------------
-
- Tuple key = Tuple.create()
- .set("accountNumber", 123456);
-
- Tuple value = Tuple.create()
- .set("firstName", "Val")
- .set("lastName", "Kulichenko")
- .set("balance", 100.00d);
-
- kvView.put(key, value);
-
- //---------------------------------------------------------------------------------
- //
- // Tuple API: get operation.
- //
- //---------------------------------------------------------------------------------
-
- value = kvView.get(key);
-
- System.out.println(
- "Retrieved using Key-Value API\n" +
- " Account Number: " + key.intValue("accountNumber") + '\n' +
- " Owner: " + value.stringValue("firstName") + " " + value.stringValue("lastName") + '\n' +
- " Balance: $" + value.doubleValue("balance"));
- }
- }
- }
-}
diff --git a/examples/src/main/java/org/apache/ignite/example/client/ClientRecordViewExample.java b/examples/src/main/java/org/apache/ignite/example/client/ClientRecordViewExample.java
deleted file mode 100644
index a32dd89..0000000
--- a/examples/src/main/java/org/apache/ignite/example/client/ClientRecordViewExample.java
+++ /dev/null
@@ -1,122 +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.example.client;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgnitionManager;
-import org.apache.ignite.client.IgniteClient;
-import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
-import org.apache.ignite.schema.SchemaBuilders;
-import org.apache.ignite.schema.definition.ColumnType;
-import org.apache.ignite.table.RecordView;
-import org.apache.ignite.table.Table;
-import org.apache.ignite.table.Tuple;
-
-/**
- * This example demonstrates the usage of the {@link Table} API of Java client.
- * <p>
- * To run the example, do the following:
- * <ol>
- * <li>Import the examples project into you IDE.</li>
- * <li>
- * (optional) Run one or more standalone nodes using the CLI tool:<br>
- * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-1}<br>
- * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-2}<br>
- * {@code ...}<br>
-* {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-n}<br>
- * </li>
- * <li>Run the example in the IDE.</li>
- * </ol>
- */
-public class ClientRecordViewExample {
- public static void main(String[] args) throws Exception {
- try (Ignite ignite = IgnitionManager.start(
- "node-0",
- Files.readString(Path.of("config", "ignite-config.json")),
- Path.of("work")
- )) {
-
- //---------------------------------------------------------------------------------
- //
- // Creating a table. The API call below is the equivalent of the following DDL:
- //
- // CREATE TABLE accounts (
- // accountNumber INT PRIMARY KEY,
- // firstName VARCHAR,
- // lastName VARCHAR,
- // balance DOUBLE
- // )
- //
- //---------------------------------------------------------------------------------
-
- ignite.tables().createTable("PUBLIC.accounts", tbl ->
- SchemaConfigurationConverter.convert(
- SchemaBuilders.tableBuilder("PUBLIC", "accounts")
- .columns(
- SchemaBuilders.column("accountNumber", ColumnType.INT32).asNonNull().build(),
- SchemaBuilders.column("firstName", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("lastName", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("balance", ColumnType.DOUBLE).asNullable().build()
- )
- .withPrimaryKey("accountNumber")
- .build(), tbl)
- .changeReplicas(1)
- .changePartitions(10)
- );
-
- try (IgniteClient client = IgniteClient.builder()
- .addresses("127.0.0.1:10800")
- .build()
- ) {
- RecordView<Tuple> accounts = client.tables().table("PUBLIC.accounts").recordView();
-
- //---------------------------------------------------------------------------------
- //
- // Tuple API: insert operation.
- //
- //---------------------------------------------------------------------------------
-
- Tuple newAccountTuple = Tuple.create()
- .set("accountNumber", 123456)
- .set("firstName", "Val")
- .set("lastName", "Kulichenko")
- .set("balance", 100.00d);
-
- accounts.insert(newAccountTuple);
-
- //---------------------------------------------------------------------------------
- //
- // Tuple API: get operation.
- //
- //---------------------------------------------------------------------------------
-
- Tuple accountNumberTuple = Tuple.create().set("accountNumber", 123456);
-
- Tuple accountTuple = accounts.get(accountNumberTuple);
-
- System.out.println(
- "Retrieved using Tuple API\n" +
- " Account Number: " + accountTuple.intValue("accountNumber") + '\n' +
- " Owner: " + accountTuple.stringValue("firstName") + " " + accountTuple.stringValue("lastName") + '\n' +
- " Balance: $" + accountTuple.doubleValue("balance"));
- }
- }
- }
-}
diff --git a/examples/src/main/java/org/apache/ignite/example/rebalance/RebalanceExample.java b/examples/src/main/java/org/apache/ignite/example/rebalance/RebalanceExample.java
index 62ea4e6..9fac5bf 100644
--- a/examples/src/main/java/org/apache/ignite/example/rebalance/RebalanceExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/rebalance/RebalanceExample.java
@@ -20,25 +20,30 @@ package org.apache.ignite.example.rebalance;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgnitionManager;
import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
import org.apache.ignite.schema.SchemaBuilders;
import org.apache.ignite.schema.definition.ColumnType;
+import org.apache.ignite.schema.definition.TableDefinition;
import org.apache.ignite.table.KeyValueView;
import org.apache.ignite.table.Table;
import org.apache.ignite.table.Tuple;
/**
- * This example demonstrates data rebalance on new nodes.
+ * This example demonstrates the data rebalance process.
+ * The following sequence of events is emulated:
*
- * - Start 3 nodes (A, B, C)
- * - Put some data
- * - Add 2 new nodes (D, E)
- * - Set new baseline to (A, D, E)
- * - Stop (B, C)
- * - Check that data is still available on the new configuration
+ * <ul>
+ * <li>Start 3 nodes (A, B and C)</li>
+ * <li>Insert some data</li>
+ * <li>Add 2 more nodes (D and E)</li>
+ * <li>Set new baseline to (A, D, E)</li>
+ * <li>Stop nodes B and C</li>
+ * <li>Check that data is still available on the new configuration</li>
+ * </ul>
*
* <p>
* To run the example, do the following:
@@ -48,60 +53,105 @@ import org.apache.ignite.table.Tuple;
* </ol>
*/
public class RebalanceExample {
-
public static void main(String[] args) throws Exception {
- var nodes = new ArrayList<Ignite>();
+ List<Ignite> nodes = new ArrayList<>();
- for (int i = 0; i < 3; i++) {
- nodes.add(IgnitionManager.start("node-" + i,
- Files.readString(Path.of("config", "rebalance", "ignite-config-" + i + ".json")),
- Path.of("work" + i)));
- }
+ try {
+ System.out.println("Starting server nodes... Logging to file: ignite.log");
- var node0 = nodes.get(0);
-
- Table testTable = node0.tables().createTable("PUBLIC.rebalance", tbl ->
- SchemaConfigurationConverter.convert(
- SchemaBuilders.tableBuilder("PUBLIC", "rebalance")
- .columns(
- SchemaBuilders.column("key", ColumnType.INT32).asNonNull().build(),
- SchemaBuilders.column("value", ColumnType.string()).asNullable().build()
- )
- .withPrimaryKey("key")
- .build(), tbl)
- .changeReplicas(5)
- .changePartitions(1)
- );
-
- KeyValueView<Tuple, Tuple> kvView = testTable.keyValueView();
- Tuple key = Tuple.create()
- .set("key", 1);
-
- Tuple value = Tuple.create()
- .set("value", "test");
-
- kvView.put(key, value);
-
- String oldValue = testTable.recordView().get(key).value("value");
- System.out.println("Value in the start cluster configuration " + oldValue);
-
- for (int i = 3; i < 5; i++) {
- nodes.add(IgnitionManager.start("node-" + i,
- Files.readString(Path.of("config", "rebalance", "ignite-config-" + i + ".json")),
- Path.of("work" + i)));
- }
+ System.setProperty("java.util.logging.config.file", "config/java.util.logging.properties");
+
+ for (int i = 0; i < 3; i++) {
+ nodes.add(IgnitionManager.start("node-" + i,
+ Files.readString(Path.of("config", "rebalance", "ignite-config-" + i + ".json")),
+ Path.of("work" + i)));
+ }
+
+ Ignite node0 = nodes.get(0);
+
+ //--------------------------------------------------------------------------------------
+ //
+ // Creating a table. The API call below is the equivalent of the following DDL:
+ //
+ // CREATE TABLE rebalance (
+ // key INT PRIMARY KEY,
+ // value VARCHAR
+ // )
+ //
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nCreating a table...");
+
+ TableDefinition tableDef = SchemaBuilders.tableBuilder("PUBLIC", "rebalance")
+ .columns(
+ SchemaBuilders.column("key", ColumnType.INT32).asNonNull().build(),
+ SchemaBuilders.column("value", ColumnType.string()).asNullable().build()
+ )
+ .withPrimaryKey("key")
+ .build();
+
+ Table testTable = node0.tables().createTable("PUBLIC.rebalance", tableChange ->
+ SchemaConfigurationConverter.convert(tableDef, tableChange)
+ .changeReplicas(5)
+ .changePartitions(1)
+ );
+
+ //--------------------------------------------------------------------------------------
+ //
+ // Inserting a key-value pair into the table.
+ //
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nInserting a key-value pair...");
+
+ KeyValueView<Tuple, Tuple> kvView = testTable.keyValueView();
- node0.setBaseline(Set.of("node-0", "node-3", "node-4"));
+ Tuple key = Tuple.create().set("key", 1);
+ Tuple value = Tuple.create().set("value", "test");
- IgnitionManager.stop(nodes.get(1).name());
- IgnitionManager.stop(nodes.get(2).name());
+ kvView.put(key, value);
- var valueOnNewNode = nodes.get(4).tables().table("PUBLIC.rebalance").recordView().get(key).value("value");
+ System.out.println("\nCurrent value: " + kvView.get(key).value("value"));
- System.out.println("Value in the new cluster configuration " + valueOnNewNode);
+ //--------------------------------------------------------------------------------------
+ //
+ // Changing the topology and updating the baseline.
+ //
+ //--------------------------------------------------------------------------------------
- IgnitionManager.stop(nodes.get(0).name());
- IgnitionManager.stop(nodes.get(3).name());
- IgnitionManager.stop(nodes.get(4).name());
+ System.out.println("\nChanging the topology...");
+
+ for (int i = 3; i < 5; i++) {
+ nodes.add(IgnitionManager.start("node-" + i,
+ Files.readString(Path.of("config", "rebalance", "ignite-config-" + i + ".json")),
+ Path.of("work" + i)));
+ }
+
+ node0.setBaseline(Set.of("node-0", "node-3", "node-4"));
+
+ IgnitionManager.stop(nodes.get(1).name());
+ IgnitionManager.stop(nodes.get(2).name());
+
+ //--------------------------------------------------------------------------------------
+ //
+ // Retrieving the value from one of the new nodes.
+ //
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nRetrieving the value from one of the new nodes...");
+
+ String valueOnNewNode = nodes.get(4).tables().table("PUBLIC.rebalance").keyValueView().get(key).value("value");
+
+ System.out.println("\nRetrieved value: " + valueOnNewNode);
+
+ System.out.println("\nDropping the table and stopping the cluster...");
+
+ node0.tables().dropTable(tableDef.canonicalName());
+ }
+ finally {
+ IgnitionManager.stop(nodes.get(0).name());
+ IgnitionManager.stop(nodes.get(3).name());
+ IgnitionManager.stop(nodes.get(4).name());
+ }
}
}
diff --git a/examples/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java b/examples/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
index ce58b63..a44f8b8 100644
--- a/examples/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/sql/jdbc/SqlJdbcExample.java
@@ -30,224 +30,246 @@ import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConver
import org.apache.ignite.schema.SchemaBuilders;
import org.apache.ignite.schema.definition.ColumnType;
import org.apache.ignite.schema.definition.TableDefinition;
-import org.apache.ignite.table.Table;
/**
- * This example demonstrates usage of Ignite JDBC driver.
+ * This example demonstrates the usage of the Apache Ignite JDBC driver.
* <p>
* To run the example, do the following:
* <ol>
* <li>Import the examples project into you IDE.</li>
+ * <li>
+ * (optional) Run one or more standalone nodes using the CLI tool:<br>
+ * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-1}<br>
+ * {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-2}<br>
+ * {@code ...}<br>
+* {@code ignite node start --config=$IGNITE_HOME/examples/config/ignite-config.json node-n}<br>
+ * </li>
* <li>Run the example in the IDE.</li>
* </ol>
*/
public class SqlJdbcExample {
- /**
- * Executes example.
- *
- * @param args Command line arguments, none required.
- * @throws Exception If example execution failed.
- */
public static void main(String[] args) throws Exception {
- Ignite ignite = IgnitionManager.start(
+ System.out.println("Starting a server node... Logging to file: ignite.log");
+
+ System.setProperty("java.util.logging.config.file", "config/java.util.logging.properties");
+
+ try (Ignite ignite = IgnitionManager.start(
"node-0",
Files.readString(Path.of("config", "ignite-config.json")),
Path.of("work")
- );
-
- print("JDBC example started.");
-
- // Open JDBC connection
- try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/")) {
- print("Connected to server.");
-
- //---------------------------------------------------------------------------------
+ )) {
+ //--------------------------------------------------------------------------------------
//
- // Creating City table.
+ // Creating 'CITIES' table. The API call below is the equivalent of the following DDL:
//
- // CREATE TABLE city (
- // id INT PRIMARY KEY,
- // name VARCHAR
+ // CREATE TABLE cities (
+ // ID INT PRIMARY KEY,
+ // NAME VARCHAR
// )
//
- //---------------------------------------------------------------------------------
- TableDefinition cityTbl = SchemaBuilders.tableBuilder("PUBLIC", "CITY").columns(
- SchemaBuilders.column("ID", ColumnType.INT32).asNonNull().build(),
- SchemaBuilders.column("NAME", ColumnType.string()).asNullable().build()
- ).withPrimaryKey("ID").build();
-
- ignite.tables().createTable(cityTbl.canonicalName(), tblCh ->
- SchemaConfigurationConverter.convert(cityTbl, tblCh)
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nCreating 'CITIES' table...");
+
+ TableDefinition citiesTableDef = SchemaBuilders.tableBuilder("PUBLIC", "CITIES")
+ .columns(
+ SchemaBuilders.column("ID", ColumnType.INT32).asNonNull().build(),
+ SchemaBuilders.column("NAME", ColumnType.string()).asNullable().build()
+ )
+ .withPrimaryKey("ID")
+ .build();
+
+ ignite.tables().createTable(citiesTableDef.canonicalName(), tableChange ->
+ SchemaConfigurationConverter.convert(citiesTableDef, tableChange)
.changeReplicas(1)
- .changePartitions(3)
+ .changePartitions(10)
);
- //---------------------------------------------------------------------------------
+
+ //--------------------------------------------------------------------------------------
//
- // Creating accounts table.
+ // Creating 'ACCOUNTS' table. The API call below is the equivalent of the following DDL:
//
- // CREATE TABLE accounts (
- // accountId INT PRIMARY KEY,
- // cityId INT,
- // firstName VARCHAR,
- // lastName VARCHAR,
- // balance DOUBLE
+ // CREATE TABLE ACCOUNTS (
+ // ACCOUNT_ID INT PRIMARY KEY,
+ // CITY_ID INT,
+ // FIRST_NAME VARCHAR,
+ // LAST_NAME VARCHAR,
+ // BALANCE DOUBLE
// )
//
- //---------------------------------------------------------------------------------
-
- TableDefinition accountsTbl = SchemaBuilders.tableBuilder("PUBLIC", "ACCOUNTS").columns(
- SchemaBuilders.column("ACCOUNTID", ColumnType.INT32).asNonNull().build(),
- SchemaBuilders.column("CITYID", ColumnType.INT32).asNonNull().build(),
- SchemaBuilders.column("FIRSTNAME", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("LASTNAME", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("BALANCE", ColumnType.DOUBLE).asNullable().build()
- ).withPrimaryKey("ACCOUNTID").build();
-
- ignite.tables().createTable(accountsTbl.canonicalName(), tblCh ->
- SchemaConfigurationConverter.convert(accountsTbl, tblCh)
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nCreating 'ACCOUNTS' table...");
+
+ TableDefinition accountsTableDef = SchemaBuilders.tableBuilder("PUBLIC", "ACCOUNTS")
+ .columns(
+ SchemaBuilders.column("ACCOUNT_ID", ColumnType.INT32).asNonNull().build(),
+ SchemaBuilders.column("CITY_ID", ColumnType.INT32).asNonNull().build(),
+ SchemaBuilders.column("FIRST_NAME", ColumnType.string()).asNullable().build(),
+ SchemaBuilders.column("LAST_NAME", ColumnType.string()).asNullable().build(),
+ SchemaBuilders.column("BALANCE", ColumnType.DOUBLE).asNullable().build()
+ )
+ .withPrimaryKey("ACCOUNT_ID")
+ .build();
+
+ ignite.tables().createTable(accountsTableDef.canonicalName(), tableChange ->
+ SchemaConfigurationConverter.convert(accountsTableDef, tableChange)
.changeReplicas(1)
- .changePartitions(3)
+ .changePartitions(10)
);
- print("Created database objects.");
+ //--------------------------------------------------------------------------------------
+ //
+ // Creating a JDBC connection to connect to the cluster.
+ //
+ //--------------------------------------------------------------------------------------
- // Populate City table with PreparedStatement.
- try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO city (id, name) VALUES (?, ?)")) {
- stmt.setInt(1, 1);
- stmt.setString(2, "Forest Hill");
- stmt.executeUpdate();
+ System.out.println("\nConnecting to server...");
- stmt.setInt(1, 2);
- stmt.setString(2, "Denver");
- stmt.executeUpdate();
+ try (Connection conn = DriverManager.getConnection("jdbc:ignite:thin://127.0.0.1:10800/")) {
- stmt.setInt(1, 3);
- stmt.setString(2, "St. Petersburg");
- stmt.executeUpdate();
- }
+ //--------------------------------------------------------------------------------------
+ //
+ // Populating 'CITIES' table.
+ //
+ //--------------------------------------------------------------------------------------
- // Populate Person table with PreparedStatement.
- try (PreparedStatement stmt =
- conn.prepareStatement("INSERT INTO accounts (accountId, cityId, firstName, lastName, balance)" +
- " values (?, ?, ?, ?, ?)")) {
- stmt.setInt(1, 1);
- stmt.setInt(2, 1);
- stmt.setString(3, "John");
- stmt.setString(4, "Doe");
- stmt.setDouble(5, 1000.0d);
- stmt.executeUpdate();
-
- stmt.setInt(1, 2);
- stmt.setInt(2, 1);
- stmt.setString(3, "Jane");
- stmt.setString(4, "Roe");
- stmt.setDouble(5, 2000.0d);
- stmt.executeUpdate();
-
- stmt.setInt(1, 3);
- stmt.setInt(2, 2);
- stmt.setString(3, "Mary");
- stmt.setString(4, "Major");
- stmt.setDouble(5, 1500.0d);
- stmt.executeUpdate();
-
- stmt.setInt(1, 4);
- stmt.setInt(2, 3);
- stmt.setString(3, "Richard");
- stmt.setString(4, "Miles");
- stmt.setDouble(5, 1450.0d);
- stmt.executeUpdate();
- }
+ System.out.println("\nPopulating 'CITIES' table...");
- print("Accounts with city.");
+ try (PreparedStatement stmt = conn.prepareStatement("INSERT INTO CITIES (ID, NAME) VALUES (?, ?)")) {
+ stmt.setInt(1, 1);
+ stmt.setString(2, "Forest Hill");
+ stmt.executeUpdate();
- //---------------------------------------------------------------------------------
- //
- // Gets accounts joined with cities.
- //
- //---------------------------------------------------------------------------------
-
- try (Statement stmt = conn.createStatement()) {
- try (ResultSet rs =
- stmt.executeQuery("SELECT a.firstName, a.lastName, c.name FROM accounts a " +
- "INNER JOIN city c on c.id = a.cityId")) {
- print("Query results:");
+ stmt.setInt(1, 2);
+ stmt.setString(2, "Denver");
+ stmt.executeUpdate();
- while (rs.next()) {
- System.out.println(">>> " + rs.getString(1) + ", " + rs.getString(2)
- + ", " + rs.getString(3));
- }
+ stmt.setInt(1, 3);
+ stmt.setString(2, "St. Petersburg");
+ stmt.executeUpdate();
}
- }
- //---------------------------------------------------------------------------------
- //
- // Gets accounts with balance lower than 1500.
- //
- //---------------------------------------------------------------------------------
-
- print("Accounts with low balance.");
-
- try (Statement stmt = conn.createStatement()) {
- try (ResultSet rs =
- stmt.executeQuery("SELECT a.firstName, a.lastName, a.balance FROM accounts a " +
- "WHERE a.balance < 1500.0")) {
- print("Query results:");
+ //--------------------------------------------------------------------------------------
+ //
+ // Populating 'ACCOUNTS' table.
+ //
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nPopulating 'ACCOUNTS' table...");
+
+ try (PreparedStatement stmt = conn.prepareStatement(
+ "INSERT INTO ACCOUNTS (ACCOUNT_ID, CITY_ID, FIRST_NAME, LAST_NAME, BALANCE) values (?, ?, ?, ?, ?)")) {
+ stmt.setInt(1, 1);
+ stmt.setInt(2, 1);
+ stmt.setString(3, "John");
+ stmt.setString(4, "Doe");
+ stmt.setDouble(5, 1000.0d);
+ stmt.executeUpdate();
+
+ stmt.setInt(1, 2);
+ stmt.setInt(2, 1);
+ stmt.setString(3, "Jane");
+ stmt.setString(4, "Roe");
+ stmt.setDouble(5, 2000.0d);
+ stmt.executeUpdate();
+
+ stmt.setInt(1, 3);
+ stmt.setInt(2, 2);
+ stmt.setString(3, "Mary");
+ stmt.setString(4, "Major");
+ stmt.setDouble(5, 1500.0d);
+ stmt.executeUpdate();
+
+ stmt.setInt(1, 4);
+ stmt.setInt(2, 3);
+ stmt.setString(3, "Richard");
+ stmt.setString(4, "Miles");
+ stmt.setDouble(5, 1450.0d);
+ stmt.executeUpdate();
+ }
- while (rs.next()) {
- System.out.println(">>> " + rs.getString(1) + ", " + rs.getString(2)
- + ", " + rs.getDouble(3));
+ //--------------------------------------------------------------------------------------
+ //
+ // Requesting information about all account owners.
+ //
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nAll accounts:");
+
+ try (Statement stmt = conn.createStatement()) {
+ try (ResultSet rs = stmt.executeQuery(
+ "SELECT a.FIRST_NAME, a.LAST_NAME, c.NAME FROM ACCOUNTS a " +
+ "INNER JOIN CITIES c on c.ID = a.CITY_ID")) {
+ while (rs.next()) {
+ System.out.println(" " +
+ rs.getString(1) + ", " +
+ rs.getString(2) + ", " +
+ rs.getString(3));
+ }
}
}
- }
-
- //---------------------------------------------------------------------------------
- //
- // Delete one of accounts.
- //
- //---------------------------------------------------------------------------------
- print("Delete an account with id '1'.");
+ //--------------------------------------------------------------------------------------
+ //
+ // Requesting accounts with balances lower than 1,500.
+ //
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nAccounts with balance lower than 1,500:");
+
+ try (Statement stmt = conn.createStatement()) {
+ try (ResultSet rs = stmt.executeQuery(
+ "SELECT a.FIRST_NAME, a.LAST_NAME, a.BALANCE FROM ACCOUNTS a WHERE a.BALANCE < 1500.0")) {
+ while (rs.next()) {
+ System.out.println(" " +
+ rs.getString(1) + ", " +
+ rs.getString(2) + ", " +
+ rs.getDouble(3));
+ }
+ }
+ }
- try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM accounts WHERE accountId = ?")) {
- stmt.setInt(1, 1);
- stmt.executeUpdate();
- }
+ //--------------------------------------------------------------------------------------
+ //
+ // Deleting one of the accounts.
+ //
+ //--------------------------------------------------------------------------------------
- print("Existing accounts.");
+ System.out.println("\nDeleting one of the accounts...");
- try (Statement stmt = conn.createStatement()) {
- try (ResultSet rs =
- stmt.executeQuery("SELECT a.firstName, a.lastName, c.name FROM accounts a " +
- "INNER JOIN city c on c.id = a.cityId")) {
- print("Query results:");
+ try (PreparedStatement stmt = conn.prepareStatement("DELETE FROM ACCOUNTS WHERE ACCOUNT_ID = ?")) {
+ stmt.setInt(1, 1);
+ stmt.executeUpdate();
+ }
- while (rs.next()) {
- System.out.println(">>> " + rs.getString(1) + ", " + rs.getString(2)
- + ", " + rs.getString(3));
+ //--------------------------------------------------------------------------------------
+ //
+ // Requesting information about all account owners once again
+ // to verify that the account was actually deleted.
+ //
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nAll accounts:");
+
+ try (Statement stmt = conn.createStatement()) {
+ try (ResultSet rs = stmt.executeQuery(
+ "SELECT a.FIRST_NAME, a.LAST_NAME, c.NAME FROM ACCOUNTS a " +
+ "INNER JOIN CITIES c on c.ID = a.CITY_ID")) {
+ while (rs.next()) {
+ System.out.println(" " +
+ rs.getString(1) + ", " +
+ rs.getString(2) + ", " +
+ rs.getString(3));
+ }
}
}
}
- // Drop database objects.
- for (Table table : ignite.tables().tables()) {
- print("Drop table: " + table.tableName());
+ System.out.println("\nDropping tables and stopping the server...");
- ignite.tables().dropTable(table.tableName());
- }
+ ignite.tables().dropTable(citiesTableDef.canonicalName());
+ ignite.tables().dropTable(accountsTableDef.canonicalName());
}
-
- print("JDBC example finished.");
-
- ignite.close();
- }
-
- /**
- * Prints message.
- *
- * @param msg Message to print before all objects are printed.
- */
- private static void print(String msg) {
- System.out.println("\n>>> " + msg);
}
}
diff --git a/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java b/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
index 29a111e..810d669 100644
--- a/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/table/KeyValueViewExample.java
@@ -21,11 +21,12 @@ import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
import org.apache.ignite.schema.SchemaBuilders;
import org.apache.ignite.schema.definition.ColumnType;
+import org.apache.ignite.schema.definition.TableDefinition;
import org.apache.ignite.table.KeyValueView;
-import org.apache.ignite.table.Table;
import org.apache.ignite.table.Tuple;
/**
@@ -46,15 +47,18 @@ import org.apache.ignite.table.Tuple;
*/
public class KeyValueViewExample {
public static void main(String[] args) throws Exception {
- try (Ignite ignite = IgnitionManager.start(
+ System.out.println("Starting a server node... Logging to file: ignite.log");
+
+ System.setProperty("java.util.logging.config.file", "config/java.util.logging.properties");
+
+ try (Ignite server = IgnitionManager.start(
"node-0",
Files.readString(Path.of("config", "ignite-config.json")),
Path.of("work")
)) {
-
- //---------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
//
- // Creating a table. The API call below is the equivalent of the following DDL:
+ // Creating 'accounts' table. The API call below is the equivalent of the following DDL:
//
// CREATE TABLE accounts (
// accountNumber INT PRIMARY KEY,
@@ -63,54 +67,84 @@ public class KeyValueViewExample {
// balance DOUBLE
// )
//
- //---------------------------------------------------------------------------------
-
- Table accounts = ignite.tables().createTable("PUBLIC.accounts", tbl ->
- SchemaConfigurationConverter.convert(
- SchemaBuilders.tableBuilder("PUBLIC", "accounts")
- .columns(
- SchemaBuilders.column("accountNumber", ColumnType.INT32).asNonNull().build(),
- SchemaBuilders.column("firstName", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("lastName", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("balance", ColumnType.DOUBLE).asNullable().build()
- )
- .withPrimaryKey("accountNumber")
- .build(), tbl)
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nCreating 'accounts' table...");
+
+ TableDefinition accountsTableDef = SchemaBuilders.tableBuilder("PUBLIC", "accounts")
+ .columns(
+ SchemaBuilders.column("accountNumber", ColumnType.INT32).asNonNull().build(),
+ SchemaBuilders.column("firstName", ColumnType.string()).asNullable().build(),
+ SchemaBuilders.column("lastName", ColumnType.string()).asNullable().build(),
+ SchemaBuilders.column("balance", ColumnType.DOUBLE).asNullable().build()
+ )
+ .withPrimaryKey("accountNumber")
+ .build();
+
+ server.tables().createTable(accountsTableDef.canonicalName(), tableChange ->
+ SchemaConfigurationConverter.convert(accountsTableDef, tableChange)
.changeReplicas(1)
.changePartitions(10)
);
- KeyValueView<Tuple, Tuple> kvView = accounts.keyValueView();
-
- //---------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
//
- // Tuple API: insert operation.
+ // Creating a client to connect to the cluster.
//
- //---------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
- Tuple key = Tuple.create()
- .set("accountNumber", 123456);
+ System.out.println("\nConnecting to server...");
- Tuple value = Tuple.create()
- .set("firstName", "Val")
- .set("lastName", "Kulichenko")
- .set("balance", 100.00d);
+ try (IgniteClient client = IgniteClient.builder()
+ .addresses("127.0.0.1:10800")
+ .build()
+ ) {
+ //--------------------------------------------------------------------------------------
+ //
+ // Creating a key-value view for the 'accounts' table.
+ //
+ //--------------------------------------------------------------------------------------
- kvView.put(key, value);
+ KeyValueView<Tuple, Tuple> kvView = client.tables().table("PUBLIC.accounts").keyValueView();
- //---------------------------------------------------------------------------------
- //
- // Tuple API: get operation.
- //
- //---------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
+ //
+ // Performing the 'put' operation.
+ //
+ //--------------------------------------------------------------------------------------
- value = accounts.recordView().get(key);
+ System.out.println("\nInserting a key-value pair into the 'accounts' table...");
- System.out.println(
- "Retrieved using Key-Value API\n" +
+ Tuple key = Tuple.create()
+ .set("accountNumber", 123456);
+
+ Tuple value = Tuple.create()
+ .set("firstName", "Val")
+ .set("lastName", "Kulichenko")
+ .set("balance", 100.00d);
+
+ kvView.put(key, value);
+
+ //--------------------------------------------------------------------------------------
+ //
+ // Performing the 'get' operation.
+ //
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nRetrieving a value using KeyValueView API...");
+
+ value = kvView.get(key);
+
+ System.out.println(
+ "\nRetrieved value:\n" +
" Account Number: " + key.intValue("accountNumber") + '\n' +
" Owner: " + value.stringValue("firstName") + " " + value.stringValue("lastName") + '\n' +
" Balance: $" + value.doubleValue("balance"));
+ }
+
+ System.out.println("\nDropping the table and stopping the server...");
+
+ server.tables().dropTable(accountsTableDef.canonicalName());
}
}
}
diff --git a/examples/src/main/java/org/apache/ignite/example/table/RecordViewExample.java b/examples/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
index 2dbe913..b747839 100644
--- a/examples/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
+++ b/examples/src/main/java/org/apache/ignite/example/table/RecordViewExample.java
@@ -21,15 +21,16 @@ import java.nio.file.Files;
import java.nio.file.Path;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgnitionManager;
+import org.apache.ignite.client.IgniteClient;
import org.apache.ignite.internal.schema.configuration.SchemaConfigurationConverter;
import org.apache.ignite.schema.SchemaBuilders;
import org.apache.ignite.schema.definition.ColumnType;
+import org.apache.ignite.schema.definition.TableDefinition;
import org.apache.ignite.table.RecordView;
-import org.apache.ignite.table.Table;
import org.apache.ignite.table.Tuple;
/**
- * This example demonstrates the usage of the {@link Table} API.
+ * This example demonstrates the usage of the {@link RecordView} API.
* <p>
* To run the example, do the following:
* <ol>
@@ -46,15 +47,18 @@ import org.apache.ignite.table.Tuple;
*/
public class RecordViewExample {
public static void main(String[] args) throws Exception {
- try (Ignite ignite = IgnitionManager.start(
+ System.out.println("Starting a server node... Logging to file: ignite.log");
+
+ System.setProperty("java.util.logging.config.file", "config/java.util.logging.properties");
+
+ try (Ignite server = IgnitionManager.start(
"node-0",
Files.readString(Path.of("config", "ignite-config.json")),
- Path.of("work"))
- ) {
-
- //---------------------------------------------------------------------------------
+ Path.of("work")
+ )) {
+ //--------------------------------------------------------------------------------------
//
- // Creating a table. The API call below is the equivalent of the following DDL:
+ // Creating 'accounts' table. The API call below is the equivalent of the following DDL:
//
// CREATE TABLE accounts (
// accountNumber INT PRIMARY KEY,
@@ -63,53 +67,84 @@ public class RecordViewExample {
// balance DOUBLE
// )
//
- //---------------------------------------------------------------------------------
-
- RecordView<Tuple> accounts = ignite.tables().createTable("PUBLIC.accounts", tbl ->
- SchemaConfigurationConverter.convert(
- SchemaBuilders.tableBuilder("PUBLIC", "accounts")
- .columns(
- SchemaBuilders.column("accountNumber", ColumnType.INT32).asNonNull().build(),
- SchemaBuilders.column("firstName", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("lastName", ColumnType.string()).asNullable().build(),
- SchemaBuilders.column("balance", ColumnType.DOUBLE).asNullable().build()
- )
- .withPrimaryKey("accountNumber")
- .build(), tbl)
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nCreating 'accounts' table...");
+
+ TableDefinition accountsTableDef = SchemaBuilders.tableBuilder("PUBLIC", "accounts")
+ .columns(
+ SchemaBuilders.column("accountNumber", ColumnType.INT32).asNonNull().build(),
+ SchemaBuilders.column("firstName", ColumnType.string()).asNullable().build(),
+ SchemaBuilders.column("lastName", ColumnType.string()).asNullable().build(),
+ SchemaBuilders.column("balance", ColumnType.DOUBLE).asNullable().build()
+ )
+ .withPrimaryKey("accountNumber")
+ .build();
+
+ server.tables().createTable(accountsTableDef.canonicalName(), tableChange ->
+ SchemaConfigurationConverter.convert(accountsTableDef, tableChange)
.changeReplicas(1)
.changePartitions(10)
- ).recordView();
+ );
- //---------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
//
- // Tuple API: insert operation.
+ // Creating a client to connect to the cluster.
//
- //---------------------------------------------------------------------------------
+ //--------------------------------------------------------------------------------------
- Tuple newAccountTuple = Tuple.create()
- .set("accountNumber", 123456)
- .set("firstName", "Val")
- .set("lastName", "Kulichenko")
- .set("balance", 100.00d);
+ System.out.println("\nConnecting to server...");
- accounts.insert(newAccountTuple);
+ try (IgniteClient client = IgniteClient.builder()
+ .addresses("127.0.0.1:10800")
+ .build()
+ ) {
+ //--------------------------------------------------------------------------------------
+ //
+ // Creating a record view for the 'accounts' table.
+ //
+ //--------------------------------------------------------------------------------------
- //---------------------------------------------------------------------------------
- //
- // Tuple API: get operation.
- //
- //---------------------------------------------------------------------------------
+ RecordView<Tuple> accounts = client.tables().table("PUBLIC.accounts").recordView();
- Tuple accountNumberTuple = Tuple.create().set("accountNumber", 123456);
+ //--------------------------------------------------------------------------------------
+ //
+ // Performing the 'insert' operation.
+ //
+ //--------------------------------------------------------------------------------------
- Tuple accountTuple = accounts.get(accountNumberTuple);
+ System.out.println("\nInserting a record into the 'accounts' table...");
- System.out.println(
- "Retrieved using Tuple API\n" +
+ Tuple newAccountTuple = Tuple.create()
+ .set("accountNumber", 123456)
+ .set("firstName", "Val")
+ .set("lastName", "Kulichenko")
+ .set("balance", 100.00d);
+
+ accounts.insert(newAccountTuple);
+
+ //--------------------------------------------------------------------------------------
+ //
+ // Performing the 'get' operation.
+ //
+ //--------------------------------------------------------------------------------------
+
+ System.out.println("\nRetrieving a record using RecordView API...");
+
+ Tuple accountNumberTuple = Tuple.create().set("accountNumber", 123456);
+
+ Tuple accountTuple = accounts.get(accountNumberTuple);
+
+ System.out.println(
+ "\nRetrieved record:\n" +
" Account Number: " + accountTuple.intValue("accountNumber") + '\n' +
" Owner: " + accountTuple.stringValue("firstName") + " " + accountTuple.stringValue("lastName") + '\n' +
" Balance: $" + accountTuple.doubleValue("balance"));
+ }
+
+ System.out.println("\nDropping the table and stopping the server...");
+ server.tables().dropTable(accountsTableDef.canonicalName());
}
}
}
diff --git a/examples/src/test/java/org/apache/ignite/example/client/ClientExamplesTest.java b/examples/src/test/java/org/apache/ignite/example/client/ClientExamplesTest.java
deleted file mode 100644
index 6b38419..0000000
--- a/examples/src/test/java/org/apache/ignite/example/client/ClientExamplesTest.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.example.client;
-
-import java.nio.file.Files;
-import java.nio.file.Path;
-
-import org.apache.ignite.example.ExampleTestUtils;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.junit.jupiter.api.AfterEach;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-/**
- * These tests check that all client examples pass correctly.
- */
-public class ClientExamplesTest {
- /** Empty argument to invoke an example. */
- protected static final String[] EMPTY_ARGS = new String[0];
-
- /**
- * Runs ClientRecordViewExample and checks its output.
- *
- * @throws Exception If failed.
- */
- @Test
- public void testClientRecordViewExample() throws Exception {
- ExampleTestUtils.assertConsoleOutput(ClientRecordViewExample::main, EMPTY_ARGS,
- "Retrieved using Tuple API\n" +
- " Account Number: 123456\n" +
- " Owner: Val Kulichenko\n" +
- " Balance: $100.0\n");
- }
-
- /**
- * Runs ClientKeyValueViewExample and checks its output.
- *
- * @throws Exception If failed.
- */
- @Test
- public void testClientKeyValueViewExample() throws Exception {
- ExampleTestUtils.assertConsoleOutput(ClientKeyValueViewExample::main, EMPTY_ARGS,
- "Retrieved using Key-Value API\n" +
- " Account Number: 123456\n" +
- " Owner: Val Kulichenko\n" +
- " Balance: $100.0\n");
- }
-
- /**
- * Removes a previously created work directory.
- */
- @BeforeEach
- @AfterEach
- private void removeWorkDir() {
- Path workDir = Path.of("work");
-
- if (Files.exists(workDir))
- IgniteUtils.deleteIfExists(workDir);
- }
-}
diff --git a/examples/src/test/java/org/apache/ignite/example/sql/jdbc/SqlExamplesTest.java b/examples/src/test/java/org/apache/ignite/example/sql/jdbc/SqlExamplesTest.java
index 2a7db3a..7bd9033 100644
--- a/examples/src/test/java/org/apache/ignite/example/sql/jdbc/SqlExamplesTest.java
+++ b/examples/src/test/java/org/apache/ignite/example/sql/jdbc/SqlExamplesTest.java
@@ -41,20 +41,20 @@ public class SqlExamplesTest {
@Test
public void testSqlJdbcExample() throws Exception {
ExampleTestUtils.assertConsoleOutputContains(SqlJdbcExample::main, EMPTY_ARGS,
- ">>> Query results:\n" +
- ">>> John, Doe, Forest Hill\n" +
- ">>> Jane, Roe, Forest Hill\n" +
- ">>> Mary, Major, Denver\n" +
- ">>> Richard, Miles, St. Petersburg\n",
+ "\nAll accounts:\n" +
+ " John, Doe, Forest Hill\n" +
+ " Jane, Roe, Forest Hill\n" +
+ " Mary, Major, Denver\n" +
+ " Richard, Miles, St. Petersburg\n",
- ">>> Query results:\n" +
- ">>> John, Doe, 1000.0\n" +
- ">>> Richard, Miles, 1450.0\n",
+ "\nAccounts with balance lower than 1,500:\n" +
+ " John, Doe, 1000.0\n" +
+ " Richard, Miles, 1450.0\n",
- ">>> Query results:\n" +
- ">>> Jane, Roe, Forest Hill\n" +
- ">>> Mary, Major, Denver\n" +
- ">>> Richard, Miles, St. Petersburg\n"
+ "\nAll accounts:\n" +
+ " Jane, Roe, Forest Hill\n" +
+ " Mary, Major, Denver\n" +
+ " Richard, Miles, St. Petersburg\n"
);
}
diff --git a/examples/src/test/java/org/apache/ignite/example/table/TableExamplesTest.java b/examples/src/test/java/org/apache/ignite/example/table/TableExamplesTest.java
index 8c7daa6..2004ba6 100644
--- a/examples/src/test/java/org/apache/ignite/example/table/TableExamplesTest.java
+++ b/examples/src/test/java/org/apache/ignite/example/table/TableExamplesTest.java
@@ -40,8 +40,8 @@ public class TableExamplesTest {
*/
@Test
public void testRecordViewExample() throws Exception {
- ExampleTestUtils.assertConsoleOutput(RecordViewExample::main, EMPTY_ARGS,
- "Retrieved using Tuple API\n" +
+ ExampleTestUtils.assertConsoleOutputContains(RecordViewExample::main, EMPTY_ARGS,
+ "\nRetrieved record:\n" +
" Account Number: 123456\n" +
" Owner: Val Kulichenko\n" +
" Balance: $100.0\n");
@@ -54,8 +54,8 @@ public class TableExamplesTest {
*/
@Test
public void testKeyValueViewExample() throws Exception {
- ExampleTestUtils.assertConsoleOutput(KeyValueViewExample::main, EMPTY_ARGS,
- "Retrieved using Key-Value API\n" +
+ ExampleTestUtils.assertConsoleOutputContains(KeyValueViewExample::main, EMPTY_ARGS,
+ "\nRetrieved value:\n" +
" Account Number: 123456\n" +
" Owner: Val Kulichenko\n" +
" Balance: $100.0\n");