public void TestLoadFromConfigFileYamlNOOverridesButSet() { // Should be able to instantiate a new instance of "Client" with a valid path to the YAML configuration string f = TestUtils.TestUtils.RelocateFilePathsYAML("fixture/sdkintegration/network_configs/network-config.yaml".Locate()); NetworkConfig config = NetworkConfig.FromYamlFile(f); //HFClient client = HFClient.loadFromConfig(f); Assert.IsNotNull(config); HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); Channel channel = client.LoadChannelFromConfig("foo", config); Assert.IsNotNull(channel); Assert.IsTrue(channel.Orderers.Count != 0); foreach (Orderer orderer in channel.Orderers) { Properties properties = orderer.Properties; string str = properties.Get("grpc.keepalive_time_ms"); Assert.AreEqual(long.Parse(str), 360000L); str = properties.Get("grpc.keepalive_timeout_ms"); Assert.AreEqual(long.Parse(str), 180000L); } }
public void TestLoadFromConfigFileYamlNOOverrides() { // Should be able to instantiate a new instance of "Client" with a valid path to the YAML configuration string f = TestUtils.TestUtils.RelocateFilePathsYAML("fixture/sdkintegration/network_configs/network-config.yaml".Locate()); NetworkConfig config = NetworkConfig.FromYamlFile(f); //HFClient client = HFClient.loadFromConfig(f); Assert.IsNotNull(config); HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); Channel channel = client.LoadChannelFromConfig("foo", config); Assert.IsNotNull(channel); Assert.IsTrue(channel.Peers.Count != 0); foreach (Peer peer in channel.Peers) { Properties properties = peer.Properties; Assert.IsNotNull(properties); //Assert.IsNull(properties.Get("grpc.keepalive_time_ms")); Assert.IsNull(properties.Get("grpc.keepalive_timeout_ms")); //Assert.IsNull(properties.Get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls")); } }
private static Channel ConstructChannel(HFClient client, string channelName) { //Channel newChannel = client.GetChannel(channelName); Channel newChannel = client.LoadChannelFromConfig(channelName, networkConfig); if (newChannel == null) { throw new System.Exception("Channel " + channelName + " is not defined in the config file!"); } return(newChannel.Initialize()); }
public void TestGetChannelNotExists() { // Should be able to instantiate a new instance of "Client" with a valid path to the YAML configuration string f = TestUtils.TestUtils.RelocateFilePathsYAML("fixture/sdkintegration/network_configs/network-config.yaml".Locate()); NetworkConfig config = NetworkConfig.FromYamlFile(f); //HFClient client = HFClient.loadFromConfig(f); Assert.IsNotNull(config); HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); client.LoadChannelFromConfig("MissingChannel", config); }
public void TestNewChannel() { // Should be able to instantiate a new instance of "Channel" with the definition in the network configuration' JObject jsonConfig = GetJsonConfig(1, 0, 1); NetworkConfig config = NetworkConfig.FromJsonObject(jsonConfig); HFClient client = HFClient.Create(); TestHFClient.SetupClient(client); Channel channel = client.LoadChannelFromConfig(CHANNEL_NAME, config); Assert.IsNotNull(channel); Assert.AreEqual(CHANNEL_NAME, channel.Name); Assert.AreEqual(channel.GetPeers(PeerRole.SERVICE_DISCOVERY).Count, 1); }
public void TestGetChannelNoPeers() { // Should not be able to instantiate a new instance of "Channel" with no peers configured JObject jsonConfig = GetJsonConfig(1, 1, 0); NetworkConfig config = NetworkConfig.FromJsonObject(jsonConfig); HFClient client = HFClient.Create(); TestHFClient.SetupClient(client); client.LoadChannelFromConfig(CHANNEL_NAME, config); //HFClient client = HFClient.loadFromConfig(jsonConfig); //TestHFClient.setupClient(client); //client.getChannel(CHANNEL_NAME); }
public void TestLoadFromConfigFileJson() { // Should be able to instantiate a new instance of "Client" with a valid path to the JSON configuration string f = TestUtils.TestUtils.RelocateFilePathsJSON("fixture/sdkintegration/network_configs/network-config.json".Locate()); NetworkConfig config = NetworkConfig.FromJsonFile(f); Assert.IsNotNull(config); //HFClient client = HFClient.loadFromConfig(f); //Assert.Assert.IsNotNull(client); HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); Channel channel = client.LoadChannelFromConfig("mychannel", config); Assert.IsNotNull(channel); }
public void TestGetChannel() { // Should be able to instantiate a new instance of "Channel" with orderer, org and peer defined in the network configuration JObject jsonConfig = GetJsonConfig(4, 1, 1); NetworkConfig config = NetworkConfig.FromJsonObject(jsonConfig); HFClient client = HFClient.Create(); TestHFClient.SetupClient(client); Channel channel = client.LoadChannelFromConfig(CHANNEL_NAME, config); //HFClient client = HFClient.loadFromConfig(jsonConfig); //TestHFClient.setupClient(client); //Channel channel = client.getChannel(CHANNEL_NAME); Assert.IsNotNull(channel); Assert.AreEqual(CHANNEL_NAME, channel.Name); IReadOnlyList <Orderer> orderers = channel.Orderers; Assert.IsNotNull(orderers); Assert.AreEqual(1, orderers.Count); Orderer orderer = orderers.First(); Assert.AreEqual("orderer1.example.com", orderer.Name); IReadOnlyList <Peer> peers = channel.Peers; Assert.IsNotNull(peers); Assert.AreEqual(1, peers.Count); Peer peer = peers.First(); Assert.AreEqual("peer0.org1.example.com", peer.Name); }
public void TestLoadFromConfigFileYamlOverrides() { // Should be able to instantiate a new instance of "Client" with a valid path to the YAML configuration string f = TestUtils.TestUtils.RelocateFilePathsYAML("fixture/sdkintegration/network_configs/network-config.yaml".Locate()); NetworkConfig config = NetworkConfig.FromYamlFile(f); foreach (string peerName in config.PeerNames) { Properties peerProperties = config.GetPeerProperties(peerName); //example of setting keepAlive to avoid timeouts on inactive http2 connections. // Under 5 minutes would require changes to server side to accept faster ping rates. peerProperties.Set("grpc.keepalive_time_ms", 5 * 60 * 1000); peerProperties.Set("grpc.keepalive_timeout_ms", 8 * 1000); // peerProperties.Set("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", "true"); config.SetPeerProperties(peerName, peerProperties); } foreach (string orderName in config.OrdererNames) { Properties ordererProperties = config.GetOrdererProperties(orderName); ordererProperties.Set("grpc.max_receive_message_length", 9000000); //ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls", new Object[] {false}); config.SetOrdererProperties(orderName, ordererProperties); } //HFClient client = HFClient.loadFromConfig(f); Assert.IsNotNull(config); HFClient client = HFClient.Create(); client.CryptoSuite = Factory.Instance.GetCryptoSuite(); client.UserContext = TestUtils.TestUtils.GetMockUser(USER_NAME, USER_MSP_ID); Channel channel = client.LoadChannelFromConfig("foo", config); Assert.IsNotNull(channel); Assert.IsTrue(channel.Peers.Count > 0); foreach (Peer peer in channel.Peers) { Properties properties = peer.Properties; Assert.IsNotNull(properties); Assert.IsNotNull(properties.Get("grpc.keepalive_time_ms")); Assert.IsNotNull(properties.Get("grpc.keepalive_timeout_ms")); //Assert.IsNotNull(properties.get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls")); Endpoint ep = new Endpoint(peer.Url, properties); ChannelOption keepalive = ep.ChannelOptions.FirstOrDefault(a => a.Name == "grpc.keepalive_time_ms"); ChannelOption keepalivetimeout = ep.ChannelOptions.FirstOrDefault(a => a.Name == "grpc.keepalive_timeout_ms"); Assert.IsNotNull(keepalive); Assert.IsNotNull(keepalivetimeout); Assert.AreEqual(5 * 60 * 1000, keepalive.IntValue); Assert.AreEqual(8 * 1000, keepalivetimeout.IntValue); } foreach (Orderer orderer in channel.Orderers) { Properties properties = orderer.Properties; Assert.IsNotNull(properties); Assert.IsNotNull(properties.Get("grpc.max_receive_message_length")); //Assert.IsNotNull(properties.get("grpc.NettyChannelBuilderOption.keepAliveWithoutCalls")); Endpoint ep = new Endpoint(orderer.Url, properties); ChannelOption msize = ep.ChannelOptions.FirstOrDefault(a => a.Name == "grpc.max_receive_message_length"); Assert.IsNotNull(msize); Assert.AreEqual(9000000, msize.IntValue); } }