예제 #1
0
        public void HoconValue_GetObject_should_use_fallback_values_with_complex_objects()
        {
            var config1            = HoconConfigurationFactory.ParseString(@"
	            akka.actor.deployment {
		            /worker1 {
			            router = round-robin-group1
			            routees.paths = [""/user/testroutes/1""]
		            }
	            }"    );
            var config2            = HoconConfigurationFactory.ParseString(@"
	            akka.actor.deployment {
		            /worker2 {
			            router = round-robin-group2
			            routees.paths = [""/user/testroutes/2""]
		            }
	            }"    );
            var configWithFallback = config1.WithFallback(config2);

            var config  = configWithFallback.GetConfig("akka.actor.deployment");
            var rootObj = config.Value.GetObject();

            rootObj.Unwrapped.Should().ContainKeys("/worker1", "/worker2");
            rootObj["/worker1.router"].Raw.Should().Be("round-robin-group1");
            rootObj["/worker1.router"].Raw.Should().Be("round-robin-group1");
            rootObj["/worker1.routees.paths"].Value[0].GetArray()[0].Raw.Should().Be(@"""/user/testroutes/1""");
            rootObj["/worker2.routees.paths"].Value[0].GetArray()[0].Raw.Should().Be(@"""/user/testroutes/2""");
        }
예제 #2
0
        public void CanUseFallbackString()
        {
            var hocon1 = @"
foo {
   bar {
      a=123str
   }
}";
            var hocon2 = @"
foo {
   bar {
      a=1str
      b=2str
      c=3str
   }
   car = ""bar""
}
dar = d";

            var config1 = HoconConfigurationFactory.ParseString(hocon1);
            var config2 = HoconConfigurationFactory.ParseString(hocon2);

            var config = config1.WithFallback(config2);

            Assert.Equal("123str", config.GetString("foo.bar.a"));
            Assert.Equal("2str", config.GetString("foo.bar.b"));
            Assert.Equal("3str", config.GetString("foo.bar.c"));
            Assert.Equal("bar", config.GetString("foo.car"));
            Assert.Equal("d", config.GetString("dar"));
        }
예제 #3
0
        public void Should_dump_HOCON_with_1_Fallback()
        {
            var myHocon1 = HoconConfigurationFactory.ParseString(@"akka{
                actor.provider = cluster
                deployment{
                    /foo {
                        dispatcher = bar
                    }
                }
            }");

            var myHocon2 = HoconConfigurationFactory.ParseString(@"akka{
                debug{
                    received  = on
                }
                actor.provider = cluster
                deployment{
                    /foo {
                        dispatcher = foo
                    }
                    /bar {
                        mailbox = ""myFoo""
                    }
                }
            }");

            var fullHocon = myHocon1.WithFallback(myHocon2);

            var dump = fullHocon.DumpConfig();

            dump.Should().Contain(myHocon1.PrettyPrint(2));
            dump.Should().Contain(myHocon2.PrettyPrint(2));
        }
예제 #4
0
        public void WithFallback_ShouldMergeSubstitutionProperly()
        {
            var a        = HoconConfigurationFactory.ParseString("{ executor : fork-join-executor }");
            var subbed   = HoconConfigurationFactory.ParseString(@"
mystring = substring
myapp{
    my-fork-join-dispatcher {
        type = ForkJoinDispatcher
        dedicated-thread-pool.thread-count = 4
        dedicated-thread-pool.substring = ${mystring}
    }
}
akka.actor.deployment{
    /pool1 {
        router = random-pool
        pool-dispatcher = ${myapp.my-fork-join-dispatcher}
    }
}");
            var combined = a
                           .WithFallback(subbed.GetConfig("akka.actor.deployment./pool1.pool-dispatcher"));

            var expectedConfig = HoconConfigurationFactory.ParseString(@"
executor : fork-join-executor
type = ForkJoinDispatcher
dedicated-thread-pool.thread-count = 4
dedicated-thread-pool.substring = substring
");

            var result   = combined.Root.ToString(1, 2);
            var expected = expectedConfig.Root.ToString(1, 2);

            expected.Should().BeEquivalentTo(result);
            combined.GetInt("dedicated-thread-pool.thread-count").Should().Be(4);
            combined.GetString("dedicated-thread-pool.substring").Should().Be("substring");
        }
예제 #5
0
        public void CanUseFallbackInSubConfig()
        {
            var hocon1 = @"
foo {
   bar {
      a=123
   }
}";
            var hocon2 = @"
foo {
   bar {
      a=1
      b=2
      c=3
   }
}";

            var config1 = HoconConfigurationFactory.ParseString(hocon1);
            var config2 = HoconConfigurationFactory.ParseString(hocon2);

            var config = config1.WithFallback(config2).GetConfig("foo.bar");

            Assert.Equal(123, config.GetInt("a"));
            Assert.Equal(2, config.GetInt("b"));
            Assert.Equal(3, config.GetInt("c"));
        }
예제 #6
0
        private static void Main(string[] args)
        {
            var config = HoconConfigurationFactory.Load();
            var val    = config.GetString("root.simple-string");

            Console.WriteLine("Hocon says: " + val);
            Console.ReadKey();
        }
예제 #7
0
        public void CanLoadDefaultConfig()
        {
            var defaultConf = HoconConfigurationFactory.Default();

            defaultConf.Should().NotBe(HoconConfigurationFactory.Empty);
            defaultConf.HasPath("root.simple-string").Should().BeTrue();
            defaultConf.GetString("root.simple-string").Should().Be("Hello HOCON2");
        }
예제 #8
0
        public void CanParseDuplicateKeys()
        {
            var hocon   = @"
               akka{
                    loglevel=INFO
	                loggers=[""Akka.Logger.Serilog.SerilogLogger, Akka.Logger.Serilog""]

                    remote {
		                log-remote-lifecycle-events = DEBUG
		                dot-netty.tcp {
			                port = 0
			                hostname = localhost
			                send-buffer-size =  60000000b        
			                receive-buffer-size =  60000000b
			                maximum-frame-size = 30000000b
		                }
	                }

                    actor.provider = cluster

                    # duplicate
                    remote {
		                log-remote-lifecycle-events = DEBUG
		                dot-netty.tcp {
			                port = 0
			                hostname = localhost
			                send-buffer-size =  60000000b        
			                receive-buffer-size =  60000000b
			                maximum-frame-size = 30000000b
		                }
	                }

                    cluster {
		                allow-weakly-up-members = on
		                seed-nodes = [""akka.tcp://ClusterSys@localhost:3881""]
		                roles = [pubsub,webapi]

		                failure-detector {
			                acceptable-heartbeat-pause=8s
		                }

		                pub-sub {
			                role = pubsub
		                }
		                downing-provider-class = ""Akka.Cluster.SplitBrainResolver, Akka.Cluster""
		                split-brain-resolver {
			                active-strategy = keep-majority
			                stable-after = 30s 
		                }
		                down-removal-margin = 30s
	                }
                }
            ";
            var config  = HoconConfigurationFactory.ParseString(hocon);
            var config2 = config.GetConfig("akka.remote");

            config2.GetString("dot-netty.tcp.hostname").Should().Be("localhost");
        }
예제 #9
0
파일: Program.cs 프로젝트: Arkatufus/HOCON
        public static void ShouldSerializeHocon(string hocon, string fallback1, string fallback2)
        {
            var hocon1 = HoconConfigurationFactory.ParseString(hocon);
            var fb1    = string.IsNullOrEmpty(fallback1) ? Config.Empty : HoconConfigurationFactory.ParseString(fallback1);
            var fb2    = string.IsNullOrEmpty(fallback1) ? Config.Empty : HoconConfigurationFactory.ParseString(fallback2);

            var final = hocon1.WithFallback(fb1).WithFallback(fb2);

            VerifySerialization(final);
        }
예제 #10
0
        public void CanParseQuotedKeys()
        {
            var hocon  = @"
a {
   ""some quoted, key"": 123
}
";
            var config = HoconConfigurationFactory.ParseString(hocon);

            Assert.Equal(123, config.GetInt("a.\"some quoted, key\""));
        }
예제 #11
0
        public void QuotedKeyWithInvalidCharactersShouldSerializeProperly()
        {
            var hoconString  = @"this.""should[]"".work = true";
            var config       = HoconConfigurationFactory.ParseString(hoconString);
            var serialized   = JsonConvert.SerializeObject(config);
            var deserialized = JsonConvert.DeserializeObject <Config>(serialized);

            Assert.True(config.GetBoolean("this.\"should[]\".work"));
            Assert.True(deserialized.GetBoolean("this.\"should[]\".work"));
            Assert.Equal(config, deserialized);
        }
예제 #12
0
        public void Config_should_be_serializable()
        {
            var config       = HoconConfigurationFactory.ParseString(@"
                foo{
                  bar.biz = 12
                  baz = ""quoted""
                }");
            var serialized   = JsonConvert.SerializeObject(config);
            var deserialized = JsonConvert.DeserializeObject <Config>(serialized);

            config.DumpConfig().Should().Be(deserialized.DumpConfig());
        }
예제 #13
0
        public void HoconValue_GetObject_should_use_fallback_values()
        {
            var config1    = HoconConfigurationFactory.ParseString("a = 5");
            var config2    = HoconConfigurationFactory.ParseString("b = 3");
            var config     = config1.WithFallback(config2);
            var rootObject = config.Root.GetObject();

            rootObject.ContainsKey("a").Should().BeTrue();
            rootObject["a"].Raw.Should().Be("5");
            rootObject.ContainsKey("b").Should().BeTrue();
            rootObject["b"].Raw.Should().Be("3");
        }
예제 #14
0
        public void CanEnumerateQuotedKeys()
        {
            var hocon      = @"
a {
   ""some quoted, key"": 123
}
";
            var config     = HoconConfigurationFactory.ParseString(hocon);
            var config2    = config.GetConfig("a");
            var enumerable = config2.AsEnumerable();

            Assert.Equal("some quoted, key", enumerable.Select(kvp => kvp.Key).First());
        }
예제 #15
0
        public void CanParseSubConfig()
        {
            var hocon     = @"
a {
   b {
     c = 1
     d = true
   }
}";
            var config    = HoconConfigurationFactory.ParseString(hocon);
            var subConfig = config.GetConfig("a");

            Assert.Equal(1, subConfig.GetInt("b.c"));
            Assert.True(subConfig.GetBoolean("b.d"));
        }
예제 #16
0
        public void Should_dump_stand_alone_HOCON()
        {
            var myHocon = HoconConfigurationFactory.ParseString(@"akka{
                actor.provider = cluster
                deployment{
                    /foo {
                        dispatcher = bar
                    }
                }
            }");

            var dump = myHocon.DumpConfig();

            dump.Should().Contain(myHocon.PrettyPrint(2));
        }
예제 #17
0
        public void Config_will_not_throw_on_duplicate_fallbacks()
        {
            var c1 = HoconConfigurationFactory.ParseString(@"foo.bar = baz");
            var c2 = HoconConfigurationFactory.ParseString(@"bar.biz = fuber");

            // normal fallback
            var f1 = c1.WithFallback(c2).WithFallback(Config.Empty);

            c1.Fallbacks.Count.Should().Be(0); // original copy should not have been modified.

            // someone adds the same fallback again with realizing it
            f1.WithFallback(Config.Empty).GetString("bar.biz").Should().Be("fuber"); // shouldn't throw

            var final = f1.WithFallback(c2);

            final.GetString("bar.biz").Should().Be("fuber"); // shouldn't throw
        }
예제 #18
0
        public void Should_dump_HOCON_with_2_Fallback()
        {
            var myHocon1 = HoconConfigurationFactory.ParseString(@"akka{
                actor.provider = cluster
                deployment{
                    /foo {
                        dispatcher = bar
                    }
                }
            }");

            var myHocon2 = HoconConfigurationFactory.ParseString(@"akka{
                debug{
                    received  = on
                }
                actor.provider = cluster
                deployment{
                    /foo {
                        dispatcher = foo
                    }
                    /bar {
                        mailbox = ""myFoo""
                    }
                }
            }");

            var myHocon3 = HoconConfigurationFactory.ParseString(@"akka{
                remote{
                    transport = ""foo""
                }
            }");

            var fullHocon = myHocon1
                            .SafeWithFallback(myHocon2)
                            .SafeWithFallback(myHocon3);

            fullHocon.GetString("akka.remote.transport").Should().Be("foo");

            var dump = fullHocon.DumpConfig();

            dump.Should().Contain(myHocon1.PrettyPrint(2));
            dump.Should().Contain(myHocon2.PrettyPrint(2));
            dump.Should().Contain(myHocon3.PrettyPrint(2));
        }
예제 #19
0
        public void ShouldSerializeFallbackValues()
        {
            var a = HoconConfigurationFactory.ParseString(@" akka : {
                some-key : value
            }");
            var b = HoconConfigurationFactory.ParseString(@"akka : {
                other-key : 42
            }");

            var c = a.WithFallback(b);

            c.GetInt("akka.other-key").Should().Be(42, "Fallback value should exist as data");
            c.ToString().Should().NotContain("other-key", "Fallback values are ignored by default");
            c.ToString(true).Should().Contain("other-key", "Fallback values should be displayed when requested");

            c.GetString("akka.some-key").Should().Be("value", "Original value should remain");
            c.ToString().Should().Contain("some-key", "Original values are shown by default");
            c.ToString(true).Should().Contain("some-key", "Original values should be displayed always");
        }
예제 #20
0
        public void Quoted_key_should_be_parsed()
        {
            var config1 = HoconConfigurationFactory.ParseString(
                "akka.actor.deployment.default = { }"
                );
            var config2 = HoconConfigurationFactory.ParseString(@"
                akka.actor.deployment {
                  ""/weird/*"" {
                    router = round-robin-pool
                    nr-of-instances = 2
                  }
                }
            ");

            var megred = config2.WithFallback(config1).Value;

            // Is throwing at "/weird/*" key parsing
            megred.Invoking(r => r.GetObject()).Should().NotThrow();
        }
예제 #21
0
        public void CanUseMultiLevelFallback()
        {
            var hocon1 = @"
foo {
   bar {
      a=123
   }
}";
            var hocon2 = @"
foo {
   bar {
      a=1
      b=2
      c=3
   }
}";
            var hocon3 = @"
foo {
   bar {
      a=99
      zork=555
   }
}";
            var hocon4 = @"
foo {
   bar {
      borkbork=-1
   }
}";

            var config1 = HoconConfigurationFactory.ParseString(hocon1);
            var config2 = HoconConfigurationFactory.ParseString(hocon2);
            var config3 = HoconConfigurationFactory.ParseString(hocon3);
            var config4 = HoconConfigurationFactory.ParseString(hocon4);

            var config = config1.WithFallback(config2.WithFallback(config3.WithFallback(config4)));

            Assert.Equal(123, config.GetInt("foo.bar.a"));
            Assert.Equal(2, config.GetInt("foo.bar.b"));
            Assert.Equal(3, config.GetInt("foo.bar.c"));
            Assert.Equal(555, config.GetInt("foo.bar.zork"));
            Assert.Equal(-1, config.GetInt("foo.bar.borkbork"));
        }
예제 #22
0
        public void WithFallback_ShouldNotChangeOriginalConfig()
        {
            var a = HoconConfigurationFactory.ParseString(@" akka : {
                some-key : value
            }");
            var b = HoconConfigurationFactory.ParseString(@"akka : {
                other-key : 42
            }");

            var oldA        = a;
            var oldAContent = new Config(a);

            a.WithFallback(b);
            a.WithFallback(b);

            a.Fallbacks.Count.Should().Be(0);
            a.GetString("akka.other-key", null).Should().BeNull();
            ReferenceEquals(oldA, a).Should().BeTrue();
            oldAContent.Should().Equals(a);
        }
예제 #23
0
        public void CanSubstituteArrayCorrectly()
        {
            var hocon     = @"
 c: {
    q: {
        a: [2, 5]
    }
}
c: {
    m: ${c.q} {a: [6]}
}
";
            var config    = HoconConfigurationFactory.ParseString(hocon);
            var unchanged = config.GetIntList("c.q.a");

            unchanged.Should().Equal(2, 5);
            var changed = config.GetIntList("c.m.a");

            changed.Should().Equal(6);
        }
예제 #24
0
        public void Quoted_key_with_dot_should_be_parsed()
        {
            var config1 = HoconConfigurationFactory.ParseString(
                @"akka.actor.serialization-bindings = {
                    ""System.Byte[]"" : bytes,
                    ""System.Object"" : json
                }"
                );
            var config2 = HoconConfigurationFactory.ParseString(
                @"akka.actor.serialization-bindings = {
                    ""System.Byte[]"" : bytes,
                    ""System.Object"" : json
                }"
                );

            var megred = config2.WithFallback(config1).Value;

            // Is throwing at "System.Byte[]" key parsing
            megred.Invoking(r => r.GetObject()).Should().NotThrow();
        }
예제 #25
0
        private static void Main(string[] args)
        {
            // The "environment-property" property is set through environment variable.
            // On debug mode, it is set inside the debug tab in the project properties.
            var baseHocon  = @"
root {
   some-property1 = 123
   some-property2 = 234 
   environment-property = ${?ENV_MY_PROPERTY} 
}
";
            var userHocon  = @"
root {
   some-property2 = 456  
   some-property3 = 789
}
";
            var baseConfig = HoconConfigurationFactory.ParseString(baseHocon);
            var userConfg  = HoconConfigurationFactory.ParseString(userHocon);

            var merged = userConfg.WithFallback(baseConfig);

            var val1 = merged.GetString("root.some-property1");
            var val2 = merged.GetString("root.some-property2");
            var val3 = merged.GetString("root.some-property3");

            Console.WriteLine("root.some-property1 = {0}", val1);
            Console.WriteLine("root.some-property2 = {0}", val2);
            Console.WriteLine("root.some-property3 = {0}", val3);

            if (merged.HasPath("root.environment-property"))
            {
                var envVal = merged.GetString("root.environment-property");
                Console.WriteLine("root.environment-property = {0}", envVal);
            }

            Console.ReadKey();
        }
예제 #26
0
        public void Fallback_should_not_be_modified()
        {
            var config1 = HoconConfigurationFactory.ParseString(@"
	            a {
                    b {
                        c = 5
                        e = 7
                    }
	            }"    );
            var config2 = HoconConfigurationFactory.ParseString(@"
	            a {
                    b {
                        d = 3
                        c = 1
                    }
	            }"    );

            var merged = config1.WithFallback(config2).Value.GetObject(); // Perform values loading

            config1.GetInt("a.b.c").Should().Be(5);
            config1.GetInt("a.b.e").Should().Be(7);
            config2.GetInt("a.b.c").Should().Be(1);
            config2.GetInt("a.b.d").Should().Be(3);
        }
예제 #27
0
        public void CanParseSerializersAndBindings()
        {
            var hocon = @"
akka.actor {
    serializers {
      akka-containers = ""Akka.Remote.Serialization.MessageContainerSerializer, Akka.Remote""
      proto = ""Akka.Remote.Serialization.ProtobufSerializer, Akka.Remote""
      daemon-create = ""Akka.Remote.Serialization.DaemonMsgCreateSerializer, Akka.Remote""
    }

    serialization-bindings {
# Since com.google.protobuf.Message does not extend Serializable but
# GeneratedMessage does, need to use the more specific one here in order
# to avoid ambiguity
      ""Akka.Actor.ActorSelectionMessage"" = akka-containers
      ""Akka.Remote.DaemonMsgCreate, Akka.Remote"" = daemon-create
    }

}";

            var config = HoconConfigurationFactory.ParseString(hocon);

            var serializersConfig       = config.GetConfig("akka.actor.serializers").AsEnumerable().ToList();
            var serializerBindingConfig = config.GetConfig("akka.actor.serialization-bindings").AsEnumerable().ToList();

            Assert.Equal(
                "Akka.Remote.Serialization.MessageContainerSerializer, Akka.Remote",
                serializersConfig.Select(kvp => kvp.Value)
                .First()
                .GetString()
                );
            Assert.Equal(
                "Akka.Remote.DaemonMsgCreate, Akka.Remote",
                serializerBindingConfig.Select(kvp => kvp.Key).Last()
                );
        }
예제 #28
0
 public void Setup()
 {
     config = HoconConfigurationFactory.ParseString(TestConfigStrings.AkkaConfigString);
 }
예제 #29
0
 public void ShouldResolveEmptyToEmpty()
 {
     HoconConfigurationFactory.Empty.IsEmpty.Should().BeTrue();
     HoconConfigurationFactory.ParseString("{}").IsEmpty.Should().BeTrue();
     Config.Empty.IsEmpty.Should().BeTrue();
 }
예제 #30
0
 /// <summary>
 ///     Loads a configuration named "akka" defined in the current application's
 ///     configuration file, e.g. app.config or web.config.
 /// </summary>
 /// <returns>
 ///     The configuration defined in the configuration file. If the section
 ///     "akka" is not found, this returns an empty Config.
 /// </returns>
 public static Config Load()
 {
     return(HoconConfigurationFactory.Default());
 }