This is an automated email from the ASF dual-hosted git repository.
ptupitsyn pushed a commit to branch ignite-14972
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/ignite-14972 by this push:
new ef87b3e00 FakeAsyncResultSet, FakeSession, FakeSessionBuilder
ef87b3e00 is described below
commit ef87b3e0037afa1f7d2d4ec0b6971efb226b92ba
Author: Pavel Tupitsyn <[email protected]>
AuthorDate: Mon May 30 20:06:24 2022 +0300
FakeAsyncResultSet, FakeSession, FakeSessionBuilder
---
.../ignite/client/fakes/FakeAsyncResultSet.java | 86 +++++++++
.../apache/ignite/client/fakes/FakeSession.java | 212 +++++++++++++++++++++
.../ignite/client/fakes/FakeSessionBuilder.java | 100 ++++++++++
3 files changed, 398 insertions(+)
diff --git
a/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeAsyncResultSet.java
b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeAsyncResultSet.java
new file mode 100644
index 000000000..5e496dbda
--- /dev/null
+++
b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeAsyncResultSet.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.client.fakes;
+
+import java.util.concurrent.CompletionStage;
+import org.apache.ignite.sql.ResultSetMetadata;
+import org.apache.ignite.sql.Session;
+import org.apache.ignite.sql.SqlRow;
+import org.apache.ignite.sql.Statement;
+import org.apache.ignite.sql.async.AsyncResultSet;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+public class FakeAsyncResultSet implements AsyncResultSet {
+ private final Session session;
+ private final Transaction transaction;
+ private final Statement statement;
+ private final Object[] arguments;
+
+ public FakeAsyncResultSet(Session session, Transaction transaction,
Statement statement, Object[] arguments) {
+ this.session = session;
+ this.transaction = transaction;
+ this.statement = statement;
+ this.arguments = arguments;
+ }
+
+ @Override
+ public @Nullable ResultSetMetadata metadata() {
+ return null;
+ }
+
+ @Override
+ public boolean hasRowSet() {
+ return false;
+ }
+
+ @Override
+ public long affectedRows() {
+ return 0;
+ }
+
+ @Override
+ public boolean wasApplied() {
+ return false;
+ }
+
+ @Override
+ public Iterable<SqlRow> currentPage() {
+ return null;
+ }
+
+ @Override
+ public int currentPageSize() {
+ return 0;
+ }
+
+ @Override
+ public CompletionStage<? extends AsyncResultSet> fetchNextPage() {
+ return null;
+ }
+
+ @Override
+ public boolean hasMorePages() {
+ return false;
+ }
+
+ @Override
+ public CompletionStage<Void> closeAsync() {
+ return null;
+ }
+}
diff --git
a/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeSession.java
b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeSession.java
new file mode 100644
index 000000000..613bce94e
--- /dev/null
+++
b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeSession.java
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.client.fakes;
+
+import static org.apache.ignite.internal.client.ClientUtils.sync;
+
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Flow.Publisher;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.sql.BatchedArguments;
+import org.apache.ignite.sql.ResultSet;
+import org.apache.ignite.sql.Session;
+import org.apache.ignite.sql.Statement;
+import org.apache.ignite.sql.async.AsyncResultSet;
+import org.apache.ignite.sql.reactive.ReactiveResultSet;
+import org.apache.ignite.tx.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Client SQL session.
+ */
+public class FakeSession implements Session {
+ @Nullable
+ private final Integer defaultPageSize;
+
+ @Nullable
+ private final String defaultSchema;
+
+ @Nullable
+ private final Long defaultTimeout;
+
+ @Nullable
+ private final Map<String, Object> properties;
+
+ /**
+ * Constructor.
+ *
+ * @param defaultPageSize Default page size.
+ * @param defaultSchema Default schema.
+ * @param defaultTimeout Default timeout.
+ * @param properties Properties.
+ */
+ @SuppressWarnings("AssignmentOrReturnOfFieldWithMutableType")
+ public FakeSession(
+ @Nullable Integer defaultPageSize,
+ @Nullable String defaultSchema,
+ @Nullable Long defaultTimeout,
+ @Nullable Map<String, Object> properties) {
+ this.defaultPageSize = defaultPageSize;
+ this.defaultSchema = defaultSchema;
+ this.defaultTimeout = defaultTimeout;
+ this.properties = properties;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public ResultSet execute(@Nullable Transaction transaction, String query,
@Nullable Object... arguments) {
+ // TODO: Wrap AsyncResultSet.
+ // return sync(executeAsync(transaction, query, arguments));
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public ResultSet execute(@Nullable Transaction transaction, Statement
statement, @Nullable Object... arguments) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public CompletableFuture<AsyncResultSet> executeAsync(@Nullable
Transaction transaction, String query, @Nullable Object... arguments) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public CompletableFuture<AsyncResultSet> executeAsync(
+ @Nullable Transaction transaction,
+ Statement statement,
+ @Nullable Object... arguments) {
+ Objects.requireNonNull(statement);
+
+ return CompletableFuture.completedFuture(new FakeAsyncResultSet(this,
transaction, statement, arguments));
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public ReactiveResultSet executeReactive(@Nullable Transaction
transaction, String query, @Nullable Object... arguments) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public ReactiveResultSet executeReactive(@Nullable Transaction
transaction, Statement statement, @Nullable Object... arguments) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int[] executeBatch(@Nullable Transaction transaction, String
dmlQuery, BatchedArguments batch) {
+ return new int[0];
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int[] executeBatch(@Nullable Transaction transaction, Statement
dmlStatement, BatchedArguments batch) {
+ return new int[0];
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public CompletableFuture<int[]> executeBatchAsync(@Nullable Transaction
transaction, String query, BatchedArguments batch) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public CompletableFuture<int[]> executeBatchAsync(@Nullable Transaction
transaction, Statement statement, BatchedArguments batch) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Publisher<Integer> executeBatchReactive(@Nullable Transaction
transaction, String query, BatchedArguments batch) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Publisher<Integer> executeBatchReactive(@Nullable Transaction
transaction, Statement statement, BatchedArguments batch) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void executeScript(String query, @Nullable Object... arguments) {
+
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public CompletableFuture<Void> executeScriptAsync(String query, @Nullable
Object... arguments) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public long defaultTimeout(TimeUnit timeUnit) {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public String defaultSchema() {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int defaultPageSize() {
+ return 0;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public @Nullable Object property(String name) {
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void close() {
+ sync(closeAsync());
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public CompletableFuture<Void> closeAsync() {
+ // TODO: Cancel/close all active futures.
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public Publisher<Void> closeReactive() {
+ // TODO: Future to Publisher.
+ return null;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public SessionBuilder toBuilder() {
+ return null;
+ }
+}
diff --git
a/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeSessionBuilder.java
b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeSessionBuilder.java
new file mode 100644
index 000000000..574d7d910
--- /dev/null
+++
b/modules/client/src/test/java/org/apache/ignite/client/fakes/FakeSessionBuilder.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.client.fakes;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Objects;
+import java.util.concurrent.TimeUnit;
+import org.apache.ignite.sql.Session;
+import org.apache.ignite.sql.Session.SessionBuilder;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Client SQL session builder.
+ */
+public class FakeSessionBuilder implements SessionBuilder {
+ /** */
+ private final Map<String, Object> properties = new HashMap<>();
+
+ /** */
+ private String defaultSchema;
+
+ /** */
+ private Long defaultTimeoutMs;
+
+ /** */
+ private Integer pageSize;
+
+ @Override
+ public long defaultTimeout(TimeUnit timeUnit) {
+ Objects.requireNonNull(timeUnit);
+
+ return timeUnit.convert(defaultTimeoutMs == null ? 0 :
defaultTimeoutMs, TimeUnit.MILLISECONDS);
+ }
+
+ @Override
+ public SessionBuilder defaultTimeout(long timeout, TimeUnit timeUnit) {
+ Objects.requireNonNull(timeUnit);
+
+ defaultTimeoutMs = TimeUnit.MILLISECONDS.convert(timeout, timeUnit);
+
+ return this;
+ }
+
+ @Override
+ public String defaultSchema() {
+ return defaultSchema;
+ }
+
+ @Override
+ public SessionBuilder defaultSchema(String schema) {
+ defaultSchema = schema;
+
+ return this;
+ }
+
+ @Override
+ public int defaultPageSize() {
+ return pageSize == null ? 0 : pageSize;
+ }
+
+ @Override
+ public SessionBuilder defaultPageSize(int pageSize) {
+ this.pageSize = pageSize;
+
+ return this;
+ }
+
+ @Override
+ public @Nullable Object property(String name) {
+ return properties.get(name);
+ }
+
+ @Override
+ public SessionBuilder property(String name, @Nullable Object value) {
+ properties.put(name, value);
+
+ return this;
+ }
+
+ @Override
+ public Session build() {
+ return new FakeSession(pageSize, defaultSchema, defaultTimeoutMs, new
HashMap<>(properties));
+ }
+}