Esempio n. 1
0
        public void ErlParserTest()
        {
            var tests = new Dictionary <string, IErlObject>
            {
                { "<<1,2,3>>", new ErlBinary(new byte[] { 1, 2, 3 }) },
                { "<<>>", new ErlBinary(new byte[] {}) },
                { "<<\"abc\">>", new ErlBinary(new byte[] { (byte)'a', (byte)'b', (byte)'c' }) },
                { "<<\"\">>", new ErlBinary(new byte[] {}) },
            };

            foreach (var t in tests)
            {
                try
                {
                    ErlObject.Parse(t.Key, t.Value);
                    Aver.Pass();
                }
                catch (Exception)
                {
                    Aver.Fail("Error parsing: {0} (test: {1})".Args(t.Key, t.ToString()));
                }

                var res = ErlObject.Parse(t.Key, t.Value);
                Aver.AreEqual(t.Value, res,
                              "Unexpected value: {0} (expected: {1})".Args(res, t.Value));
            }
        }
Esempio n. 2
0
        public void InvalidBoundaryFromOutside()
        {
            var test = Encoding.UTF8.GetBytes(
                @"--7de23d3b1d07fe
Content-Disposition: form-data; name=""name1""

value 1
--7de23d3b1d07fe
Content-Disposition: form-data; name=""name2""

value 2
--7de23d3b1d07fe--
");
            string boundary = "8asd56sge";

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Invalid explicit boundary");
            }
            catch (Exception ex)
            {
                Conout.Write(ex.ToMessageWithType());
                Aver.IsTrue(ex.Message.Contains(StringConsts.MULTIPART_SPECIFIED_BOUNDARY_ISNT_FOUND_ERROR));
            }
        }
Esempio n. 3
0
        public static async Task ASYNC_TestContractA_TwoWayCall_Timeout(string CONF_SRC)
        {
            TestServerA.s_Accumulator = 0;

            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);

            using (var app = new AzosApplication(null, conf.Root))
            {
                var cl = new TestContractAClient(app.Glue, app.ConfigRoot.AttrByName("cs").Value);
                cl.TimeoutMs = 2000;

                CallSlot call = null;
                try
                {
                    call = await cl.Async_Sleeper(10000);

                    call.GetValue <int>();
                }
                catch (ClientCallException err)
                {
                    Aver.IsTrue(CallStatus.Timeout == err.Status);
                    return;
                }
                catch (System.IO.IOException err) //sync binding throws IO exception
                {
                    Aver.IsTrue(err.Message.Contains("after a period of time"));
                    return;
                }

                Aver.Fail("Invalid Call status: " + (call != null ? call.CallStatus.ToString() : "call==null"));
            }
        }
Esempio n. 4
0
        public void Test_DocCompositeField_2()
        {
            using (var app = new AzosApplication(null, BASE_CONF))
            {
                var doc = new DocCompositeField();
                doc.D1 = new DocDirectField();
                doc.D2 = new DocDirectField {
                    S1 = "kgergegergegegeyrepkpperunvpuewpfoue[rputme[wutmpwempfouwm"
                };
                var ve = doc.Validate(app);
                Aver.IsNotNull(ve);
                if (ve is FieldValidationException fve)
                {
                    Console.WriteLine(fve.Message);
                    Aver.IsTrue(fve.Message.Contains("list"));
                }
                else
                {
                    Aver.Fail("Not a FVExcp");
                }


                doc.D2.S1 = "key";
                ve        = doc.Validate(app);
                Aver.IsNull(ve);
            }
        }
Esempio n. 5
0
        public void Test_DocArray_3()
        {
            using (var app = new AzosApplication(null, BASE_CONF))
            {
                var doc = new DocArray();
                doc.IMin   = 5000;
                doc.DArray = new[] { new DocCompositeField {
                                         D1 = new DocDirectField {
                                             S1 = "zzzzkey"
                                         }, D2 = new DocDirectField {
                                             S1 = "key"
                                         }
                                     } };

                var ve = doc.Validate(app);
                Aver.IsNotNull(ve);
                if (ve is FieldValidationException fve)
                {
                    fve.Message.See();
                    Aver.IsTrue(fve.Message.Contains("list"));
                }
                else
                {
                    Aver.Fail(Constants.ERR_NOT_FVEXCP);
                }


                doc.DArray[0].D1.S1 = "key";
                ve = doc.Validate(app);
                Aver.IsNull(ve);
            }
        }
Esempio n. 6
0
        bool IRunnableHook.Epilogue(Runner runner, FID id, Exception error)
        {
            Aver.Fail(" As of 20210730 This test suite is no longer supported and needs to be completely re-written in Sky ==================================================== ");

            m_ServerProcess.StandardInput.WriteLine(string.Empty);
            return(false);
        }
Esempio n. 7
0
        public void DuplicatedNames()
        {
            var test = Encoding.UTF8.GetBytes(
                @"-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""name""

value 1
-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""name""

value 2
-----------------------------7de23d3b1d07fe--
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Repeated name!");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains("is already registered."));
            }
        }
Esempio n. 8
0
        public void NonNull_2()
        {
            object x = null;

            try
            {
                x.NonNull();
                Aver.Fail("ShouldNever be here");
            }
            catch (CallGuardException error)
            {
                Console.WriteLine(error.ToMessageWithType());
                Aver.IsTrue(error.Message.Contains("'<unknown>' may not be null"));
            }

            try
            {
                x.NonNull(nameof(x));
                Aver.Fail("ShouldNever be here");
            }
            catch (CallGuardException error)
            {
                Console.WriteLine(error.ToMessageWithType());
                Aver.IsTrue(error.Message.Contains("'x' may not be null"));
            }
        }
Esempio n. 9
0
        public void Test_DocList_3()
        {
            using (var app = new AzosApplication(null, BASE_CONF))
            {
                var doc = new DocList();
                doc.IMin  = 5000;
                doc.DList = new List <object> {
                    new DocCompositeField {
                        D1 = new DocDirectField {
                            S1 = "zzzzkey"
                        }, D2 = new DocDirectField {
                            S1 = "key"
                        }
                    }
                };

                var ve = doc.Validate(app);
                Aver.IsNotNull(ve);
                if (ve is FieldValidationException fve)
                {
                    Console.WriteLine(fve.Message);
                    Aver.IsTrue(fve.Message.Contains("list"));
                }
                else
                {
                    Aver.Fail("Not a FVExcp");
                }


                ((DocCompositeField)doc.DList[0]).D1.S1 = "key";
                ve = doc.Validate(app);
                Aver.IsNull(ve);
            }
        }
Esempio n. 10
0
        public void Test_DocArray_2()
        {
            using (var app = new AzosApplication(null, BASE_CONF))
            {
                var doc = new DocArray();
                doc.IMin   = 5;//below acceptable
                doc.DArray = new[] { new DocCompositeField {
                                         D1 = new DocDirectField {
                                             S1 = "key"
                                         }, D2 = new DocDirectField {
                                             S1 = "key"
                                         }
                                     } };

                var ve = doc.Validate(app);
                Aver.IsNotNull(ve);
                if (ve is FieldValidationException fve)
                {
                    Console.WriteLine(fve.Message);
                    Aver.IsTrue(fve.Message.Contains("min"));
                }
                else
                {
                    Aver.Fail("Not a FVExcp");
                }


                doc.IMin = 5000;
                ve       = doc.Validate(app);
                Aver.IsNull(ve);
            }
        }
Esempio n. 11
0
        public void NonBlank_2()
        {
            string x = null;

            try
            {
                x.NonBlank();
                Aver.Fail("ShouldNever be here");
            }
            catch (Exception error) when(!(error is AvermentException))
            {
                Console.WriteLine(error.ToMessageWithType());
                Aver.IsTrue(error.Message.Contains("'<unknown>' may not be blank"));
            }

            try
            {
                x.NonBlank(nameof(x));
                Aver.Fail("ShouldNever be here");
            }
            catch (Exception error) when(!(error is AvermentException))
            {
                Console.WriteLine(error.ToMessageWithType());
                Aver.IsTrue(error.Message.Contains("'x' may not be blank"));
            }
        }
Esempio n. 12
0
        public void NonNull_2()
        {
            object x = null;

            try
            {
                x.NonNull();
                Aver.Fail(Constants.ERR_NOT_THROWN);
            }
            catch (CallGuardException error)
            {
                error.ToMessageWithType().See();
                Aver.IsTrue(error.Message.Contains("'<unknown>' may not be null"));
            }

            try
            {
                x.NonNull(nameof(x));
                Aver.Fail(Constants.ERR_NOT_THROWN);
            }
            catch (CallGuardException error)
            {
                error.ToMessageWithType().See();
                Aver.IsTrue(error.Message.Contains("'x' may not be null"));
            }
        }
Esempio n. 13
0
        public static void TASK_TestContractA_TwoWayCall_Timeout(string CONF_SRC)
        {
            TestServerA.s_Accumulator = 0;

            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);

            using (var app = new ServiceBaseApplication(null, conf.Root))
            {
                var cl = new TestContractAClient(App.ConfigRoot.AttrByName("cs").Value);
                cl.TimeoutMs = 2000;

                System.Threading.Tasks.Task <CallSlot> task = null;
                try
                {
                    task = cl.Async_Sleeper(10000).AsTask;
                    task.Result.GetValue <int>();
                }
                catch (ClientCallException err)
                {
                    Aver.IsTrue(CallStatus.Timeout == err.Status);
                    return;
                }
                catch (System.IO.IOException err) //sync binding throws IO exception
                {
                    Aver.IsTrue(err.Message.Contains("after a period of time"));
                    return;
                }

                Aver.Fail("Invalid Call status: " + (task != null ? task.Result.CallStatus.ToString() : "task==null"));
            }
        }
Esempio n. 14
0
        public static void TestContractA_TwoWayCall_Timeout(string CONF_SRC)
        {
            TestServerA.s_Accumulator = 0;

            var conf = LaconicConfiguration.CreateFromString(CONF_SRC);

            using (var app = new ServiceBaseApplication(null, conf.Root))
            {
                var cl = new TestContractAClient(App.ConfigRoot.AttrByName("cs").Value);
                cl.TimeoutMs = 2000;

                try
                {
                    cl.Sleeper(5000);
                }
                catch (ClientCallException err)
                {
                    Aver.IsTrue(CallStatus.Timeout == err.Status);
                    return;
                }
                catch (System.IO.IOException err) //sync binding throws IO exception
                {
                    Aver.IsTrue(err.Message.Contains("after a period of time"));
                    return;
                }

                Aver.Fail("Invalid Call status");
            }
        }
Esempio n. 15
0
        public void SetCountLimit_Throw()
        {
            var sut = new CappedQueue <MyItem>(i => i == null ? 0 : i.Name == null ? 0 : i.Name.Length);

            sut.CountLimit = 3;
            sut.Handling   = QueueLimitHandling.Throw;

            Aver.IsTrue(sut.TryEnqueue(new MyItem {
                Name = "Cat"
            }));
            Aver.AreEqual(1, sut.Count);

            Aver.IsTrue(sut.TryEnqueue(new MyItem {
                Name = "Dog"
            }));
            Aver.AreEqual(2, sut.Count);

            Aver.IsTrue(sut.TryEnqueue(null));
            Aver.AreEqual(3, sut.Count);

            try
            {
                //Rabbit will not fit - will throw
                Aver.IsFalse(sut.TryEnqueue(new MyItem {
                    Name = "Rabbit"
                }));
            }
            catch (AzosException error)
            {
                Aver.IsTrue(error.Message.Contains("limit is reached"));
                Conout.WriteLine("Expected and got: " + error.ToMessageWithType());
                return;
            }
            Aver.Fail("No expected exception");
        }
Esempio n. 16
0
        public void Verify_InvalidHash()
        {
            var  buf = IDPasswordCredentials.PlainPasswordToSecureBuffer("@8luE+5ky=");
            var  hash = Manager.ComputeHash(PasswordFamily.Text, buf);
            bool rehash, check;

            hash["salt"] = null;
            try
            {
                check = Manager.Verify(buf, hash, out rehash);
                Aver.Fail("no exception");
            }
            catch (AzosException e)
            {
                Aver.IsTrue(e.Message.Contains("ExtractPasswordHashingOptions((hash|hash[salt])==null)"));
            }

            hash = null;
            try
            {
                check = Manager.Verify(buf, hash, out rehash);
                Aver.Fail("no exception");
            }
            catch (AzosException e)
            {
                Aver.IsTrue(e.Message.Contains("Verify((password|hash)==null)"));
            }
        }
Esempio n. 17
0
        public void Test_DocList_2()
        {
            using (var app = new AzosApplication(null, BASE_CONF))
            {
                var doc = new DocList();
                doc.IMin  = 5;//below acceptable
                doc.DList = new List <object> {
                    new DocCompositeField {
                        D1 = new DocDirectField {
                            S1 = "key"
                        }, D2 = new DocDirectField {
                            S1 = "key"
                        }
                    }
                };

                var ve = doc.Validate(app);
                Aver.IsNotNull(ve);
                if (ve is FieldValidationException fve)
                {
                    fve.Message.See();
                    Aver.IsTrue(fve.Message.Contains("min"));
                }
                else
                {
                    Aver.Fail(Constants.ERR_NOT_FVEXCP);
                }


                doc.IMin = 5000;
                ve       = doc.Validate(app);
                Aver.IsNull(ve);
            }
        }
Esempio n. 18
0
        public static Amount Parse(string val)
        {
            if (val == null)
            {
                throw new FinancialException(StringConsts.ARGUMENT_ERROR + typeof(Amount).FullName + ".Parse(null)");
            }

            try
            {
                var i = val.IndexOf(':');
                if (i < 0)
                {
                    var dv = decimal.Parse(val);
                    return(new Amount(null, dv));
                }
                else
                {
                    var iso = val.Substring(i + 1);
                    iso = iso.Trim();
                    if (iso.IsNullOrWhiteSpace())
                    {
                        Aver.Fail("Nothing after :");
                    }
                    var dv = decimal.Parse(val.Substring(0, i), INVARIANT);
                    return(new Amount(iso, dv));
                }
            }
            catch
            {
                throw new FinancialException(StringConsts.FINANCIAL_AMOUNT_PARSE_ERROR.Args(val.TakeFirstChars(24, "..")));
            }
        }
Esempio n. 19
0
        public void InvalidEOF()
        {
            var test = Encoding.UTF8.GetBytes(
                @"-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""field1""

value 1
-----------------------------7de23d3b1d07fe
Content-Disposition: form-data; name=""field2""

value 2--
");
            string boundary = null;

            try
            {
                var mp = Multipart.ReadFromBytes(test, ref boundary);
                Aver.Fail("Invalid EOF!");
            }
            catch (Exception e)
            {
                Conout.Write(e.ToMessageWithType());
                Aver.IsTrue(e.Message.Contains(StringConsts.MULTIPART_TERMINATOR_ISNT_FOUND_ERROR));
            }
        }
Esempio n. 20
0
        public void ErlParserMFATest()
        {
            var tests = new Dictionary <string, Tuple <string, string, ErlList, object[]> >
            {
                { "a:b()", Tuple.Create("a", "b", new ErlList(), (object[])null) },
                { "a:b().", Tuple.Create("a", "b", new ErlList(), (object[])null) },
                { "a:b()\t      .", Tuple.Create("a", "b", new ErlList(), (object[])null) },
                { "a:b()       ", Tuple.Create("a", "b", new ErlList(), (object[])null) },
                { "a:b()\n.", Tuple.Create("a", "b", new ErlList(), (object[])null) },
                { "a:b(%comment\n).", Tuple.Create("a", "b", new ErlList(), (object[])null) },
                { "a:b().%comment", Tuple.Create("a", "b", new ErlList(), (object[])null) },
                { "a:b()\t", Tuple.Create("a", "b", new ErlList(), (object[])null) },
                { "a:b(10)", Tuple.Create("a", "b", new ErlList(10), (object[])null) },
                { "a:b(10).", Tuple.Create("a", "b", new ErlList(10), (object[])null) },
                { "aa:bb(10)", Tuple.Create("aa", "bb", new ErlList(10), (object[])null) },
                { "a:b(10,20)", Tuple.Create("a", "b", new ErlList(10, 20), (object[])null) },
                { "a:b(~w)", Tuple.Create("a", "b", new ErlList(10), new object[] { 10 }) },
                { "a:b(~w).", Tuple.Create("a", "b", new ErlList(10), new object[] { 10 }) },
                {
                    "a:b(~f,~d).",
                    Tuple.Create("a", "b", new ErlList(10d, 20), new object[] { 10d, 20 })
                },
                {
                    "a:b([~w,~w],30)",
                    Tuple.Create("a", "b", new ErlList(new ErlList(10, 20), 30),
                                 new object[] { 10, 20 })
                },
                {
                    "a:b([~w,~w],~w)",
                    Tuple.Create("a", "b", new ErlList(new ErlList(10, 20), 30),
                                 new object[] { 10, 20, 30 })
                },
            };

            foreach (var t in tests)
            {
                try
                {
                    ErlObject.ParseMFA(t.Key, t.Value.Item4);
                    Aver.Pass();
                }
                catch (Exception)
                {
                    Aver.Fail("Error parsing: {0} (test: {1})".Args(t.Key, t.ToString()));
                }

                var res = ErlObject.ParseMFA(t.Key, t.Value.Item4);
                Aver.AreEqual(t.Value.Item1, res.Item1.Value,
                              "Unexpected module value: {0} (expected: {1})".Args(
                                  res.Item1.Value, t.Value.Item1));
                Aver.AreEqual(t.Value.Item2, res.Item2.Value,
                              "Unexpected function value: {0} (expected: {1})".Args(
                                  res.Item2.Value, t.Value.Item2));
                Aver.AreObjectsEqual(t.Value.Item3, res.Item3,
                                     "Unexpected args value: {0} (expected: {1})".Args(res.Item3,
                                                                                       t.Value.Item3));
            }
        }
Esempio n. 21
0
        public void PaymethodToken()
        {
            if ((PaySystem.PaySystemHost as FakePaySystemHost).BraintreePayMethodToken.IsNullOrEmpty())
            {
                Aver.Fail("System variable BRAINTREE_SANDBOX_PAYMETHOD_TOKEN is not set");
            }

            Transaction tran = null;

            using (var session = BraintreeSystem.StartSession())
            {
                ((BraintreeSystem)BraintreeSystem).GenerateClientToken(session);

                var fromAccount = new Account("user", FakePaySystemHost.BRAINTREE_WEB_TERM, "PaymethodToken");
                var toAccount   = Account.EmptyInstance;
                session.StoreAccountData(new ActualAccountData(fromAccount)
                {
                    Identity      = fromAccount.Identity,
                    IsWebTerminal = false,
                    AccountID     = (PaySystem.PaySystemHost as FakePaySystemHost).BraintreePayMethodToken,
                    FirstName     = "Stan",
                    LastName      = "Ulam",
                    Phone         = "(333) 777-77-77",
                    EMail         = "*****@*****.**"
                });
                session.StoreAccountData(new ActualAccountData(toAccount));
                tran = session.Charge(fromAccount, toAccount, new Amount("usd", 99M), capture: false);
            }

            Aver.IsTrue(tran.Status == TransactionStatus.Success);
            Aver.IsTrue(tran.Type == TransactionType.Charge);
            Aver.AreObjectsEqual(tran.Amount, new Amount("usd", 99M));
            Aver.AreObjectsEqual(tran.AmountCaptured, new Amount("usd", 0M));
            Aver.IsTrue(tran.CanCapture);
            Aver.IsFalse(tran.CanRefund);
            Aver.IsTrue(tran.CanVoid);

            tran.Capture();
            Aver.IsTrue(tran.Status == TransactionStatus.Success);
            Aver.AreObjectsEqual(tran.Amount, new Amount("usd", 99M));
            Aver.AreObjectsEqual(tran.AmountCaptured, new Amount("usd", 99M));
            Aver.AreObjectsEqual(tran.AmountRefunded, new Amount("usd", 0M));
            Aver.IsFalse(tran.CanCapture);
            Aver.IsTrue(tran.CanRefund);
            Aver.IsFalse(tran.CanVoid);

            tran.Refund();
            Aver.IsTrue(tran.Status == TransactionStatus.Success);
            Aver.AreObjectsEqual(tran.Amount, new Amount("usd", 99M));
            Aver.AreObjectsEqual(tran.AmountCaptured, new Amount("usd", 99M));
            Aver.AreObjectsEqual(tran.AmountRefunded, new Amount("usd", 99M));
            Aver.IsFalse(tran.CanCapture);
            Aver.IsFalse(tran.CanRefund);
            Aver.IsFalse(tran.CanVoid);
        }
Esempio n. 22
0
        public void PutCheckerboardPattern3()
        {
            using (var pile = MakeMMFPile())
            {
                pile.Start();
                var ipile = pile as IPile;

                const ulong CNT = 123;

                var ppp = new Tuple <PilePointer, string> [CNT];

                for (ulong i = 0; i < CNT; i++)
                {
                    var str = NFX.Parsing.NaturalTextGenerator.Generate(179);
                    ppp[i] = new Tuple <PilePointer, string>(ipile.Put(str), str);
                }

                Aver.AreEqual(CNT, (ulong)ipile.ObjectCount);

                for (ulong i = 0; i < CNT; i++)
                {
                    if (i % 3 != 0)
                    {
                        ipile.Delete(ppp[i].Item1);
                    }
                }

                Aver.AreEqual(CNT / 3, (ulong)ipile.ObjectCount);

                for (ulong i = 0; i < CNT; i++)
                {
                    if (i % 3 != 0)
                    {
                        try
                        {
                            ipile.Get(ppp[i].Item1);
                            Aver.Fail("Object is deleted but its pointer doesn't throw exception!");
                        }
                        catch (PileAccessViolationException) {}
                    }
                    else
                    {
                        var ch = ipile.Get(ppp[i].Item1);
                        Aver.AreObjectsEqual(ppp[i].Item2, ch);
                    }
                }

                ////Console.WriteLine("ObjectCount: {0}", ipile.ObjectCount);
                ////Console.WriteLine("AllocatedMemoryBytes: {0}", ipile.AllocatedMemoryBytes);
                ////Console.WriteLine("UtilizedBytes: {0}", ipile.UtilizedBytes);
                ////Console.WriteLine("OverheadBytes: {0}", ipile.OverheadBytes);
                ////Console.WriteLine("SegmentCount: {0}", ipile.SegmentCount);
            }
        }
Esempio n. 23
0
        public void Parallel_PutDeleteGet_Checkerboard()
        {
            const int CNT    = 1002030;//1000203;
            var       tuples = new Tuple <PilePointer, ChargeRow> [CNT];

            using (var pile = new DefaultPile())
            {
                pile.Start();

                var ipile = pile as IPile;

                Parallel.For(0, CNT, i => {
                    var ch    = ChargeRow.MakeFake(new GDID(0, (ulong)i));
                    var pp    = ipile.Put(ch);
                    tuples[i] = new Tuple <PilePointer, ChargeRow>(pp, ch);
                });

                Aver.AreEqual(CNT, ipile.ObjectCount);

                Parallel.For(0, CNT, i => {
                    if (i % 3 != 0)
                    {
                        ipile.Delete(tuples[i].Item1);
                    }
                });

                Aver.AreEqual(CNT / 3, ipile.ObjectCount);

                var deletedHits = new ConcurrentDictionary <int, int>();

                Parallel.For(0, CNT, i => {
                    if (i % 3 != 0)
                    {
                        try
                        {
                            deletedHits.AddOrUpdate(System.Threading.Thread.CurrentThread.ManagedThreadId, 1, (threadId, val) => val + 1);
                            ipile.Get(tuples[i].Item1);
                            Aver.Fail("Object is deleted but its pointer doesn't throw exception!");
                        }
                        catch (PileAccessViolationException) {}
                    }
                    else
                    {
                        var ch = ipile.Get(tuples[i].Item1);
                        Aver.AreObjectsEqual(ch, tuples[i].Item2);
                    }
                });

                foreach (var kvp in deletedHits)
                {
                    Console.WriteLine("Thread '{0}' {1:n0} times accessed deleted pointer", kvp.Key, kvp.Value);
                }
            }
        }
Esempio n. 24
0
 public void TryCreatePart_NullName()
 {
     try
     {
         var part = new Multipart.Part(null);
         Aver.Fail("Invalid name!");
     }
     catch (Exception e)
     {
         Aver.IsTrue(e.Message.Contains(Azos.Web.StringConsts.MULTIPART_PART_EMPTY_NAME_ERROR));
     }
 }
Esempio n. 25
0
 public void PolarPointInvalid()
 {
     try
     {
         var pp = new PolarPoint(100, 789);
         Aver.Fail("Object was created");
     }
     catch (AzosException ex)
     {
         Aver.IsTrue(ex.Message.Contains("angle"));
     }
 }
Esempio n. 26
0
 public void TryCreateMultipart_NullParts()
 {
     try
     {
         var part = new Multipart(null);
         Aver.Fail("Invalid parts!");
     }
     catch (Exception e)
     {
         Aver.IsTrue(e.Message.Contains(Azos.Web.StringConsts.MULTIPART_PARTS_COULDNT_BE_EMPTY_ERROR));
     }
 }
Esempio n. 27
0
        void IRunnableHook.Prologue(Runner runner, FID id)
        {
            System.GC.Collect();
            var ms = NFX.OS.Computer.GetMemoryStatus();

            var has = ms.TotalPhysicalBytes;

            if (has < MinRAM)
            {
                Aver.Fail("The machine has to have at least {0:n0} bytes of ram for this test, but it only has {1:n0} bytes".Args(MinRAM, has));
            }
        }
Esempio n. 28
0
 private void doesNotThrow(Action a)
 {
     try
     {
         a();
         Aver.Pass();
     }
     catch (Exception error)
     {
         Aver.Fail("Exception {0} was thrown: {1}".Args(error.GetType().ToString(), error.Message));
     }
 }
Esempio n. 29
0
        public void PutCheckerboardPattern2()
        {
            using (var pile = MakeMMFPile())
            {
                pile.Start();
                var ipile = pile as IPile;

                const ulong CNT = 100;

                var ppp = new Tuple <PilePointer, ChargeRow> [CNT];

                for (ulong i = 0; i < CNT; i++)
                {
                    var ch = ChargeRow.MakeFake(new GDID(0, i));
                    ppp[i] = new Tuple <PilePointer, ChargeRow>(ipile.Put(ch), ch);
                }

                Aver.AreEqual(CNT, (ulong)ipile.ObjectCount);

                for (ulong i = 0; i < CNT; i++)
                {
                    var ch = ipile.Get(ppp[i].Item1);
                    Aver.AreObjectsEqual(ch, ppp[i].Item2);
                }

                for (ulong i = 0; i < CNT; i += 2)
                {
                    ipile.Delete(ppp[i].Item1);
                }

                Aver.AreEqual(CNT / 2, (ulong)ipile.ObjectCount);

                for (ulong i = 0; i < CNT; i++)
                {
                    if (i % 2 == 0)
                    {
                        try
                        {
                            ipile.Get(ppp[i].Item1);
                            Aver.Fail("Object is deleted but its pointer doesn't throw exception!");
                        }
                        catch (PileAccessViolationException) {}
                    }
                    else
                    {
                        var ch = ipile.Get(ppp[i].Item1);
                        Aver.AreObjectsEqual(ch, ppp[i].Item2);
                    }
                }
            }
        }
Esempio n. 30
0
        public void VariableExpiration(int EXPIRE_IN_SEC)
        {
            var expireUTC = App.TimeSource.UTCNow.AddSeconds(EXPIRE_IN_SEC);//EXPIRE_IN_SEC seconds from now it will end

            var insert = new LockTransaction("Expiration", "NamespaceName_" + EXPIRE_IN_SEC, 0, 0.0d,
                                             LockOp.Assert(LockOp.SetVar("T1", "a", 100, expirationTimeUTC: expireUTC)), //This will expire soon
                                             LockOp.Assert(LockOp.SetVar("T1", "b", 200))                                //but this will only expire with session
                                             );

            var exists = new LockTransaction("Expiration", "NamespaceName_" + EXPIRE_IN_SEC, 0, 0.0d,
                                             LockOp.SelectOperatorValue("existsA", LockOp.Exists("T1", "a")),
                                             LockOp.SelectOperatorValue("existsB", LockOp.Exists("T1", "b"))
                                             );


            var user1 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 1", 100000);

            var user2 = new Agni.Locking.Server.LockSessionData(new LockSessionID(null), "User 2", 100000);


            var result = m_Server.ExecuteLockTransaction(user1, insert);

            Aver.IsTrue(LockStatus.TransactionOK == result.Status);

            result = m_Server.ExecuteLockTransaction(user2, exists);
            Aver.IsTrue(LockStatus.TransactionOK == result.Status);

            //User 2 sees it
            Aver.IsTrue(result["existsA"].AsBool());
            Aver.IsTrue(result["existsB"].AsBool());

            for (var i = 0; i < EXPIRE_IN_SEC + 10; i++)
            {
                Thread.Sleep(1000);//Lets wait
                result = m_Server.ExecuteLockTransaction(user2, exists);
                Aver.IsTrue(LockStatus.TransactionOK == result.Status);

                Aver.IsTrue(result["existsB"].AsBool());
                if (!(bool)result["existsA"])
                {
                    if (i < EXPIRE_IN_SEC - 2)
                    {
                        Aver.Fail("Expired too early");
                    }
                    return;
                }
                Console.WriteLine("{0} sec. ... has not expired yet...".Args(i));
            }

            Aver.Fail("Did not expire even after significant delay");
        }