com.hazelcast.org.apache.calcite.avatica.remote.MockProtobufService Maven / Gradle / Ivy
/*
* 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 com.hazelcast.org.apache.calcite.avatica.remote;
import com.hazelcast.org.apache.calcite.avatica.AvaticaConnection;
import com.hazelcast.org.apache.calcite.avatica.AvaticaParameter;
import com.hazelcast.org.apache.calcite.avatica.ColumnMetaData;
import com.hazelcast.org.apache.calcite.avatica.Meta;
import com.hazelcast.org.apache.calcite.avatica.MetaImpl;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
/**
* A mock implementation of ProtobufService for testing.
*
* It performs no serialization of requests and responses.
*/
public class MockProtobufService extends ProtobufService {
private final String connectionId;
private final Map mapping;
public MockProtobufService(String connectionId) {
this.connectionId = connectionId;
this.mapping = createMapping();
}
private Map createMapping() {
HashMap mappings = new HashMap<>();
// Add in mappings
mappings.put(
new OpenConnectionRequest(connectionId, new HashMap()),
new OpenConnectionResponse());
// Get the schema, no.. schema..?
mappings.put(
new SchemasRequest(connectionId, null, null),
// ownStatement=false just to avoid the extra close statement call.
new ResultSetResponse(null, 1, false, null, Meta.Frame.EMPTY, -1, null));
// Get the tables, no tables exist
mappings.put(new TablesRequest(connectionId, null, null, null, Collections.emptyList()),
// ownStatement=false just to avoid the extra close statement call.
new ResultSetResponse(null, 150, false, null, Meta.Frame.EMPTY, -1, null));
// Create a statement, get back an id
mappings.put(new CreateStatementRequest("0"), new CreateStatementResponse("0", 1, null));
// Prepare and execute a query. Values and schema are returned
mappings.put(
new PrepareAndExecuteRequest(connectionId, 1,
"select * from (\\n values (1, 'a'), (null, 'b'), (3, 'c')) as t (c1, c2)", -1),
new ResultSetResponse("0", 1, true,
Meta.Signature.create(
Arrays.asList(
MetaImpl.columnMetaData("C1", 0, Integer.class, true),
MetaImpl.columnMetaData("C2", 1, String.class, true)),
null, null, Meta.CursorFactory.ARRAY, Meta.StatementType.SELECT),
Meta.Frame.create(0, true,
Arrays.