Esempio n. 1
0
        public Ad GetById(AdId adId)
        {
            IEnumerable <Ad> adToReturn = cacheRepository.Get("Ad" + adId.Id);

            if (adToReturn != null)
            {
                return(adToReturn.SingleOrDefault());
            }

            //TO-DO - Return fixed data. Get original repo
            adToReturn = new List <Ad>();
            adToReturn = adToReturn.ToList();
            ((List <Ad>)adToReturn).Add(new Ad(adId, new Domain.Core.Model.Money(32, new Domain.Core.Model.Currency(Domain.Core.Model.Currency.IsoCode.EUR)), new Domain.Core.Model.Coords(33, 33), new Domain.Core.Model.PostalCode("08150"), "Title 1"));
            cacheRepository.Set("Ad" + adId.Id, adToReturn);
            return(adToReturn.SingleOrDefault());

            //*

            using (IDbConnection dbConnection = connection.Create())
            {
                QueryObject byId = new AdSelect().ById(adId.Id);
                adToReturn = dbConnection.Query <Ad>(byId);

                cacheRepository.Set("Ad" + adId.Id, adToReturn);
                return(adToReturn.SingleOrDefault());
            }
        }
Esempio n. 2
0
        private string GetAdIds(Hashtable AdIDList)
        {
            string AdIds = "";

            foreach (Int64 AdId in AdIDList.Keys)
            {
                AdIds += AdId.ToString() + ",";
            }
            return(AdIds.Substring(0, AdIds.Length - 1));
        }
Esempio n. 3
0
        //public AdDto ChangePostalCode(string adId, string code)
        //{
        //    Ad ad = this.adReadRepository.GetById(new AdId(adId));
        //    ad.PostalCode = this.postalCodeAdapter.GetByCode(code);

        //    //TO-Do Save in repository & Configure Mapper interface & provider
        //    return new AdDto()
        //    {
        //        Id = ad.Id.Id,
        //        Title = ad.Title,
        //        Amount = ad.Price.Amount,
        //        IsoCode = ad.Price.Currency.Iso.ToString(),
        //        PostalCode = ad.PostalCode.Code,
        //        PostalCodeName = ad.PostalCode.Name
        //    };

        //}

        public async Task <bool> ChangePriceAndSaveAd(AdId adId, int amount, string isoCode)
        {
            Ad adToChangePriceAndSave = this.adQueryRepository.GetById(adId);

            Domain.Core.Model.Currency.IsoCode isoCodeEnum = (Domain.Core.Model.Currency.IsoCode)Enum.Parse(typeof(Domain.Core.Model.Currency.IsoCode), isoCode, true);

            adToChangePriceAndSave.ChangePrice(amount, isoCodeEnum);

            if (await this.adCommandRepository.Update(adToChangePriceAndSave))
            {
                adToChangePriceAndSave.DispatchEvents();
            }

            return(true);
        }
Esempio n. 4
0
        public async Task AsyncRecoveryTest1(CheckpointType checkpointType)
        {
            TestUtils.DeleteDirectory(TestUtils.MethodTestDir, wait: true);
            log = Devices.CreateLogDevice(TestUtils.MethodTestDir + "/AsyncRecoveryTest1.log", deleteOnClose: true);

            string testPath = TestUtils.MethodTestDir + "/checkpoints4";

            Directory.CreateDirectory(testPath);

            fht1 = new FasterKV <AdId, NumClicks>
                       (128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, PageSizeBits = 10, MemorySizeBits = 13
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = testPath
            }
                       );

            fht2 = new FasterKV <AdId, NumClicks>
                       (128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, PageSizeBits = 10, MemorySizeBits = 13
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = testPath
            }
                       );

            int numOps     = 5000;
            var inputArray = new AdId[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId = i;
            }

            NumClicks value;
            AdInput   inputArg = default;
            Output    output   = default;

            var s0 = fht1.For(functions).NewSession <AdSimpleFunctions>();
            var s1 = fht1.For(functions).NewSession <AdSimpleFunctions>();
            var s2 = fht1.For(functions).NewSession <AdSimpleFunctions>();

            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                s1.Upsert(ref inputArray[key], ref value, Empty.Default, key);
            }

            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                s2.Read(ref inputArray[key], ref inputArg, ref output, Empty.Default, key);
            }

            // does not require session
            fht1.TryInitiateFullCheckpoint(out _, checkpointType);
            await fht1.CompleteCheckpointAsync();

            s2.CompletePending(true, false);

            fht1.TryInitiateFullCheckpoint(out Guid token, checkpointType);
            await fht1.CompleteCheckpointAsync();

            s2.Dispose();
            s1.Dispose();
            s0.Dispose();
            fht1.Dispose();

            fht2.Recover(token); // sync, does not require session

            using (var s3 = fht2.For(functions).ResumeSession <AdSimpleFunctions>(s1.ID, out CommitPoint lsn))
            {
                Assert.AreEqual(numOps - 1, lsn.UntilSerialNo);

                for (int key = 0; key < numOps; key++)
                {
                    var status = s3.Read(ref inputArray[key], ref inputArg, ref output, Empty.Default, s3.SerialNo);

                    if (status.IsPending)
                    {
                        s3.CompletePending(true, true);
                    }
                    else
                    {
                        Assert.AreEqual(key, output.value.numClicks);
                    }
                }
            }

            fht2.Dispose();
            log.Dispose();
            TestUtils.DeleteDirectory(TestUtils.MethodTestDir);
        }
Esempio n. 5
0
        public async Task AsyncRecoveryTest1(CheckpointType checkpointType)
        {
            log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "\\SimpleRecoveryTest2.log", deleteOnClose: true);

            Directory.CreateDirectory(TestContext.CurrentContext.TestDirectory + "\\checkpoints4");

            fht1 = new FasterKV
                   <AdId, NumClicks, AdInput, Output, Empty, SimpleFunctions>
                       (128, new SimpleFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, PageSizeBits = 10, MemorySizeBits = 13
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints4", CheckPointType = checkpointType
            }
                       );

            fht2 = new FasterKV
                   <AdId, NumClicks, AdInput, Output, Empty, SimpleFunctions>
                       (128, new SimpleFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, PageSizeBits = 10, MemorySizeBits = 13
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints4", CheckPointType = checkpointType
            }
                       );

            int numOps     = 5000;
            var inputArray = new AdId[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId = i;
            }

            NumClicks value;
            AdInput   inputArg = default;
            Output    output   = default;

            var s0 = fht1.NewSession();
            var s1 = fht1.NewSession();
            var s2 = fht1.NewSession();

            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                s1.Upsert(ref inputArray[key], ref value, Empty.Default, key);
            }

            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                s2.Read(ref inputArray[key], ref inputArg, ref output, Empty.Default, key);
            }

            // does not require session
            fht1.TakeFullCheckpoint(out _);
            await fht1.CompleteCheckpointAsync();

            s2.CompletePending(true);

            fht1.TakeFullCheckpoint(out Guid token);
            await fht1.CompleteCheckpointAsync();

            s2.Dispose();
            s1.Dispose();
            s0.Dispose();
            fht1.Dispose();

            fht2.Recover(token); // sync, does not require session

            var guid = s1.ID;

            using (var s3 = fht2.ResumeSession(guid, out CommitPoint lsn))
            {
                Assert.IsTrue(lsn.UntilSerialNo == numOps - 1);

                for (int key = 0; key < numOps; key++)
                {
                    var status = s3.Read(ref inputArray[key], ref inputArg, ref output, Empty.Default, 0);

                    if (status == Status.PENDING)
                    {
                        s3.CompletePending(true);
                    }
                    else
                    {
                        Assert.IsTrue(output.value.numClicks == key);
                    }
                }
            }

            fht2.Dispose();
            log.Close();
            new DirectoryInfo(TestContext.CurrentContext.TestDirectory + "\\checkpoints4").Delete(true);
        }
Esempio n. 6
0
        private async ValueTask SimpleRecoveryTest1_Worker(CheckpointType checkpointType, ICheckpointManager checkpointManager, bool isAsync)
        {
            string checkpointDir = TestContext.CurrentContext.TestDirectory + $"/{TEST_CONTAINER}";

            if (checkpointManager != null)
            {
                checkpointDir = null;
            }

            log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/SimpleRecoveryTest1.log", deleteOnClose: true);

            fht1 = new FasterKV
                   <AdId, NumClicks>
                       (128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = checkpointDir, CheckpointManager = checkpointManager, CheckPointType = checkpointType
            }
                       );

            fht2 = new FasterKV
                   <AdId, NumClicks>
                       (128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = checkpointDir, CheckpointManager = checkpointManager, CheckPointType = checkpointType
            }
                       );


            int numOps     = 5000;
            var inputArray = new AdId[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId = i;
            }

            NumClicks value;
            AdInput   inputArg = default;
            Output    output   = default;

            var session1 = fht1.NewSession(new AdSimpleFunctions());

            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                session1.Upsert(ref inputArray[key], ref value, Empty.Default, 0);
            }
            fht1.TakeFullCheckpoint(out Guid token);
            fht1.CompleteCheckpointAsync().GetAwaiter().GetResult();
            session1.Dispose();

            if (isAsync)
            {
                await fht2.RecoverAsync(token);
            }
            else
            {
                fht2.Recover(token);
            }

            var session2 = fht2.NewSession(new AdSimpleFunctions());

            for (int key = 0; key < numOps; key++)
            {
                var status = session2.Read(ref inputArray[key], ref inputArg, ref output, Empty.Default, 0);

                if (status == Status.PENDING)
                {
                    session2.CompletePending(true);
                }
                else
                {
                    Assert.IsTrue(output.value.numClicks == key);
                }
            }
            session2.Dispose();

            log.Dispose();
            fht1.Dispose();
            fht2.Dispose();

            if (checkpointManager == null)
            {
                new DirectoryInfo(checkpointDir).Delete(true);
            }
        }
Esempio n. 7
0
        public async ValueTask ShouldRecoverBeginAddress([Values] bool isAsync)
        {
            log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/SimpleRecoveryTest2.log", deleteOnClose: true);

            Directory.CreateDirectory(TestContext.CurrentContext.TestDirectory + "/checkpoints6");

            fht1 = new FasterKV
                   <AdId, NumClicks>
                       (128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "/checkpoints6", CheckPointType = CheckpointType.FoldOver
            }
                       );

            fht2 = new FasterKV
                   <AdId, NumClicks>
                       (128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "/checkpoints6", CheckPointType = CheckpointType.FoldOver
            }
                       );


            int numOps     = 5000;
            var inputArray = new AdId[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId = i;
            }

            NumClicks value;

            var session1 = fht1.NewSession(new AdSimpleFunctions());
            var address  = 0L;

            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                session1.Upsert(ref inputArray[key], ref value, Empty.Default, 0);

                if (key == 2999)
                {
                    address = fht1.Log.TailAddress;
                }
            }

            fht1.Log.ShiftBeginAddress(address);

            fht1.TakeFullCheckpoint(out Guid token);
            fht1.CompleteCheckpointAsync().GetAwaiter().GetResult();
            session1.Dispose();

            if (isAsync)
            {
                await fht2.RecoverAsync(token);
            }
            else
            {
                fht2.Recover(token);
            }

            Assert.AreEqual(address, fht2.Log.BeginAddress);

            log.Dispose();
            fht1.Dispose();
            fht2.Dispose();
            new DirectoryInfo(TestContext.CurrentContext.TestDirectory + "/checkpoints6").Delete(true);
        }
Esempio n. 8
0
        public async ValueTask SimpleRecoveryTest2([Values] CheckpointType checkpointType, [Values] bool isAsync)
        {
            var checkpointManager = new DeviceLogCommitCheckpointManager(new LocalStorageNamedDeviceFactory(), new DefaultCheckpointNamingScheme(TestContext.CurrentContext.TestDirectory + "/checkpoints4"), false);

            log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "/SimpleRecoveryTest2.log", deleteOnClose: true);

            // Directory.CreateDirectory(TestContext.CurrentContext.TestDirectory + "/checkpoints4");

            fht1 = new FasterKV
                   <AdId, NumClicks>
                       (128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointManager = checkpointManager, CheckPointType = checkpointType
            }
                       );

            fht2 = new FasterKV
                   <AdId, NumClicks>
                       (128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointManager = checkpointManager, CheckPointType = checkpointType
            }
                       );


            int numOps     = 5000;
            var inputArray = new AdId[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId = i;
            }

            NumClicks value;
            AdInput   inputArg = default;
            Output    output   = default;

            var session1 = fht1.NewSession(new AdSimpleFunctions());

            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                session1.Upsert(ref inputArray[key], ref value, Empty.Default, 0);
            }
            fht1.TakeFullCheckpoint(out Guid token);
            fht1.CompleteCheckpointAsync().GetAwaiter().GetResult();
            session1.Dispose();

            if (isAsync)
            {
                await fht2.RecoverAsync(token);
            }
            else
            {
                fht2.Recover(token);
            }

            var session2 = fht2.NewSession(new AdSimpleFunctions());

            for (int key = 0; key < numOps; key++)
            {
                var status = session2.Read(ref inputArray[key], ref inputArg, ref output, Empty.Default, 0);

                if (status == Status.PENDING)
                {
                    session2.CompletePending(true);
                }
                else
                {
                    Assert.IsTrue(output.value.numClicks == key);
                }
            }
            session2.Dispose();

            log.Dispose();
            fht1.Dispose();
            fht2.Dispose();
            checkpointManager.Dispose();

            new DirectoryInfo(TestContext.CurrentContext.TestDirectory + "/checkpoints4").Delete(true);
        }
Esempio n. 9
0
        public void SimpleRecoveryTest2()
        {
            log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "\\SimpleRecoveryTest2.log", deleteOnClose: true);

            Directory.CreateDirectory(TestContext.CurrentContext.TestDirectory + "\\checkpoints5");

            fht1 = new FasterKV
                   <AdId, NumClicks, Input, Output, Empty, SimpleFunctions>
                       (128, new SimpleFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints5", CheckPointType = CheckpointType.FoldOver
            }
                       );

            fht2 = new FasterKV
                   <AdId, NumClicks, Input, Output, Empty, SimpleFunctions>
                       (128, new SimpleFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints5", CheckPointType = CheckpointType.FoldOver
            }
                       );


            int numOps     = 5000;
            var inputArray = new AdId[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId = i;
            }

            NumClicks value;
            Input     inputArg = default(Input);
            Output    output   = default(Output);

            fht1.StartSession();
            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                fht1.Upsert(ref inputArray[key], ref value, Empty.Default, 0);
            }
            fht1.TakeFullCheckpoint(out Guid token);
            fht1.CompleteCheckpoint(true);
            fht1.StopSession();

            fht2.Recover(token);
            fht2.StartSession();
            for (int key = 0; key < numOps; key++)
            {
                var status = fht2.Read(ref inputArray[key], ref inputArg, ref output, Empty.Default, 0);

                if (status == Status.PENDING)
                {
                    fht2.CompletePending(true);
                }
                else
                {
                    Assert.IsTrue(output.value.numClicks == key);
                }
            }
            fht2.StopSession();

            log.Close();
            fht1.Dispose();
            fht2.Dispose();
            new DirectoryInfo(TestContext.CurrentContext.TestDirectory + "\\checkpoints5").Delete(true);
        }
Esempio n. 10
0
        public void ShouldRecoverBeginAddress()
        {
            log = Devices.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "\\SimpleRecoveryTest2.log", deleteOnClose: true);

            Directory.CreateDirectory(TestContext.CurrentContext.TestDirectory + "\\checkpoints5");

            fht1 = new FasterKV
                   <AdId, NumClicks, Input, Output, Empty, SimpleFunctions>
                       (128, new SimpleFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints6", CheckPointType = CheckpointType.FoldOver
            }
                       );

            fht2 = new FasterKV
                   <AdId, NumClicks, Input, Output, Empty, SimpleFunctions>
                       (128, new SimpleFunctions(),
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints6", CheckPointType = CheckpointType.FoldOver
            }
                       );


            int numOps     = 5000;
            var inputArray = new AdId[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId = i;
            }

            NumClicks value;

            fht1.StartSession();
            var address = 0L;

            for (int key = 0; key < numOps; key++)
            {
                value.numClicks = key;
                fht1.Upsert(ref inputArray[key], ref value, Empty.Default, 0);

                if (key == 2999)
                {
                    address = fht1.Log.TailAddress;
                }
            }

            fht1.Log.ShiftBeginAddress(address);

            fht1.TakeFullCheckpoint(out Guid token);
            fht1.CompleteCheckpoint(true);
            fht1.StopSession();

            fht2.Recover(token);

            Assert.AreEqual(address, fht2.Log.BeginAddress);

            log.Close();
            fht1.Dispose();
            fht2.Dispose();
            new DirectoryInfo(TestContext.CurrentContext.TestDirectory + "\\checkpoints6").Delete(true);
        }
Esempio n. 11
0
        public unsafe void SimpleRecoveryTest1()
        {
            log = FasterFactory.CreateLogDevice(TestContext.CurrentContext.TestDirectory + "\\hlog", deleteOnClose: true);

            Directory.CreateDirectory(TestContext.CurrentContext.TestDirectory + "\\checkpoints");

            fht1 = FasterFactory.Create
                   <AdId, NumClicks, Input, Output, Empty, SimpleFunctions, ICustomFaster>
                       (indexSizeBuckets: 128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints", CheckPointType = CheckpointType.Snapshot
            }
                       );

            fht2 = FasterFactory.Create
                   <AdId, NumClicks, Input, Output, Empty, SimpleFunctions, ICustomFaster>
                       (indexSizeBuckets: 128,
                       logSettings: new LogSettings {
                LogDevice = log, MutableFraction = 0.1, MemorySizeBits = 29
            },
                       checkpointSettings: new CheckpointSettings {
                CheckpointDir = TestContext.CurrentContext.TestDirectory + "\\checkpoints", CheckPointType = CheckpointType.Snapshot
            }
                       );


            int numOps     = 5000;
            var inputArray = new AdId[numOps];

            for (int i = 0; i < numOps; i++)
            {
                inputArray[i].adId = i;
            }

            NumClicks value;
            Input     inputArg;
            Output    output;


            fixed(AdId *input = inputArray)
            {
                fht1.StartSession();
                for (int key = 0; key < numOps; key++)
                {
                    value.numClicks = key;
                    fht1.Upsert(input + key, &value, null, 0);
                }
                fht1.TakeFullCheckpoint(out Guid token);
                fht1.CompleteCheckpoint(true);
                fht1.StopSession();

                fht2.Recover(token);
                fht2.StartSession();
                for (int key = 0; key < numOps; key++)
                {
                    var status = fht2.Read(input + key, &inputArg, &output, null, 0);

                    if (status == Status.PENDING)
                    {
                        fht2.CompletePending(true);
                    }
                    else
                    {
                        Assert.IsTrue(output.value.numClicks == key);
                    }
                }
                fht2.StopSession();
            }

            log.Close();
            fht1.Dispose();
            fht2.Dispose();
            new DirectoryInfo(TestContext.CurrentContext.TestDirectory + "\\checkpoints").Delete(true);
        }