Exemplo n.º 1
0
 /// <summary>
 /// Constructor for initialization 
 /// </summary>
 public ClientAPITest()
 {
   DependencyInjection di = DependencyInjection.GetInstance();
   di.SetConfig("config.xml");
   m_QueryObj = new QueryResult(result, message);
   m_Msg = new List<string>();
 }
Exemplo n.º 2
0
        /// <summary>
        /// Constructor for initialization 
        /// </summary>
        public RestAPI()
        {
            // Logger.LogWrite(EskimoDBLogLevel.Verbose, "Creating");
            DependencyInjection di = DependencyInjection.GetInstance();

            mockRootServer = (IRootServer)di.CreateObject("root", new object[]{
                this,new WSDualHttpBinding(),"http://localhost:8080/root"});
            mockAuthServer = (IAuthServer)di.CreateObject("auth", new object[]{
                null,new BasicHttpBinding(),"http://149.119.196.45:8080/IComm"});

            m_PutDataSetCalled = false;
            m_PutQueryInfoCalled = false;
            m_QueryResult = new QueryResult(0, null, null);
            m_id = null;
            m_QueryDataset = new QueryDataset(new System.Collections.Generic.List<Type>(), new System.Collections.Generic.List<string>());
            m_lines = 0;

            m_IterateToTheEnd = 0;
            m_CallGetResult = true;
            m_startLine = 0;
            m_RowsPerTime = 5;
            m_IterateIndex = 0;
            m_FinalLines = 0;
            m_Table = new Tables();

        }
Exemplo n.º 3
0
    /// <summary>
    /// Constructor for initialization 
    /// </summary>
    public MockRootServerTest()
    {
      m_Msg = new List<string>();
      m_IRootServerCallback = new ClientAPI();


      m_MockRootServerTestObj = new MockRootServer(m_IRootServerCallback, null, null);


      m_QueryResult = new QueryResult(m_Id, m_Content);
    }
Exemplo n.º 4
0
    /*
     * ExecQuery(query,token) receives a request with a authentication token.
     * It does a quick check on the validity of thetoken, and the query grammar, 
     * if the check doesn't pass it will return a result telling client the 
     * failure and info associated with the failure. If check passes, it adds 
     * the request to a queue, and notify client that the request is accepted.
     * @param query is the query string.
     * @param token is the authentication token
     * @returns whether the operation is successful and info related to the result.
     */
    public QueryResult ExecQuery(string query, string token)
    {
      QueryResult queryResult;
      DateTime dateTime;
      QueryProcessor queryProcessor = null;
      try
      {  
        DependencyInjection di = DependencyInjection.GetInstance();
        IAuthValidate iAuthValidate = (IAuthValidate)di.CreateObject("validate",
                                                                      new object[]
                                                                    { null,
                                                                      m_AuthSeverUrl
                                                                      });
                                                                   
        if (!iAuthValidate.Validate(token, out dateTime))
        {
          queryResult = new QueryResult(-1, "Could not authenticate user.");
          return queryResult;
        }
        
        if (!validateQuerySyntax(query, out queryResult))
        {
          return queryResult;
        }

        if (m_Statement != null)
        {
          queryProcessor = new QueryProcessor(m_ClientMap);
          IRootServerCallback callback = OperationContext.Current.GetCallbackChannel<IRootServerCallback>();
        Request request = queryProcessor.GetRequestObject(token, m_Statement, callback);
          request.setTableServerObject(m_ITableServer);
          m_RequestQueue.enQueueRequest(request);
          queryResult = new QueryResult(0, "Query syntax correct.");
          return queryResult;
        }
        else
        {
          queryResult = new QueryResult(-1, "Error parsing query.");
          return queryResult;
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine("RootServer:" + ex.Message);
      }
      queryResult = new QueryResult(-1, "Error parsing query.");
      return queryResult;
    }
Exemplo n.º 5
0
    private static void ProcessGetResult(Request request)
    {
      Object[] requestData = request.getMethodParameters();
      string id = requestData[0].ToString();
      int startLine = Convert.ToInt32(requestData[1]);
      int numberOfLines = Convert.ToInt32(requestData[2]);
      QueryResult queryResult;
      ResultStorage resultStorage = ResultStorage.Instance;
      QueryDataset queryDataset = resultStorage.GetQueryResult(id, startLine, numberOfLines);
      queryResult = new QueryResult(Convert.ToInt32(id), "Resulting rows being posted.");

      IRootServerCallback iRootServerCallback = request.getRootServerCallback();

      iRootServerCallback.PutDataset(queryResult, id, queryDataset);
    
    }
Exemplo n.º 6
0
    /// <summary>
    /// Constructor for initialization 
    /// </summary>
    public ClientAPI()
    {
      Logger.LogWrite("Initializing client api");

      m_PutDataSetCalled = false;
      m_PutQueryInfoCalled = false;
      m_QueryResult = new QueryResult(0, null, null);
      m_id = null;
      m_QueryDataset = new QueryDataset(new System.Collections.Generic.List<Type>(), new System.Collections.Generic.List<string>());
      m_lines = 0;

      m_IterateToTheEnd = 0;
      m_CallGetResult = true;
      m_startLine = 0;
      m_RowsPerTime = 5;
      m_IterateIndex = 0;
      m_FinalLines = 0;
      m_Table = new Tables();

    }
Exemplo n.º 7
0
 /// <summary>
 /// Implement the callback function PutQueryInfo()
 /// </summary>
 /// <param name="result"></param>
 /// <param name="id"></param>
 /// <param name="lines"></param>
 /// <returns></returns>
 public void PutQueryInfo(QueryResult result, string id, long lines)
 {
   m_QueryResult = result;
   m_id = id;
   m_lines = lines;
   m_PutQueryInfoCalled = true;
   return;
 }
Exemplo n.º 8
0
 /// <summary>
 /// Implement the callback function PutDataset()
 /// </summary>
 /// <param name="result"></param>
 /// <param name="id"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public void PutDataset(QueryResult result, string id, QueryDataset data)
 {
   m_QueryResult = result;
   m_id = id;
   m_QueryDataset = data;
   m_PutDataSetCalled = true;
   return;
 }
 public void PutQueryInfo(QueryResult result, string id, long lines)
 {
   Console.WriteLine("Mock root server PutQueryInfo callback called.");
   Console.WriteLine("Query Result: " + result.GetMessage());
 }
Exemplo n.º 10
0
 public void PutDataset(QueryResult result, string id, QueryDataset data)
 {
   Console.WriteLine("Mock root server PutDataset callback called.");
   Console.WriteLine("Query Result: " + result.GetMessage());
 }
Exemplo n.º 11
0
 public void PutQueryInfo(QueryResult result, string id, long lines)
 {
   Console.WriteLine("IRootServerCallback - put query info");
 }
Exemplo n.º 12
0
 public void PutDataset(QueryResult result, string id, QueryDataset data)
 {
   Console.WriteLine("IRootServerCallback - Put dataset called ");
 }
Exemplo n.º 13
0
    /// <summary>
    /// test 8
    /// testing the execution of the query 
    /// </summary>
    /// <returns></returns>
    private string Test8()
    {
      Message m8 = new Message();
      m8.TestID = 8;
      m_clientapi = new ClientAPI();
      m_clientapi.SetRootServer(RootServerUrl);
      m_clientapi.SetAuthHostAddress(AuthServerUrl);
      m_clientapi.ConfigClient();
      m_QueryObj = m_clientapi.ExecuteQuery("CREATE DB first_db", m_temptoken);
      if ((m_QueryObj.GetId() == 0) && (m_QueryObj.GetMessage() == "Database is not created"))
      {
        m8.Passed = false;
        m8.Msg = "m_clientapi.ExecuteQuery fails";
      }
      else
      {
        m8.Passed = true;
        m8.Msg = "m_clientapi.ExecuteQuery succeeds";
      }
      return m8.ToString();

    }
Exemplo n.º 14
0
 /// <summary>
 /// Function to insert items in the table , is table is created
 /// </summary>
 /// <returns></returns>
 private QueryResult InsertIntoTable()
 {
   string ret = string.Empty;
   if ((m_FirstDataBaseCreated == 0) && (m_TableCreated == 0))
   {
     m_ValuesInserted = 0;
     m_Result = m_ValuesInserted;
     m_Message = "Succeed";
     m_QueryResultObj = new QueryResult(m_Result, m_Message);
     m_IRootServerCallback.PutQueryInfo(m_QueryResultObj, "", 0);
     return m_QueryResultObj;
   }
   else
   {
     m_Result = m_TableCreated;
     m_Message = "Value cannot be inserted as the table is not created";
     m_QueryResultObj = new QueryResult(m_Result, m_Message);
     m_IRootServerCallback.PutQueryInfo(m_QueryResultObj, "", 0);
     return m_QueryResultObj;
   }
 }
Exemplo n.º 15
0
    /// <summary>
    /// Mock function to check that queries are executed in proper sequence
    /// Check the grammer of the query and allow operations accordingly.
    /// </summary>
    /// <param name="query"></param>
    /// <param name="token"></param>
    /// <returns> </returns>
    public QueryResult ExecQuery(string query, string token)
    {
      try
      {
        if (query == "CREATE DB first_db")
        {
          m_FirstDataBaseCreated = 0;
          m_Result = m_FirstDataBaseCreated;
          m_Message = "Database created";
          m_QueryResultObj = new QueryResult(m_Result, m_Message);
          m_IRootServerCallback.PutQueryInfo(m_QueryResultObj, "", 0);
          return m_QueryResultObj;
        }
        else if (query == "CREATE TABLE first_db.test_table (PRIMARY KEY prim INT, name VARCHAR(32))")
        {
          return CreateTable();
        }
        else if (query == "INSERT INTO first_db.test_table (name) VALUES 'user1'")
        {
          return InsertIntoTable();
        }
        else if (query == "INSERT INTO first_db.test_table (name) VALUES 'user2")
        {
          return InsertIntoTable();
        }
        else if (query == "INSERT INTO first_db.test_table (name) VALUES 'user3'")
        {
          return InsertIntoTable();
        }
        else if (query == @"SELECT * FROM first_db.test_table")
        {
          return SelectFromTable();
        }
        else
        {
          m_IRootServerCallback.PutQueryInfo(m_QueryResultObj, "", 0);

          return new QueryResult(0, "");
          // return new QueryResult(0, string.Empty);
        }
      }
      catch (Exception ex)
      {
        Console.WriteLine(ex.Message);
        return null;
      }
    }
Exemplo n.º 16
0
    /// <summary>
    /// Test 3
    /// Testing the insertion of data in the table
    /// </summary>
    /// <returns></returns>
    private String Test3()
    {
      Message m3 = new Message();
      m3.TestID = 3;
      m_QueryResult = m_MockRootServerTestObj.ExecQuery("INSERT INTO first_db.test_table (name) VALUES 'user1'", m_Token);
      if (m_QueryResult.GetId() == 1)
      {
        m3.Passed = false;
        m3.Msg = " m_MockRootServerTestObj.ExecQuery(INSERT INTO first_db.test_table ) fails";
      }
      else
      {
        m3.Passed = true;
        m3.Msg = " m_MockRootServerTestObj.ExecQuery(INSERT INTO first_db.test_table ) succeeds";
      }
      return m3.ToString();

    }
Exemplo n.º 17
0
 private bool validateQuerySyntax(string query, out QueryResult qr)
 {
   qr = null;
   try
   {
     if (query != "")
     {
       m_Statement = m_QParser.ValidateQuery(query);
       return true;
     }
     else
     {
       qr = new QueryResult(-1, "Error parsing the query.");
       return false;
     }
   }
   catch (QueryParserException qpe)
   {
     qr = new QueryResult(-1, qpe.Message);
     return false;
   }
   catch (Exception ex)
   {
     qr = new QueryResult(-1, ex.Message);
     return false;
   }
 }
Exemplo n.º 18
0
 /*
  * Release(id,token) will release the reference to a table object on root server
  * and let the table object be garbage collected.
  * @param id is the identifier for the table on root server.
  * @param token is the authentication token
  * @returns the result of operation and info related to the result.
  */
 public QueryResult Release(string id, string token)
 {
   Console.WriteLine("\n Release method.");
   QueryResult qr = new QueryResult(3, "release");
   return qr;
 }
Exemplo n.º 19
0
 /*
  * GetResult(id,startline,numberOfLines) receives a request asking for data
  * in a table stored on the root server. 
  * @param id is the identifier for the table on root server.
  * @param startLine is the first data entry that the client wants.
  * @param numberOfLines is the total number of data entries the client wants.
  * @param token is the authentication token.
  * @returns the result of operation and info related to the result.
  */
 public QueryResult GetResult(string id, int startLine, int numberOfLines, string token)
 {
   QueryResult queryResult;
   DateTime dateTime;
   DependencyInjection di = DependencyInjection.GetInstance();
   IAuthValidate iAuthValidate = (IAuthValidate)di.CreateObject("validate",new object[]
                                                                 { null,
                                                                   m_AuthSeverUrl
                                                                   });
   if (!iAuthValidate.Validate(token, out dateTime))
   {
     queryResult = new QueryResult(-1, "Could not authenticate user.");
     return queryResult;
   }
   Request request = new Request();
   request.SetRequestType(RequestType.GET_RESULT);
   request.setTableServerObject(m_ITableServer);
   Object[] requestData = new Object[3];
   requestData[0] = id;
   requestData[1] = startLine;
   requestData[2] = numberOfLines;
   request.SetMethodParameters(requestData);
   request.SetRootServerCallback(OperationContext.Current.GetCallbackChannel<IRootServerCallback>());
   
   m_RequestQueue.enQueueRequest(request);
   
   queryResult = new QueryResult(Convert.ToInt32(id), "Query result request received.");
   return queryResult;
 }
Exemplo n.º 20
0
 /// <summary>
 /// Function to get the result after execution of the query 
 /// </summary>
 /// <param name="id"></param>
 /// <param name="startLine"></param>
 /// <param name="numberOfLines"></param>
 /// <param name="token"></param>
 /// <returns> Result of the execution of the query </returns>
 public QueryResult GetResult(string id, int startLine, int numberOfLines, string token)
 {
   int m_Id = 1;
   string m_Result = string.Empty;
   QueryResult m_QueryResult = new QueryResult(m_Id, m_Result);
   QueryDataset m_QueryDataset = MockDataSet();
   m_IRootServerCallback.PutDataset(m_QueryResult, "1", m_QueryDataset);
   return m_QueryResult;
 }
Exemplo n.º 21
0
 /// <summary>
 /// Function to enable select queries
 /// </summary>
 /// <returns></returns>
 private QueryResult SelectFromTable()
 {
   string ret = string.Empty;
   //if ((m_TableCreated == 0) && (m_ValuesInserted == 0))
   //{
   m_TableSelected = 0;
   m_Result = m_TableSelected;
   m_Message = "Table selected";
   m_QueryResultObj = new QueryResult(m_Result, m_Message);
   m_IRootServerCallback.PutQueryInfo(m_QueryResultObj, "1", 10);
   return m_QueryResultObj;
   //}
   //else
   //{
   //    m_Result = m_TableSelected;
   //    m_Message = "Table cannot be selected";
   //    m_QueryResultObj = new QueryResult(m_Result, m_Message);
   //    m_IRootServerCallback.PutQueryInfo(m_QueryResultObj, "", 0);
   //    return m_QueryResultObj;
   //}
 }
Exemplo n.º 22
0
    /// <summary>
    /// test 2
    /// Testing the creation of the table 
    /// </summary>
    /// <returns></returns>
    private String Test2()
    {

      Message m2 = new Message();
      m2.TestID = 2;
      m_QueryResult = m_MockRootServerTestObj.ExecQuery("CREATE TABLE first_db.test_table (PRIMARY KEY prim INT, name VARCHAR(32))", m_Token);
      if (m_QueryResult.GetId() == 1)
      {
        m2.Passed = false;
        m2.Msg = " m_MockRootServerTestObj.ExecQuery(CREATE TABLE first_db.test_table) fails";
      }
      else
      {
        m2.Passed = true;
        m2.Msg = " m_MockRootServerTestObj.ExecQuery(CREATE TABLE first_db.test_table) succeeds";
      }
      return m2.ToString();
    }
Exemplo n.º 23
0
 /// <summary>
 /// This function will be used to release the table object at server for garbage collection. 
 /// </summary>
 /// <param name="id"></param>
 /// <param name="token"></param>
 /// <returns> A QueryResult object which describes info related to table  </returns>
 public QueryResult Release(string id, string token)
 {
   int m_Id = 1;
   string m_Result = string.Empty;
   QueryResult m_QueryResultObj = new QueryResult(m_Id, m_Result);
   return m_QueryResultObj;
 }
Exemplo n.º 24
0
 /// <summary>
 /// test 4
 /// Testing the selection query from the database 
 /// </summary>
 /// <returns></returns>
 private String Test4()
 {
   Message m4 = new Message();
   m4.TestID = 4;
   m_QueryResult = m_MockRootServerTestObj.ExecQuery(@"SELECT * FROM first_db.test_table", m_Token);
   if (m_QueryResult.GetId() == 1)
   {
     m4.Passed = false;
     m4.Msg = " m_MockRootServerTestObj.ExecQuery(SELECT * FROM first_db.test_table) fails";
   }
   else
   {
     m4.Passed = true;
     m4.Msg = " m_MockRootServerTestObj.ExecQuery(SELECT * FROM first_db.test_table) succeeds";
   }
   return m4.ToString();
 }
Exemplo n.º 25
0
    private static void ProcessExecQuery(Request request)
    {
      ITableServer tableServerObject = request.getTableServerObject();
      Type created = tableServerObject.GetType();

      Object resultObject = created.InvokeMember(request.getCallingMethod(),
                                                  System.Reflection.BindingFlags.Default | System.Reflection.BindingFlags.InvokeMethod,
                                                  null,
                                                  tableServerObject,
                                                  request.getMethodParameters()
                                                  );
      TableResponse tableResponse = (TableResponse)resultObject;
      IRootServerCallback iRootServerCallback = request.getRootServerCallback();
      string id = tableResponse.GetId;
      QueryResult queryResult;

      queryResult = new QueryResult(Convert.ToInt32(id), tableResponse.GetMessage);
      iRootServerCallback.PutQueryInfo(queryResult, id, 0);
    }
Exemplo n.º 26
0
    /// <summary>
    /// test 1
    /// Testing the creation of the database 
    /// </summary>
    /// <returns></returns>
    private String Test1()
    {

      Message m1 = new Message();
      m1.TestID = 1;
      m_QueryResult = m_MockRootServerTestObj.ExecQuery("CREATE DB first_db", m_Token);
      if (m_QueryResult.GetId() == 1)
      {
        m1.Passed = false;
        m1.Msg = " m_MockRootServerTestObj.ExecQuery(CREATE DB first_db) fails";
      }
      else
      {
        m1.Passed = true;
        m1.Msg = " m_MockRootServerTestObj.ExecQuery(CREATE DB first_db) succeeds";
      }
      return m1.ToString();

    }
Exemplo n.º 27
0
 /// <summary>
 /// Function to create a new table
 /// </summary>
 /// <returns></returns>
 private QueryResult CreateTable()
 {
   string ret = string.Empty;
   if (m_FirstDataBaseCreated == 0)
   {
     m_TableCreated = 0;
     m_Message = "Succeed";
     m_Result = m_TableCreated;
     m_QueryResultObj = new QueryResult(m_Result, m_Message);
     m_IRootServerCallback.PutQueryInfo(m_QueryResultObj, "", 0);
     return m_QueryResultObj;
   }
   else
   {
     m_Result = m_TableCreated;
     m_Message = "Database is not created";
     m_QueryResultObj = new QueryResult(m_Result, m_Message);
     m_IRootServerCallback.PutQueryInfo(m_QueryResultObj, "", 0);
     return m_QueryResultObj;
   }
 }