public void SimpleTest()
{
var client = new PhoenixClient(_credentials);
string connId = GenerateRandomConnId();
RequestOptions options = RequestOptions.GetGatewayDefaultOptions();
// In gateway mode, url format will be https://<cluster dns name>.azurehdinsight.net/hbasephoenix<N>/
// Requests sent to hbasephoenix0/ will be forwarded to PQS on workernode0
options.AlternativeEndpoint = "hbasephoenix0/";
string tableName = "Persons" + connId;
OpenConnectionResponse openConnResponse = null;
CreateStatementResponse createStatementResponse = null;
try
{
// Opening connection
pbc::MapField<string, string> info = new pbc::MapField<string, string>();
openConnResponse = client.OpenConnectionRequestAsync(connId, info, options).Result;
// Syncing connection
ConnectionProperties connProperties = new ConnectionProperties
{
HasAutoCommit = true,
AutoCommit = true,
HasReadOnly = true,
ReadOnly = false,
TransactionIsolation = 0,
Catalog = "",
Schema = "",
IsDirty = true
};
client.ConnectionSyncRequestAsync(connId, connProperties, options).Wait();
createStatementResponse = client.CreateStatementRequestAsync(connId, options).Result;
// Running query 1
string sql1 = "CREATE TABLE " + tableName + " (LastName varchar(255) PRIMARY KEY,FirstName varchar(255))";
client.PrepareAndExecuteRequestAsync(connId, sql1, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
// Running query 2
string sql2 = "UPSERT INTO " + tableName + " VALUES ('d1','x1')";
client.PrepareAndExecuteRequestAsync(connId, sql2, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
// Running query 3
string sql3 = "select count(*) from " + tableName;
ExecuteResponse execResponse3 = client.PrepareAndExecuteRequestAsync(connId, sql3, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Result;
long count = execResponse3.Results[0].FirstFrame.Rows[0].Value[0].ScalarValue.NumberValue;
Assert.AreEqual(1, count);
// Running query 4
string sql4 = "DROP TABLE " + tableName;
client.PrepareAndExecuteRequestAsync(connId, sql4, createStatementResponse.StatementId, long.MaxValue, int.MaxValue, options).Wait();
}
catch (Exception ex)
{
Assert.Fail(ex.Message);
}
finally
{
if (createStatementResponse != null)
{
client.CloseStatementRequestAsync(connId, createStatementResponse.StatementId, options).Wait();
createStatementResponse = null;
}
if (openConnResponse != null)
{
client.CloseConnectionRequestAsync(connId, options).Wait();
openConnResponse = null;
}
}
}