Esempio n. 1
0
 static public void FailCopyOutToStream()
 {
     cs        = new CountStream();
     cs.FailAt = 2;
     try
     {
         cout = new NpgsqlCopyOut(new NpgsqlCommand("COPY copy1 TO STDOUT", conn), conn, cs);
         cout.Start();
     }
     catch (Exception e)
     {
         if (("" + e).Contains("Test Exception handling"))
         {
             Console.Out.WriteLine("Copy to stream failed as requested.");
             return;
         }
         throw e;
     }
     finally
     {
         cs.Close();
         cout.End(); // should silently discard rest of data
     }
     throw new Exception("Copy to stream did not fail as requested");
 }
Esempio n. 2
0
    // Stream failure tests

    static public void FailCopyInFromStream()
    {
        cs            = new CountStream();
        cs.FailAt     = 2;
        cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read);
        cin           = new NpgsqlCopyIn(new NpgsqlCommand("COPY copy1 FROM STDIN DELIMITER '\b'", conn), conn, cs);
        try
        {
            cin.Start();
        }
        catch (Exception e)
        {
            if (("" + e).Contains("Test Exception handling"))
            {
                Console.Out.WriteLine("Copy from stream failed as requested.");
                return;
            }
            else
            {
                Console.Out.WriteLine("Copy from stream failing failed: " + e);
                throw e;
            }
        }
        finally
        {
            cs.Close();
            cin.End(); // should do nothing
        }
        Console.Out.WriteLine("Copy from stream did not fail as requested");
    }
Esempio n. 3
0
    static public void FailCopyInByWriting()
    {
        cs            = new CountStream();
        cs.FailAt     = 2;
        cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read);
        cin           = new NpgsqlCopyIn("COPY copy1 FROM STDIN", conn);
        cin.Start();
        if (!cin.IsActive)
        {
            throw new Exception("Copy started inactive");
        }
        byte[] buf = new byte[8];
        int    i;

        try
        {
            while ((i = cs.Read(buf, 0, buf.Length)) > 0)
            {
                cin.CopyStream.Write(buf, 0, i);
            }
        }
        catch (Exception e)
        {
            if (("" + e).Contains("Test Exception handling"))
            {
                try
                {
                    cin.Cancel("Test whether copy in fails correctly");
                }
                catch (Exception e2)
                {
                    if (("" + e2).Contains("Test whether copy in fails correctly"))
                    {
                        Console.Out.WriteLine("Copy from writing failed as requested.");
                        return;
                    }
                    throw e2;
                }
                throw new Exception("CopyIn.Cancel() didn't throw up the expected exception");
            }
            throw e;
        }
        finally
        {
            cs.Close();
            cin.End(); // should do nothing
        }
        throw new Exception("Copy from writing did not fail as requested");
    }
Esempio n. 4
0
    // Stream success tests

    static public void CopyInFromStream()
    {
        cs            = new CountStream();
        cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read);
        cin           = new NpgsqlCopyIn(new NpgsqlCommand("COPY copy1 FROM STDIN DELIMITER '\b'", conn), conn, cs);
        cin.Start();
        if (cin.IsActive)
        {
            throw new Exception("Copy from stream did not complete in single pass");
        }
        InLength += cs.BytesPassed;
        InSum    += cs.CheckSum;
        cs.Close();
        Console.Out.WriteLine("Copy from stream ok");
    }
Esempio n. 5
0
    static public void CopyOutByReading()
    {
        cs   = new CountStream();
        cout = new NpgsqlCopyOut("COPY copy1 TO STDOUT", conn);
        cout.Start();
        if (!cout.IsActive)
        {
            throw new Exception("Copy reading started inactive");
        }
        byte[] buf = new byte[9];
        int    i;

        while ((i = cout.CopyStream.Read(buf, 0, buf.Length)) > 0)
        {
            cs.Write(buf, 0, i);
        }
        cs.Close();
        cout.End();
        Console.Out.WriteLine("Lengths of text written to and read via stream from database differ by " + (InLength - cs.BytesPassed));
        Console.Out.WriteLine("Sums of characters written to and read via stream from database differ by " + (InSum - cs.CheckSum));
    }
Esempio n. 6
0
    static long InSum = 0; // this really is a SUM of the bytes! comparison depends on that.

    #endregion Fields

    #region Methods

    public static void CopyInByWriting()
    {
        cs = new CountStream();
        cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read);
        cin = new NpgsqlCopyIn( "COPY copy1 FROM STDIN DELIMITER '\b'", conn );
        cin.Start();
        if(! cin.IsActive)
        {
            throw new Exception("Copy started inactive");
        }
        byte[] buf = new byte[8];
        int i;
        while( (i = cs.Read(buf,0,buf.Length)) > 0 )
        {
            cin.CopyStream.Write(buf, 0, i);
        }
        cin.End();
        InLength += cs.BytesPassed;
        InSum += cs.CheckSum;
        cs.Close();
        Console.Out.WriteLine("Copy from writing ok");
    }
Esempio n. 7
0
    static public void CopyInByWriting()
    {
        cs            = new CountStream();
        cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read);
        cin           = new NpgsqlCopyIn("COPY copy1 FROM STDIN DELIMITER '\b'", conn);
        cin.Start();
        if (!cin.IsActive)
        {
            throw new Exception("Copy started inactive");
        }
        byte[] buf = new byte[8];
        int    i;

        while ((i = cs.Read(buf, 0, buf.Length)) > 0)
        {
            cin.CopyStream.Write(buf, 0, i);
        }
        cin.End();
        InLength += cs.BytesPassed;
        InSum    += cs.CheckSum;
        cs.Close();
        Console.Out.WriteLine("Copy from writing ok");
    }
Esempio n. 8
0
    static public void FailCopyOutByReading()
    {
        cs        = new CountStream();
        cs.FailAt = 2;
        cout      = new NpgsqlCopyOut("COPY copy1 TO STDOUT", conn);
        cout.Start();
        if (!cout.IsActive)
        {
            throw new Exception("Copy reading started inactive");
        }
        byte[] buf = new byte[9];
        int    i;

        try
        {
            while ((i = cout.CopyStream.Read(buf, 0, buf.Length)) > 0)
            {
                cs.Write(buf, 0, i);
            }
        }
        catch (Exception e)
        {
            if (("" + e).Contains("Test Exception handling"))
            {
                Console.Out.WriteLine("Copy to reading failed as requested.");
                return;
            }
            throw e;
        }
        finally
        {
            cs.Close();
            cout.End();
        }
        throw new Exception("Copy reading did not fail as requested");
    }
Esempio n. 9
0
 // Stream success tests
 public static void CopyInFromStream()
 {
     cs = new CountStream();
     cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read);
     cin = new NpgsqlCopyIn( new NpgsqlCommand("COPY copy1 FROM STDIN DELIMITER '\b'", conn), conn, cs );
     cin.Start();
     if(cin.IsActive)
     {
         throw new Exception("Copy from stream did not complete in single pass");
     }
     InLength += cs.BytesPassed;
     InSum += cs.CheckSum;
     cs.Close();
     Console.Out.WriteLine("Copy from stream ok");
 }
Esempio n. 10
0
 public static void FailCopyOutToStream()
 {
     cs = new CountStream();
     cs.FailAt = 2;
     try
     {
         cout = new NpgsqlCopyOut( new NpgsqlCommand("COPY copy1 TO STDOUT", conn), conn, cs );
         cout.Start();
     }
     catch(Exception e)
     {
         if( (""+e).Contains("Test Exception handling") )
         {
             Console.Out.WriteLine("Copy to stream failed as requested.");
             return;
         }
         throw e;
     }
     finally
     {
         cs.Close();
         cout.End(); // should silently discard rest of data
     }
     throw new Exception("Copy to stream did not fail as requested");
 }
Esempio n. 11
0
 public static void FailCopyOutByReading()
 {
     cs = new CountStream();
     cs.FailAt = 2;
     cout = new NpgsqlCopyOut( "COPY copy1 TO STDOUT", conn );
     cout.Start();
     if(! cout.IsActive)
     {
         throw new Exception("Copy reading started inactive");
     }
     byte[] buf = new byte[9];
     int i;
     try
     {
         while( (i = cout.CopyStream.Read(buf, 0, buf.Length)) > 0 )
         {
             cs.Write(buf, 0, i);
         }
     }
     catch(Exception e)
     {
         if( (""+e).Contains("Test Exception handling") )
         {
             Console.Out.WriteLine("Copy to reading failed as requested.");
             return;
         }
         throw e;
     }
     finally
     {
         cs.Close();
         cout.End();
     }
     throw new Exception("Copy reading did not fail as requested");
 }
Esempio n. 12
0
 // Stream failure tests
 public static void FailCopyInFromStream()
 {
     cs = new CountStream();
     cs.FailAt = 2;
     cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read);
     cin = new NpgsqlCopyIn( new NpgsqlCommand("COPY copy1 FROM STDIN DELIMITER '\b'", conn), conn, cs );
     try
     {
         cin.Start();
     }
     catch(Exception e)
     {
         if( (""+e).Contains("Test Exception handling") )
         {
             Console.Out.WriteLine("Copy from stream failed as requested.");
             return;
         }
         else
         {
             Console.Out.WriteLine("Copy from stream failing failed: " + e);
             throw e;
         }
     }
     finally
     {
         cs.Close();
         cin.End(); // should do nothing
     }
     Console.Out.WriteLine("Copy from stream did not fail as requested");
 }
Esempio n. 13
0
 public static void FailCopyInByWriting()
 {
     cs = new CountStream();
     cs.FailAt = 2;
     cs.WrapStream = new FileStream("test_copy.cs", FileMode.Open, FileAccess.Read);
     cin = new NpgsqlCopyIn( "COPY copy1 FROM STDIN", conn );
     cin.Start();
     if(! cin.IsActive)
     {
         throw new Exception("Copy started inactive");
     }
     byte[] buf = new byte[8];
     int i;
     try
     {
         while( (i = cs.Read(buf,0,buf.Length)) > 0 )
         {
             cin.CopyStream.Write(buf, 0, i);
         }
     }
     catch(Exception e)
     {
         if( (""+e).Contains("Test Exception handling") )
         {
             try
             {
                 cin.Cancel("Test whether copy in fails correctly");
             }
             catch(Exception e2)
             {
                 if( (""+e2).Contains("Test whether copy in fails correctly") )
                 {
                     Console.Out.WriteLine("Copy from writing failed as requested.");
                     return;
                 }
                 throw e2;
             }
             throw new Exception("CopyIn.Cancel() didn't throw up the expected exception");
         }
         throw e;
     }
     finally
     {
         cs.Close();
         cin.End(); // should do nothing
     }
     throw new Exception("Copy from writing did not fail as requested");
 }
Esempio n. 14
0
 public static void CopyOutByReading()
 {
     cs = new CountStream();
     cout = new NpgsqlCopyOut( "COPY copy1 TO STDOUT", conn );
     cout.Start();
     if(! cout.IsActive)
     {
         throw new Exception("Copy reading started inactive");
     }
     byte[] buf = new byte[9];
     int i;
     while( (i = cout.CopyStream.Read(buf, 0, buf.Length)) > 0 )
     {
         cs.Write(buf, 0, i);
     }
     cs.Close();
     cout.End();
     Console.Out.WriteLine("Lengths of text written to and read via stream from database differ by " + (InLength-cs.BytesPassed));
     Console.Out.WriteLine("Sums of characters written to and read via stream from database differ by " + (InSum-cs.CheckSum));
 }