예제 #1
0
        public RelationalDatabaseDataSet FindTablesBy(CatalogName[] catalogNameCollection)
        {
            Guard.Against.NullOrEmptyCollection(catalogNameCollection, nameof(catalogNameCollection));

            RelationalDatabaseDataSet ds = new RelationalDatabaseDataSet();

            ds.EnforceConstraints = false;

            Dsl.ConnectToMsSqlServer()
            .UsingThisConnectionString(_connection.ConnectionString)
            .ForEachCatalog(CatalogName.ToArray(catalogNameCollection))
            .SelectAllColumns()
            .From(TableStatements.From)
            .Adapt()
            .UsingThisMapping(BuildTableMapping(ds))
            .FillDataset(ds)
            ;

            /*using (SqlDataAdapter adapter = new SqlDataAdapter(TableStatments.SELECT_ALL_TABLES, Connection))
             * {
             *  adapter.TableMappings.Add(CreateTableMapping(RdmsDataSet.SchemaStructure.Table.TableName));
             *
             *  foreach (string catalog in catalogs)
             *  {
             *      Connection.ChangeDatabase(catalog);
             *
             *      adapter.Fill(ds);
             *  }
             * }*/

            return(ds);
        }
예제 #2
0
 /// <summary>
 /// Initializes a new instance of the CommandGet class.
 /// </summary>
 /// <param name="name">name property</param>
 /// <param name="fromSourceSystem">fromSourceSystem property</param>
 /// <param name="id">Id property</param>
 /// <param name="etag">ETag property</param>
 /// <param name="timestamp">Timestamp property</param>
 /// <param name="effectiveRights">EffectiveRights property</param>
 /// <param name="containerId">containerId property</param>
 /// <param name="descriptions">Description property, used to describe
 /// assets</param>
 /// <param name="experts">The data steward of the asset</param>
 /// <param name="tags">Taging the asset</param>
 /// <param name="termTags">Taging the asset using glossary terms, this
 /// is a feature only for standard SKU</param>
 /// <param name="columnDescriptions">Descriptions of a column</param>
 /// <param name="columnTags">Tagging a column</param>
 /// <param name="columnTermTags">Tagging a column with glossary terms,
 /// this is a feature only for standard SKU </param>
 /// <param name="parameterDescriptions">Parameter descriptions</param>
 /// <param name="parameterTags">Tagging a parameter</param>
 /// <param name="parameterTermTags">Tagging a parameter with glossary
 /// terms, this is a feature only for standard SKU</param>
 public CommandGet(string name, Dsl dsl, DataSource dataSource, LastRegisteredBy lastRegisteredBy, bool fromSourceSystem, string id = default(string), string etag = default(string), string timestamp = default(string), System.Collections.Generic.IList <RightsItems?> effectiveRights = default(System.Collections.Generic.IList <RightsItems?>), System.Collections.Generic.IList <RolesItem> roles = default(System.Collections.Generic.IList <RolesItem>), double?containerId = default(double?), System.Collections.Generic.IList <Description> descriptions = default(System.Collections.Generic.IList <Description>), System.Collections.Generic.IList <Expert> experts = default(System.Collections.Generic.IList <Expert>), AccessInstruction accessInstructions = default(AccessInstruction), Documentation documentation = default(Documentation), FriendlyName friendlyName = default(FriendlyName), System.Collections.Generic.IList <Tag> tags = default(System.Collections.Generic.IList <Tag>), System.Collections.Generic.IList <TermTag> termTags = default(System.Collections.Generic.IList <TermTag>), CommandSchema schema = default(CommandSchema), System.Collections.Generic.IList <ColumnDescription> columnDescriptions = default(System.Collections.Generic.IList <ColumnDescription>), System.Collections.Generic.IList <ColumnTag> columnTags = default(System.Collections.Generic.IList <ColumnTag>), System.Collections.Generic.IList <ColumnTermTag> columnTermTags = default(System.Collections.Generic.IList <ColumnTermTag>), System.Collections.Generic.IList <ParameterDescription> parameterDescriptions = default(System.Collections.Generic.IList <ParameterDescription>), System.Collections.Generic.IList <ParameterTag> parameterTags = default(System.Collections.Generic.IList <ParameterTag>), System.Collections.Generic.IList <ParameterTermTag> parameterTermTags = default(System.Collections.Generic.IList <ParameterTermTag>))
     : base(id, etag, timestamp, effectiveRights)
 {
     Roles                 = roles;
     Name                  = name;
     Dsl                   = dsl;
     DataSource            = dataSource;
     LastRegisteredBy      = lastRegisteredBy;
     FromSourceSystem      = fromSourceSystem;
     ContainerId           = containerId;
     Descriptions          = descriptions;
     Experts               = experts;
     AccessInstructions    = accessInstructions;
     Documentation         = documentation;
     FriendlyName          = friendlyName;
     Tags                  = tags;
     TermTags              = termTags;
     Schema                = schema;
     ColumnDescriptions    = columnDescriptions;
     ColumnTags            = columnTags;
     ColumnTermTags        = columnTermTags;
     ParameterDescriptions = parameterDescriptions;
     ParameterTags         = parameterTags;
     ParameterTermTags     = parameterTermTags;
 }
예제 #3
0
        public void Cluster_CRDT_should_replicate_values_to_new_node()
        {
            Join(_second, _first);

            RunOn(() =>
                  Within(TimeSpan.FromSeconds(10), () =>
                         AwaitAssert(() =>
            {
                _replicator.Tell(Dsl.GetReplicaCount);
                ExpectMsg(new ReplicaCount(2));
            })),
                  _first, _second);

            EnterBarrier("2-nodes");

            RunOn(() =>
            {
                var changedProbe = CreateTestProbe();
                _replicator.Tell(Dsl.Subscribe(KeyA, changedProbe.Ref));
                // "A" should be replicated via gossip to the new node
                Within(TimeSpan.FromSeconds(5), () =>
                       AwaitAssert(() =>
                {
                    // for some reason result is returned before CRDT gets replicated
                    _replicator.Tell(Dsl.Get(KeyA, ReadLocal.Instance));
                    var c = ExpectMsg <GetSuccess>(g => Equals(g.Key, KeyA)).Get(KeyA);
                    c.Value.ShouldBe(6UL);
                }));
                var c2 = changedProbe.ExpectMsg <Changed>(g => Equals(g.Key, KeyA)).Get(KeyA);
                c2.Value.ShouldBe(6UL);
            }, _second);

            EnterBarrierAfterTestStep();
        }
예제 #4
0
 protected override void Load(Dsl.CallData callData)
 {
     int num = callData.GetParamNum();
     if (num > 0) {
         m_Time.InitFromDsl(callData.GetParam(0));
     }
 }
예제 #5
0
        public void Insert_from_5_nodes_should_read_write_to_majority_when_all_nodes_connected()
        {
            var key           = new ORSetKey <int>("B");
            var readMajority  = new ReadMajority(_timeout);
            var writeMajority = new WriteMajority(_timeout);

            RunOn(() =>
            {
                var writeProbe = CreateTestProbe();
                var writeAcks  = MyData.Select(i =>
                {
                    SleepDelay();
                    _replicator.Tell(Dsl.Update(key, ORSet <int> .Empty, writeMajority, i, x => x.Add(_cluster.SelfUniqueAddress, i)), writeProbe.Ref);
                    return(writeProbe.ReceiveOne(_timeout.Add(TimeSpan.FromSeconds(1))));
                }).ToArray();
                var successWriteAcks = writeAcks.OfType <Replicator.UpdateSuccess>().ToArray();
                var failureWriteAcks = writeAcks.OfType <Replicator.IUpdateFailure>().ToArray();
                successWriteAcks.Select(x => (int)x.Request).ShouldBe(MyData.ToArray());
                successWriteAcks.Length.ShouldBe(MyData.Count());
                failureWriteAcks.ShouldBe(new Replicator.IUpdateFailure[0]);
                (successWriteAcks.Length + failureWriteAcks.Length).ShouldBe(MyData.Count());

                EnterBarrier("data-written-2");

                // read from majority of nodes, which is enough to retrieve all data
                var readProbe = CreateTestProbe();
                _replicator.Tell(Dsl.Get(key, readMajority), readProbe.Ref);
                var result = readProbe.ExpectMsg <Replicator.GetSuccess>(g => Equals(g.Key, key)).Get(key);
                result.Elements.ShouldBe(_expectedData);
            }, _nodes.ToArray());

            RunOn(() => EnterBarrier("data-written-2"), Controller);

            EnterBarrier("after-test-2");
        }
예제 #6
0
 private void GetState()
 {
     for (int i = 0; i < NrOfKeys; i++)
     {
         Replicator.Tell(Dsl.Get(_stateKeys[i], _readConsistency, i));
     }
 }
예제 #7
0
        public void Insert_from_5_nodes_should_replicate_values_when_all_nodes_connected()
        {
            var key = new ORSetKey <int>("A");

            RunOn(() =>
            {
                var writeProbe = CreateTestProbe();
                var writeAcks  = MyData.Select(i =>
                {
                    SleepDelay();
                    _replicator.Tell(Dsl.Update(key, ORSet <int> .Empty, WriteLocal.Instance, i, x => x.Add(_cluster.SelfUniqueAddress, i)), writeProbe.Ref);
                    return(writeProbe.ReceiveOne(TimeSpan.FromSeconds(3)));
                }).ToArray();
                var successWriteAcks = writeAcks.OfType <Replicator.UpdateSuccess>().ToArray();
                var failureWriteAcks = writeAcks.OfType <Replicator.IUpdateFailure>().ToArray();
                successWriteAcks.Select(x => (int)x.Request).ShouldBe(MyData.ToArray());
                successWriteAcks.Length.ShouldBe(MyData.Count());
                failureWriteAcks.ShouldBe(new Replicator.IUpdateFailure[0]);
                (successWriteAcks.Length + failureWriteAcks.Length).ShouldBe(MyData.Count());

                // eventually all nodes will have the data
                Within(TimeSpan.FromSeconds(15), () =>
                {
                    AwaitAssert(() =>
                    {
                        var readProbe = CreateTestProbe();
                        _replicator.Tell(Dsl.Get(key, ReadLocal.Instance), readProbe.Ref);
                        var result = readProbe.ExpectMsg <Replicator.GetSuccess>(g => Equals(g.Key, key)).Get(key);
                        result.Elements.ShouldBe(_expectedData);
                    });
                });
            }, _nodes.ToArray());

            EnterBarrier("after-test-1");
        }
예제 #8
0
        private void UpdateORDictionaryNode2And1()
        {
            var changedProbe = CreateTestProbe(_sys2);

            // subscribe to updates for KeyH, then update it with a replication factor of two
            _replicator2.Tell(Dsl.Subscribe(_keyH, changedProbe.Ref));
            _replicator2.Tell(Dsl.Update(_keyH, ORDictionary <string, Flag> .Empty, _writeTwo, x => x.SetItem(Cluster.Cluster.Get(_sys2), "a", Flag.False)));

            // receive local update
            changedProbe.ExpectMsg <Changed>(g => Equals(g.Key, _keyH)).Get(_keyH).Entries.SequenceEqual(ImmutableDictionary.CreateRange(new[]
            {
                new KeyValuePair <string, Flag>("a", Flag.False),
            })).ShouldBeTrue();

            // push update from node 1
            _replicator1.Tell(Dsl.Update(_keyH, ORDictionary <string, Flag> .Empty, _writeTwo, x => x.SetItem(Cluster.Cluster.Get(_sys1), "a", Flag.True)));

            // expect replication of update on node 2
            changedProbe.ExpectMsg <Changed>(g => Equals(g.Key, _keyH)).Get(_keyH).Entries.SequenceEqual(ImmutableDictionary.CreateRange(new[]
            {
                new KeyValuePair <string, Flag>("a", Flag.True)
            })).ShouldBeTrue();

            // add new value to dictionary from node 2
            _replicator2.Tell(Dsl.Update(_keyH, ORDictionary <string, Flag> .Empty, _writeTwo, x => x.SetItem(Cluster.Cluster.Get(_sys2), "b", Flag.True)));
            changedProbe.ExpectMsg <Changed>(g => Equals(g.Key, _keyH)).Get(_keyH).Entries.SequenceEqual(ImmutableDictionary.CreateRange(new[]
            {
                new KeyValuePair <string, Flag>("a", Flag.True),
                new KeyValuePair <string, Flag>("b", Flag.True)
            })).ShouldBeTrue();
        }
예제 #9
0
        private void HandleMessage(CreateEventMarket message)
        {
            try
            {
                var cluster    = Cluster.Get(Context.System);
                var replicator = DistributedData.Get(Context.System).Replicator;

                var key = new ORSetKey <string>($"Event-{message.EventId}");

                var writeConsistency = new WriteMajority(TimeSpan.FromSeconds(2));

                replicator.Tell(Dsl.Update(key, ORSet <string> .Empty, writeConsistency,
                                           existing => existing.Add(cluster, message.Market)));

                var localEvent =
                    replicator.Ask <IGetResponse>(Dsl.Get(key, ReadLocal.Instance));


                Sender.Tell(localEvent.Result);
            }
            catch (Exception e)
            {
                _log.Error(e, "Unable to process message CreateEventMarket for Event {0} Market {1}", message.EventId,
                           message.Market);
                Sender.Tell(
                    $"Unable to process message CreateEventMarket for Event {message.EventId} Market {message.Market}");
            }
        }
예제 #10
0
        public void Updates_from_same_node_should_be_possible_to_do_from_two_actors()
        {
            var updater1 = ActorOf(Props.Create <Updater>(), "updater1");
            var updater2 = ActorOf(Props.Create <Updater>(), "updater2");

            var b = ImmutableHashSet <string> .Empty.ToBuilder();

            for (int i = 1; i <= 100; i++)
            {
                var m1 = "a" + 1;
                var m2 = "b" + 1;
                updater1.Tell(m1);
                updater2.Tell(m2);

                b.Add(m1);
                b.Add(m2);
            }

            var expected = b.ToImmutable();

            AwaitAssert(() =>
            {
                _replicator.Tell(Dsl.Get(Updater.Key, ReadLocal.Instance));
                var msg      = ExpectMsg <GetSuccess>();
                var elements = msg.Get(Updater.Key).Elements;
                Assert.Equal(expected, elements);
            });
        }
예제 #11
0
        public void Cluster_CRDT_should_avoid_duplicate_change_events_for_same_data()
        {
            var changedProbe = CreateTestProbe();

            _replicator.Tell(Dsl.Subscribe(KeyI, changedProbe.Ref));

            EnterBarrier("subscribed-I");

            RunOn(() => _replicator.Tell(Dsl.Update(KeyI, GSet <string> .Empty, _writeTwo, a => a.Add("a"))),
                  _second);

            Within(TimeSpan.FromSeconds(5), () =>
            {
                var changed = changedProbe.ExpectMsg <Changed>(c =>
                                                               c.Get(KeyI).Elements.ShouldBe(ImmutableHashSet.Create("a")));
                var keyIData = changed.Get(KeyI);
                Sys.Log.Debug("DEBUG: Received Changed {0}", changed);
            });

            EnterBarrier("update-I");

            RunOn(() => _replicator.Tell(Dsl.Update(KeyI, GSet <string> .Empty, _writeTwo, a => a.Add("a"))),
                  _first);

            changedProbe.ExpectNoMsg(TimeSpan.FromSeconds(1));

            EnterBarrierAfterTestStep();
        }
예제 #12
0
        //The way our data works, I opted to just removed all the key data, but leave the key intact as sometimes i need to use the key again in rare instances, but once deleted, ddata doesn't allow this.
        private void HandleMessage(CloseEvent message)
        {
            try
            {
                var replicator       = DistributedData.Get(Context.System).Replicator;
                var cluster          = Cluster.Get(Context.System);
                var key              = new ORSetKey <string>($"Event-{message.EventId}");
                var writeConsistency = WriteLocal.Instance;
                replicator.Tell(Dsl.Update(key, ORSet <string> .Empty, writeConsistency, $"Event-{message.EventId}",
                                           existing =>
                {
                    return(existing.Clear(cluster));
                }));

                var finalResult =
                    replicator.Ask <IGetResponse>(Dsl.Get(key, ReadLocal.Instance));
                Sender.Tell(finalResult.Result);
            }
            catch (DataDeletedException e)
            {
                Sender.Tell($"Event {message.EventId} has been deleted");
            }
            catch (Exception e)
            {
                _log.Error(e, "Unable to process message CloseEvent for Event {0}", message.EventId);
                Sender.Tell($"Unable to process message CloseEvent for Event {message.EventId}");
            }
        }
예제 #13
0
        private void AssertValue(IKey <IReplicatedData> key, object expected)
        {
            Within(TimeSpan.FromSeconds(10), () => AwaitAssert(() =>
            {
                _replicator.Tell(Dsl.Get(key, ReadLocal.Instance));
                var g = ExpectMsg <GetSuccess>().Get(key);
                object value;
                switch (g)
                {
                case GCounter counter:
                    value = counter.Value;
                    break;

                case PNCounter pnCounter:
                    value = pnCounter.Value;
                    break;

                case GSet <string> set:
                    value = set.Elements;
                    break;

                case ORSet <string> orSet:
                    value = orSet.Elements;
                    break;

                default:
                    throw new ArgumentException("input doesn't match");
                }

                value.ShouldBe(expected);
            }));
        }
예제 #14
0
        private void AssertValue(IKey <IReplicatedData> key, object expected)
        {
            Within(TimeSpan.FromSeconds(10), () => AwaitAssert(() =>
            {
                _replicator.Tell(Dsl.Get(key, ReadLocal.Instance));
                var g = ExpectMsg <GetSuccess>().Get(key);
                object value;
                if (g is GCounter)
                {
                    value = ((GCounter)g).Value;
                }
                else if (g is PNCounter)
                {
                    value = ((PNCounter)g).Value;
                }
                else if (g is GSet <string> )
                {
                    value = ((GSet <string>)g).Elements;
                }
                else if (g is ORSet <string> )
                {
                    value = ((ORSet <string>)g).Elements;
                }
                else
                {
                    throw new ArgumentException("input doesn't match");
                }

                value.ShouldBe(expected);
            }));
        }
예제 #15
0
        private static async Task Main()
        {
            Console.WriteLine("Put the ddata mdb file in a folder called cluster-data in the application root folder. Press a key when done");
            Console.Read();

            var cfg = ConfigurationFactory.ParseString(File.ReadAllText("HOCON"))
                      .WithFallback(DistributedData.DefaultConfig());

            var originalColour = Console.ForegroundColor;

            var sys           = ActorSystem.Create("test", cfg);
            var dd            = DistributedData.Get(sys);
            int emptyKeyCount = 0;

            var resp = await dd.Replicator.Ask <GetKeysIdsResult>(Dsl.GetKeyIds);

            foreach (var resultKey in resp.Keys)
            {
                var key = new ORSetKey <string>($"{resultKey}");

                var keyResp = await dd.Replicator.Ask <IGetResponse>(Dsl.Get(key));

                Console.ForegroundColor = ConsoleColor.Green;
                if (keyResp.Get(key).Elements.Count == 0)
                {
                    emptyKeyCount++;
                }

                Console.WriteLine($"{key.Id}\t{string.Join<string>(",", keyResp.Get(key).Elements)}");
            }

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine($"Finished loading {resp.Keys.Count} keys. There were {emptyKeyCount} empty keys");
            Console.ForegroundColor = originalColour;
        }
예제 #16
0
        public void GenerateCode(Dsl.IConceptInfo conceptInfo, ICodeBuilder codeBuilder)
        {
            var info = (DataStructureInfo)conceptInfo;

            if (info.Module.Name == "Common" && info.Name == "Claim")
                codeBuilder.InsertCode(DeactivateInsteadOfDelete, ClaimRepositoryCodeGenerator.DeactivateInsteadOfDeleteTag, info);
        }
 public ISkillTriger CreateTriger(Dsl.ISyntaxComponent trigerConfig, SkillInstance instance)
 {
     ISkillTriger triger = null;
     string type = trigerConfig.GetId();
     ISkillTrigerFactory factory = GetFactory(type);
     if (null != factory) {
         try {
             triger = factory.Create();
             triger.Init(trigerConfig, instance);
         } catch (Exception ex) {
             GameFramework.LogSystem.Error("triger:{0} line:{1} failed.", trigerConfig.ToScriptString(), trigerConfig.GetLine());
             throw ex;
         }
     } else {
     #if !DEBUG
         GameFramework.LogSystem.Error("CreateTriger failed, type:{0}", type);
     #endif
     }
     if (null != triger) {
         GameFramework.LogSystem.Debug("CreateTriger, type:{0} triger:{1}", type, triger.GetType().Name);
     } else {
     #if !DEBUG
         GameFramework.LogSystem.Error("CreateTriger failed, type:{0}", type);
     #endif
     }
     return triger;
 }
예제 #18
0
        public void Cluster_CRDT_should_converge_after_many_concurrent_updates()
        {
            Within(TimeSpan.FromSeconds(10), () =>
            {
                RunOn(() =>
                {
                    var c = GCounter.Empty;
                    for (ulong i = 0; i < 100UL; i++)
                    {
                        c = c.Increment(_cluster, i);
                        _replicator.Tell(Dsl.Update(KeyF, GCounter.Empty, _writeTwo, x => x.Increment(_cluster, 1)));
                    }

                    var results = ReceiveN(100);
                    results.All(x => x is UpdateSuccess).ShouldBeTrue();
                }, _first, _second, _third);

                EnterBarrier("100-updates-done");

                RunOn(() =>
                {
                    _replicator.Tell(Dsl.Get(KeyF, _readTwo));
                    var c = ExpectMsg <GetSuccess>(g => Equals(g.Key, KeyF)).Get(KeyF);
                    c.Value.ShouldBe(3 * 100UL);
                }, _first, _second, _third);

                EnterBarrierAfterTestStep();
            });
        }
 public static void FirstParse(Dsl.DslInfo dslInfo)
 {
     string id = dslInfo.GetId();
     if (id == "command") {
         if (dslInfo.Functions.Count == 2) {
             StorySystem.CommonCommands.CompositeCommand cmd = new CommonCommands.CompositeCommand();
             cmd.InitSharedData();
             Dsl.FunctionData first = dslInfo.First;
             cmd.Name = first.Call.GetParamId(0);
             Dsl.FunctionData second = dslInfo.Second;
             for (int ix = 0; ix < second.Call.GetParamNum(); ++ix) {
                 cmd.ArgNames.Add(second.Call.GetParamId(ix));
             }
             //注册
             StoryCommandManager.Instance.RegisterCommandFactory(cmd.Name, new CommonCommands.CompositeCommandFactory(cmd), true);
         }
     } else if (id == "value") {
         if (dslInfo.Functions.Count == 3) {
             StorySystem.CommonValues.CompositeValue val = new CommonValues.CompositeValue();
             val.InitSharedData();
             Dsl.FunctionData first = dslInfo.First;
             val.Name = first.Call.GetParamId(0);
             Dsl.FunctionData second = dslInfo.Second;
             for (int ix = 0; ix < second.Call.GetParamNum(); ++ix) {
                 val.ArgNames.Add(second.Call.GetParamId(ix));
             }
             Dsl.FunctionData third = dslInfo.Functions[2];
             val.ReturnName = third.Call.GetParamId(0);
             //注册
             StoryValueManager.Instance.RegisterValueFactory(val.Name, new CommonValues.CompositeValueFactory(val), true);
         }
     }
 }
예제 #20
0
        private async Task ReplicatorDuplicatePublish()
        {
            var p1 = CreateTestProbe(_sys1);
            var p2 = CreateTestProbe(_sys2);
            var p3 = CreateTestProbe(_sys3);

            var probes = new[] { p1, p2, p3 };

            // subscribe to updates on all 3 nodes
            _replicator1.Tell(Dsl.Subscribe(_keyI, p1.Ref));
            _replicator2.Tell(Dsl.Subscribe(_keyI, p2.Ref));
            _replicator3.Tell(Dsl.Subscribe(_keyI, p3.Ref));

            // update item on 2
            _replicator2.Tell(Dsl.Update(_keyI, GSet <string> .Empty, _writeTwo, a => a.Add("a")));

            Sys.Log.Info("Pushed change from sys2 for I");

            // wait for write to replicate to all 3 nodes
            Within(TimeSpan.FromSeconds(5), () =>
            {
                foreach (var p in probes)
                {
                    p.ExpectMsg <Changed>(c => c.Get(_keyI).Elements.ShouldBe(ImmutableHashSet.Create("a")));
                }
            });

            // create duplicate write on node 1
            Sys.Log.Info("Pushing change from sys1 for I");
            _replicator1.Tell(Dsl.Update(_keyI, GSet <string> .Empty, _writeTwo, a => a.Add("a")));


            // no probe should receive an update
            p2.ExpectNoMsg(TimeSpan.FromSeconds(1));
        }
예제 #21
0
 private static RuleDef AbsoluteMaxAmount(int amountLimit)
 {
     return
         ((
              from amount in Dsl.GetAmount <Unit>()
              select new Amount(Math.Min(amount, amountLimit))
              ).Apply());
 }
예제 #22
0
            public void ProduceValidSqlQuery_With_AndIsEqualClause(string whereColumn, string whereValue, string andColumn, string andValue, string expected)
            {
                ICanCallAfterSqlBuilder builder = Dsl.PlainSql();

                string result = builder.SelectAllColumns().From(TableName).Where(whereColumn).IsEqualTo(whereValue).And(andColumn).IsEqualTo(andValue).ToSql();

                Assert.Equal($"{DefaulSelectFromWithWhere} {expected}", result);
            }
예제 #23
0
 private void LoadCondition(Dsl.CallData callData)
 {
     int num = callData.GetParamNum();
     if (num > 0 && callData.GetId() == "if") {
         m_HaveCondition = true;
         m_Condition.InitFromDsl(callData.GetParam(0));
     }
 }
 protected override void Load(Dsl.CallData callData)
 {
     int num = callData.GetParamNum();
     if (num > 1) {
         m_Key.InitFromDsl(callData.GetParam(0));
         m_Value.InitFromDsl(callData.GetParam(1));
     }
 }
 protected override void Load(Dsl.CallData callData)
 {
     int num = callData.GetParamNum();
     if (num > 1) {
         m_TargetSceneId.InitFromDsl(callData.GetParam(0));
         m_ObjId.InitFromDsl(callData.GetParam(1));
     }
 }
예제 #26
0
            public void ProduceValidSqlQuery_With_SelectAllColumnsFromATableWithoutAlias()
            {
                ICanCallAfterSqlBuilder builder = Dsl.PlainSql();

                string result = builder.SelectAllColumns().From(TableName).WithoutAlias().ToSql();

                Assert.Equal($"SELECT * {DefaultFromWithoutAlias}", result);
            }
 protected override void Load(Dsl.CallData callData)
 {
     int num = callData.GetParamNum();
     if (num > 1) {
         m_ObjPath.InitFromDsl(callData.GetParam(0));
         m_ComponentType.InitFromDsl(callData.GetParam(1));
     }
 }
 protected override void Load(Dsl.CallData callData, SkillInstance instance)
 {
     if (callData.GetParamNum() >= 3) {
         StartTime = long.Parse(callData.GetParamId(0));
         m_RemainTime = long.Parse(callData.GetParamId(1));
         m_RotateSpeed = DslUtility.CalcVector3(callData.GetParam(2) as Dsl.CallData);
     }
 }
예제 #29
0
            public void ProduceValidSqlQuery_WithWhereClause_AlphanumericEqual(string inputColumn, string inputValue, string expected)
            {
                ICanCallAfterSqlBuilder builder = Dsl.PlainSql();

                string result = builder.SelectAllColumns().From(TableName).Where(inputColumn).IsEqualTo(inputValue).ToSql();

                Assert.Equal($"{DefaulSelectFromWithWhere} {expected}", result);
            }
예제 #30
0
 protected override void Load(Dsl.CallData callData)
 {
     int num = callData.GetParamNum();
     for (int i = 0; i < num; ++i) {
         IStoryValue<string> val = new StoryValue<string>();
         val.InitFromDsl(callData.GetParam(i));
         m_MsgIds.Add(val);
     }
 }
예제 #31
0
        public static IEnumerable<string> GenerateFile(string file)
        {
            var name = Path.GetFileNameWithoutExtension(file);
            var directory = Path.GetDirectoryName(file);
            File representation;

            using (var stream = System.IO.File.OpenRead(file))
            {
                var lexer = new GrammarLexer(new AntlrInputStream(stream));
                var tokenStream = new CommonTokenStream(lexer);
                var context = new GrammarParser(tokenStream).program();

                var dsl = new Dsl(name);
                dsl.Visit(context);
                representation = dsl.File;
            }

            var outputs = representation.GenerateSource();

            if (outputs.HasMessageContent)
            {
                if (outputs.HasMarkers)
                {
                    var path = Path.Combine(directory, $"{representation.Name}MarkerInterfaces.cs");
                    System.IO.File.WriteAllText(path, outputs.Markers);
                    yield return path;
                }

                if (outputs.HasMessages)
                {
                    var path = Path.Combine(directory, $"{representation.Name}Messages.cs");
                    System.IO.File.WriteAllText(path, outputs.Messages);
                    yield return path;
                }

                if (outputs.HasEnumerations)
                {
                    var path = Path.Combine(directory, $"{representation.Name}Enums.cs");
                    System.IO.File.WriteAllText(path, outputs.Enumerations);
                    yield return path;
                }
            }

            if (outputs.HasStateDefinitions)
            {
                var path = Path.Combine(directory, $"{representation.Name}StateSubscriptions.cs");
                System.IO.File.WriteAllText(path, outputs.StateDefinitions);
                yield return path;
            }

            if (outputs.HasEntities)
            {
                var path = Path.Combine(directory, $"{representation.Name}Entities.cs");
                System.IO.File.WriteAllText(path, outputs.Entities);
                yield return path;
            }
        }
예제 #32
0
        public void Cluster_CRDT_should_work_in_2_node_cluster()
        {
            RunOn(() =>
            {
                // start with 20 on both nodes
                _replicator.Tell(Dsl.Update(KeyB, GCounter.Empty, WriteLocal.Instance, x => x.Increment(_cluster, 20)));
                ExpectMsg(new UpdateSuccess(KeyB, null));

                // add 1 on both nodes using WriteTwo
                _replicator.Tell(Dsl.Update(KeyB, GCounter.Empty, _writeTwo, x => x.Increment(_cluster, 1)));
                ExpectMsg(new UpdateSuccess(KeyB, null));

                // the total, after replication should be 42
                AwaitAssert(() =>
                {
                    _replicator.Tell(Dsl.Get(KeyB, _readTwo));
                    var c = ExpectMsg <GetSuccess>(g => Equals(g.Key, KeyB)).Get(KeyB);
                    c.Value.ShouldBe(42);
                });
            }, _first, _second);

            EnterBarrier("update-42");

            RunOn(() =>
            {
                // add 1 on both nodes using WriteAll
                _replicator.Tell(Dsl.Update(KeyB, GCounter.Empty, _writeAll, x => x.Increment(_cluster, 1)));
                ExpectMsg(new UpdateSuccess(KeyB, null));

                // the total, after replication should be 44
                AwaitAssert(() =>
                {
                    _replicator.Tell(Dsl.Get(KeyB, _readAll));
                    var c = ExpectMsg <GetSuccess>(g => Equals(g.Key, KeyB)).Get(KeyB);
                    c.Value.ShouldBe(44);
                });
            }, _first, _second);

            EnterBarrier("update-44");

            RunOn(() =>
            {
                // add 1 on both nodes using WriteMajority
                _replicator.Tell(Dsl.Update(KeyB, GCounter.Empty, _writeMajority, x => x.Increment(_cluster, 1)));
                ExpectMsg(new UpdateSuccess(KeyB, null));

                // the total, after replication should be 46
                AwaitAssert(() =>
                {
                    _replicator.Tell(Dsl.Get(KeyB, _readMajority));
                    var c = ExpectMsg <GetSuccess>(g => Equals(g.Key, KeyB)).Get(KeyB);
                    c.Value.ShouldBe(46);
                });
            }, _first, _second);

            EnterBarrierAfterTestStep();
        }
 protected override void Load(Dsl.CallData callData, SkillInstance instance)
 {
     int num = callData.GetParamNum();
     if (num > 0) {
         StartTime = long.Parse(callData.GetParamId(0));
     } else {
         StartTime = 0;
     }
 }
예제 #34
0
 private static RuleExprAst <int> MaxTotalDebt(int debtLimit)
 {
     return
         (from amount in Dsl.GetAmount()
          from creditA in Dsl.GetValue("CreditA")
          from creditB in Dsl.GetValue("CreditB")
          let totalCredit = creditA + creditB
                            select totalCredit > debtLimit ? 0 : amount);
 }
 protected override void Load(Dsl.CallData callData, SkillInstance instance)
 {
     int num = callData.GetParamNum();
     if (num >= 1) {
         StartTime = long.Parse(callData.GetParamId(0));
     }
     if (num >= 2) {
         m_RemainTime = long.Parse(callData.GetParamId(1));
     }
 }
예제 #36
0
 protected override void PreStart()
 {
     _pruningToken =
         Context.System.Scheduler.ScheduleTellRepeatedlyCancelable(
             PruningConfiguration.PruningInterval,
             PruningConfiguration.PruningInterval, Replicator.Replicator,
             Dsl.Get(
                 new LWWDictionaryKey <string, DeduplicationState>(
                     ReplicatorKey), request: new PurgeStateQuery()), Self);
 }
예제 #37
0
 /// <summary>
 /// On one of the nodes the data has been updated by the pruning, client can update anyway
 /// </summary>
 private void UpdateAfterPruning(int expectedValue)
 {
     _replicator.Tell(Dsl.Update(KeyA, GCounter.Empty, new WriteAll(_timeout), x => x.Increment(_cluster.SelfUniqueAddress, 1)));
     ExpectMsg <Replicator.UpdateSuccess>(msg =>
     {
         _replicator.Tell(Dsl.Get(KeyA, ReadLocal.Instance));
         var retrieved = ExpectMsg <Replicator.GetSuccess>().Get(KeyA);
         retrieved.Value.ShouldBe(expectedValue);
     });
 }
예제 #38
0
 private static RuleDef MaxAmountPerApplicant(int amountLimit, int ageLimit)
 {
     return
         ((
              from amount in Dsl.GetAmount <string>()
              from age in Variables.Age.Value
              where age < ageLimit
              select new Amount(Math.Min(amount, amountLimit))
              ).Lift());
 }
예제 #39
0
 private static RuleDef MaxAmountForAge(int amountLimit, int ageLimit)
 {
     return
         ((
              from amount in Dsl.GetAmount <Unit>()
              from ages in Variables.Age.Values
              where ages.Max() < ageLimit
              select new Amount(Math.Min(amount, amountLimit))
              ).Apply());
 }
 protected override void Load(Dsl.CallData callData, SkillInstance instance)
 {
     int num = callData.GetParamNum();
     if (num >= 4) {
         StartTime = long.Parse(callData.GetParamId(0));
         m_RelativeOffset.X = float.Parse(callData.GetParamId(1));
         m_RelativeOffset.Y = float.Parse(callData.GetParamId(2));
         m_RelativeOffset.Z = float.Parse(callData.GetParamId(3));
     }
 }
예제 #41
0
        public void Cluster_CRDT_should_support_prefer_oldest_members()
        {
            // disable gossip and delta replication to only verify the write and read operations
            var oldestReplicator = Sys.ActorOf(
                Replicator.Props(
                    ReplicatorSettings.Create(Sys).WithPreferOldest(true).WithGossipInterval(TimeSpan.FromMinutes(1))),//.withDeltaCrdtEnabled(false)),
                "oldestReplicator");

            Within(TimeSpan.FromSeconds(5), () =>
            {
                var countProbe = CreateTestProbe();
                AwaitAssert(() =>
                {
                    oldestReplicator.Tell(GetReplicaCount.Instance, countProbe.Ref);
                    countProbe.ExpectMsg(new ReplicaCount(3));
                });
            });
            EnterBarrier("oldest-replicator-started");

            var probe = CreateTestProbe();

            RunOn(() =>
            {
                oldestReplicator.Tell(
                    Dsl.Update(KeyK, new LWWRegister <string>(Cluster.SelfUniqueAddress, "0"), _writeTwo, a => a.WithValue(Cluster.SelfUniqueAddress, "1")),
                    probe.Ref);
                probe.ExpectMsg(new UpdateSuccess(KeyK, null));
            }, _second);
            EnterBarrier("updated-1");

            RunOn(() =>
            {
                // replicated to oldest
                oldestReplicator.Tell(new Get(KeyK, ReadLocal.Instance), probe.Ref);
                var msg = probe.ExpectMsg <GetSuccess>(m => m.Data is LWWRegister <string>);
                ((LWWRegister <string>)msg.Data).Value.Should().Be("1");
                //probe.ExpectMsg<GetSuccess[LWWRegister[String]]>.dataValue.value should === ("1");
            }, _first);

            RunOn(() =>
            {
                // not replicated to third (not among the two oldest)
                oldestReplicator.Tell(Dsl.Get(KeyK, ReadLocal.Instance), probe.Ref);
                probe.ExpectMsg(new NotFound(KeyK, null));

                // read from oldest
                oldestReplicator.Tell(Dsl.Get(KeyK, _readTwo), probe.Ref);
                var msg = probe.ExpectMsg <GetSuccess>(m => m.Data is LWWRegister <string>);
                ((LWWRegister <string>)msg.Data).Value.Should().Be("1");
                //probe.ExpectMsg<GetSuccess[LWWRegister[String]]>.dataValue.value should === ("1");
            }, _third);

            EnterBarrierAfterTestStep();
        }
예제 #42
0
            public Updater()
            {
                var cluster    = Cluster.Cluster.Get(Context.System);
                var replicator = DistributedData.Get(Context.System).Replicator;

                Receive <string>(s =>
                {
                    var update = Dsl.Update(Key, ORSet <string> .Empty, WriteLocal.Instance, old => old.Add(cluster.SelfUniqueAddress, s));
                    replicator.Tell(update);
                });
            }
예제 #43
0
 private void AssertDeleted(IKey <IReplicatedData> key)
 {
     Within(TimeSpan.FromSeconds(5), () =>
     {
         AwaitAssert(() =>
         {
             _replicator.Tell(Dsl.Get(key, ReadLocal.Instance));
             ExpectMsg(new DataDeleted(key));
         });
     });
 }
예제 #44
0
        public void Durable_CRDT_should_work_in_a_multi_node_cluster()
        {
            Join(second, first);

            var r = NewReplicator(Sys);

            Within(TimeSpan.FromSeconds(10), () =>
            {
                AwaitAssert(() =>
                {
                    r.Tell(Dsl.GetReplicaCount);
                    ExpectMsg(new ReplicaCount(2));
                });
            });

            EnterBarrier("both-initialized");

            r.Tell(Dsl.Update(keyA, GCounter.Empty, writeTwo, c => c.Increment(cluster)));
            ExpectMsg(new UpdateSuccess(keyA, null));

            r.Tell(Dsl.Update(keyC, ORSet <string> .Empty, writeTwo, c => c.Add(cluster, Myself.Name)));
            ExpectMsg(new UpdateSuccess(keyC, null));

            EnterBarrier("update-done-" + testStepCounter);

            r.Tell(Dsl.Get(keyA, readTwo));
            ExpectMsg <GetSuccess>().Get(keyA).Value.ShouldBe(2UL);

            r.Tell(Dsl.Get(keyC, readTwo));
            ExpectMsg <GetSuccess>().Get(keyC).Elements.ShouldBe(ImmutableHashSet.CreateRange(new[] { first.Name, second.Name }));

            EnterBarrier("values-verified-" + testStepCounter);

            Watch(r);
            Sys.Stop(r);
            ExpectTerminated(r);

            var r2 = default(IActorRef);

            AwaitAssert(() => r2 = NewReplicator(Sys)); // try until name is free
            AwaitAssert(() =>
            {
                r2.Tell(Dsl.GetKeyIds);
                ExpectMsg <GetKeysIdsResult>().Keys.ShouldNotBe(ImmutableHashSet <string> .Empty);
            });

            r2.Tell(Dsl.Get(keyA, ReadLocal.Instance));
            ExpectMsg <GetSuccess>().Get(keyA).Value.ShouldBe(2UL);

            r2.Tell(Dsl.Get(keyC, ReadLocal.Instance));
            ExpectMsg <GetSuccess>().Get(keyC).Elements.ShouldBe(ImmutableHashSet.CreateRange(new[] { first.Name, second.Name }));

            EnterBarrierAfterTestStep();
        }
 protected override void Load(Dsl.CallData callData, SkillInstance instance )
 {
     int num = callData.GetParamNum();
     if (num >= 2) {
         StartTime = long.Parse(callData.GetParamId(0));
         m_Speed = float.Parse(callData.GetParamId(1));
     }
     if (num >= 3) {
         m_IsEffectSkillTime = bool.Parse(callData.GetParamId(2));
     }
 }
예제 #46
0
 protected override void Load(Dsl.StatementData statementData)
 {
     if (statementData.Functions.Count == 2) {
         Dsl.FunctionData first = statementData.First;
         Dsl.FunctionData second = statementData.Second;
         if (null != first && null != first.Call && null != second && null != second.Call) {
             Load(first.Call);
             LoadCondition(second.Call);
         }
     }
 }
예제 #47
0
 protected override void Load(Dsl.CallData callData)
 {
     int num = callData.GetParamNum();
     if (num > 0) {
         m_Format.InitFromDsl(callData.GetParam(0));
     }
     for (int i = 1; i < callData.GetParamNum(); ++i) {
         StoryValue val = new StoryValue();
         val.InitFromDsl(callData.GetParam(i));
         m_FormatArgs.Add(val);
     }
 }
 protected override void Load(Dsl.CallData callData, SkillInstance instance)
 {
     if (callData.GetParamNum() > 0) {
         m_Type = callData.GetParamId(0);
     }
     if (callData.GetParamNum() > 1) {
         StartTime = long.Parse(callData.GetParamId(1));
     }
     if (callData.GetParamNum() > 2) {
         m_DeltaTime = long.Parse(callData.GetParamId(2));
     }
 }
 protected override void Load(Dsl.CallData callData)
 {
     int num = callData.GetParamNum();
     if (num > 1) {
         m_Object.InitFromDsl(callData.GetParam(0));
         m_Method.InitFromDsl(callData.GetParam(1));
     }
     for (int i = 2; i < callData.GetParamNum(); ++i) {
         StoryValue val = new StoryValue();
         val.InitFromDsl(callData.GetParam(i));
         m_Args.Add(val);
     }
 }
 protected override void Load(Dsl.CallData callData, SkillInstance instance)
 {
     int num = callData.GetParamNum();
     if (num >= 4) {
         StartTime = long.Parse(callData.GetParamId(0));
         m_RelativeOffset.x = float.Parse(callData.GetParamId(1));
         m_RelativeOffset.y = float.Parse(callData.GetParamId(2));
         m_RelativeOffset.z = float.Parse(callData.GetParamId(3));
     }
     if (num >= 5) {
         m_IsForRoundMove = callData.GetParamId(4) == "true";
     }
 }
예제 #51
0
 public static Vector2 CalcVector2(Dsl.CallData callData)
 {
     if (null == callData || callData.GetId() != "vector2")
     return Vector2.zero;
       int num = callData.GetParamNum();
       if (2 == num) {
     float x = float.Parse(callData.GetParamId(0));
     float y = float.Parse(callData.GetParamId(1));
     return new Vector2(x, y);
       } else {
     return Vector2.zero;
       }
 }
예제 #52
0
 internal static Vector3 CalcVector3(Dsl.CallData callData)
 {
     if (null == callData || callData.GetId() != "vector3")
     return Vector3.Zero;
       int num = callData.GetParamNum();
       if (3 == num) {
     float x = float.Parse(callData.GetParamId(0));
     float y = float.Parse(callData.GetParamId(1));
     float z = float.Parse(callData.GetParamId(2));
     return new Vector3(x, y, z);
       } else {
     return Vector3.Zero;
       }
 }
예제 #53
0
 internal static Quaternion CalcEularRotation(Dsl.CallData callData)
 {
     if (null == callData || callData.GetId() != "eular")
     return Quaternion.Identity;
       int num = callData.GetParamNum();
       if (3 == num) {
     float x = float.Parse(callData.GetParamId(0));
     float y = float.Parse(callData.GetParamId(1));
     float z = float.Parse(callData.GetParamId(2));
     return Quaternion.CreateFromYawPitchRoll(x, y, z);
       } else {
     return Quaternion.Identity;
       }
 }
예제 #54
0
 public static Vector3 CalcEularAngles(Dsl.CallData callData)
 {
     if (null == callData || callData.GetId() != "eular")
     return Vector3.Zero;
       int num = callData.GetParamNum();
       if (3 == num) {
     float x = float.Parse(callData.GetParamId(0));
     float y = float.Parse(callData.GetParamId(1));
     float z = float.Parse(callData.GetParamId(2));
     return new Vector3(x, y, z) * 59.29578f;
       } else {
     return Vector3.Zero;
       }
 }
 protected override void Load(Dsl.CallData callData, SkillInstance instance)
 {
     int num = callData.GetParamNum();
     if (num >= 6) {
         StartTime = long.Parse(callData.GetParamId(0));
         m_RemainTime = long.Parse(callData.GetParamId(1));
         m_GoPath = callData.GetParamId(2);
         m_ShaderName = callData.GetParamId(3);
         m_StartColor = DslUtility.CalcColor(callData.GetParam(4) as Dsl.CallData);
         m_ChangeColor = DslUtility.CalcColor(callData.GetParam(5) as Dsl.CallData);
     }
     if (num >= 7) {
         m_ChangeTime = long.Parse(callData.GetParamId(6));
     }
 }
예제 #56
0
 public static Quaternion CalcQuaternion(Dsl.CallData callData)
 {
     if (null == callData || callData.GetId() != "quaternion")
     return Quaternion.identity;
       int num = callData.GetParamNum();
       if (4 == num) {
     float x = float.Parse(callData.GetParamId(0));
     float y = float.Parse(callData.GetParamId(1));
     float z = float.Parse(callData.GetParamId(2));
     float w = float.Parse(callData.GetParamId(3));
     return new Quaternion(x, y, z, w);
       } else {
     return Quaternion.identity;
       }
 }
예제 #57
0
 public static Color CalcColor(Dsl.CallData callData)
 {
     if (null == callData || callData.GetId() != "color")
     return Color.white;
       int num = callData.GetParamNum();
       if (4 == num) {
     float r = float.Parse(callData.GetParamId(0));
     float g = float.Parse(callData.GetParamId(1));
     float b = float.Parse(callData.GetParamId(2));
     float a = float.Parse(callData.GetParamId(3));
     return new Color(r, g, b, a);
       } else {
     return Color.white;
       }
 }
예제 #58
0
 protected override void Load(Dsl.FunctionData functionData)
 {
     Dsl.CallData callData = functionData.Call;
     if (null != callData) {
         if (callData.GetParamNum() > 0) {
             Dsl.ISyntaxComponent param = callData.GetParam(0);
             m_Condition.InitFromDsl(param);
         }
         for (int i = 0; i < functionData.Statements.Count; i++) {
             IStoryCommand cmd = StoryCommandManager.Instance.CreateCommand(functionData.Statements[i]);
             if (null != cmd)
                 m_LoadedCommands.Add(cmd);
         }
     }
     IsCompositeCommand = true;
 }
 protected override void Load(Dsl.CallData callData, SkillInstance instance)
 {
     int num = callData.GetParamNum();
     if (num >= 1) {
         StartTime = long.Parse(callData.GetParamId(0));
     }
     if (num >= 9) {
         m_RelativeCenter.X = float.Parse(callData.GetParamId(1));
         m_RelativeCenter.Y = float.Parse(callData.GetParamId(2));
         m_RelativeCenter.Z = float.Parse(callData.GetParamId(3));
         m_Radius = float.Parse(callData.GetParamId(4));
         m_AngleOrLength = float.Parse(callData.GetParamId(5));
         m_AoeType = int.Parse(callData.GetParamId(6));
         m_MaxCount = int.Parse(callData.GetParamId(7));
         m_RelativeToTarget = callData.GetParamId(8) == "true";
     }
 }
예제 #60
0
 public static Quaternion CalcEularRotation(Dsl.CallData callData)
 {
     if (null == callData || callData.GetId() != "eular")
     return Quaternion.identity;
       int num = callData.GetParamNum();
       if (3 == num) {
     float x = float.Parse(callData.GetParamId(0));
     float y = float.Parse(callData.GetParamId(1));
     float z = float.Parse(callData.GetParamId(2));
     try {
       return Quaternion.Euler(x, y, z);
     } catch {
       return Quaternion.identity;
     }
       } else {
     return Quaternion.identity;
       }
 }