private void CreateBlocks(JsonNode root) { width = root.Get<int>("width"); height = root.Get<int>("height"); Blocks = new BlockType[width,height]; var blocksData = root["layers"][0]["data"].GetIntArray(); for (int y = 0; y < height; y++) for (int x = 0; x < width; x++) Blocks[x, y] = (BlockType)blocksData[x + y * width]; }
public void ParseBooleansStringsAndNumbers() { var json = new JsonNode("{ \"Flag\": true, \"SomeNumber\": 1.23, \"Text\": \"blub\" }"); Assert.AreEqual(3, json.NumberOfNodes); Assert.IsTrue(json.Get<bool>("Flag")); Assert.AreEqual(1.23f, json.Get<float>("SomeNumber")); Assert.AreEqual("blub", json.GetOrDefault("Text", "")); }
public void ExtractSomeDataValue() { var json = new JsonNode("{ \"SomeData\":6 }"); Assert.AreEqual(1, json.NumberOfNodes); Assert.AreEqual(6, json.Get<int>("SomeData")); Assert.Throws<JsonNode.NodeNotFound>(() => json.Get<int>("blah")); }
public virtual void TestRMNMInfoMissmatch() { RMContext rmc = Org.Mockito.Mockito.Mock <RMContext>(); ResourceScheduler rms = Org.Mockito.Mockito.Mock <ResourceScheduler>(); ConcurrentMap <NodeId, RMNode> map = new ConcurrentHashMap <NodeId, RMNode>(); RMNode node = MockNodes.NewNodeInfo(1, MockNodes.NewResource(4 * 1024)); map[node.GetNodeID()] = node; Org.Mockito.Mockito.When(rmc.GetRMNodes()).ThenReturn(map); RMNMInfo rmInfo = new RMNMInfo(rmc, rms); string liveNMs = rmInfo.GetLiveNodeManagers(); ObjectMapper mapper = new ObjectMapper(); JsonNode jn = mapper.ReadTree(liveNMs); NUnit.Framework.Assert.AreEqual("Unexpected number of live nodes:", 1, jn.Size()); IEnumerator <JsonNode> it = jn.GetEnumerator(); while (it.HasNext()) { JsonNode n = it.Next(); NUnit.Framework.Assert.IsNotNull(n.Get("HostName")); NUnit.Framework.Assert.IsNotNull(n.Get("Rack")); NUnit.Framework.Assert.IsTrue("Node " + n.Get("NodeId") + " should be RUNNING", n .Get("State").AsText().Contains("RUNNING")); NUnit.Framework.Assert.IsNotNull(n.Get("NodeHTTPAddress")); NUnit.Framework.Assert.IsNotNull(n.Get("LastHealthUpdate")); NUnit.Framework.Assert.IsNotNull(n.Get("HealthReport")); NUnit.Framework.Assert.IsNotNull(n.Get("NodeManagerVersion")); NUnit.Framework.Assert.IsNull(n.Get("NumContainers")); NUnit.Framework.Assert.IsNull(n.Get("UsedMemoryMB")); NUnit.Framework.Assert.IsNull(n.Get("AvailableMemoryMB")); } }
public void ExtractSomeDataValue() { var json = new JsonNode("{ \"SomeData\":6 }"); Assert.AreEqual(1, json.NumberOfNodes); Assert.AreEqual(6, json.Get <int>("SomeData")); Assert.Throws <JsonNode.NodeNotFound>(() => json.Get <int>("blah")); }
public void ParseBooleansStringsAndNumbers() { var json = new JsonNode("{ \"Flag\": true, \"SomeNumber\": 1.23, \"Text\": \"blub\" }"); Assert.AreEqual(3, json.NumberOfNodes); Assert.IsTrue(json.Get <bool>("Flag")); Assert.AreEqual(1.23f, json.Get <float>("SomeNumber")); Assert.AreEqual("blub", json.GetOrDefault("Text", "")); }
private void CreateActor(JsonNode entityData) { JsonNode properties = entityData["properties"]; var position = new Vector2D(entityData.Get<int>("x"), entityData.Get<int>("y")); var type = entityData.Get<string>("type"); actorList.Add(new Actor(this, position, type) { MaxVelocityX = Meter * properties.GetOrDefault("maxdx", DefaultMaxVelocityX), WantsToGoLeft = properties.GetOrDefault("left", false), WantsToGoRight = properties.GetOrDefault("right", false) }); }
private void CreateActor(JsonNode entityData) { JsonNode properties = entityData["properties"]; var position = new Vector2D(entityData.Get <int>("x"), entityData.Get <int>("y")); var type = entityData.Get <string>("type"); actorList.Add(new Actor(this, position, type) { MaxVelocityX = Meter * properties.GetOrDefault("maxdx", DefaultMaxVelocityX), WantsToGoLeft = properties.GetOrDefault("left", false), WantsToGoRight = properties.GetOrDefault("right", false) }); }
private void CreateBlocks(JsonNode root) { width = root.Get <int>("width"); height = root.Get <int>("height"); Blocks = new BlockType[width, height]; var blocksData = root["layers"][0]["data"].GetIntArray(); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Blocks[x, y] = (BlockType)blocksData[x + y * width]; } } }
/// <summary> /// In order to query a namenode mxbean, a http connection in the form of /// "http://hostname/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo" /// is sent to namenode. /// </summary> /// <remarks> /// In order to query a namenode mxbean, a http connection in the form of /// "http://hostname/jmx?qry=Hadoop:service=NameNode,name=NameNodeInfo" /// is sent to namenode. JMX attributes are exposed via JmxJsonServelet on /// the namenode side. /// </remarks> /// <exception cref="System.IO.IOException"/> private static JsonNode GetProperty(string props, string propertyname) { if (props == null || props.Equals(string.Empty) || propertyname == null || propertyname .Equals(string.Empty)) { return(null); } ObjectMapper m = new ObjectMapper(); JsonNode rootNode = m.ReadValue <JsonNode>(props); JsonNode jn = rootNode.Get("beans").Get(0).Get(propertyname); return(jn); }
public static TextAnchor JsonToTextAnchor(JsonNode json) { TextAnchor ta = TextAnchor.MiddleCenter; switch (json.Get <string>()) { case "LowerCenter": ta = TextAnchor.LowerCenter; break; case "LowerLeft": ta = TextAnchor.LowerLeft; break; case "LowerRight": ta = TextAnchor.LowerRight; break; case "MiddleCenter": ta = TextAnchor.MiddleCenter; break; case "MiddleLeft": ta = TextAnchor.MiddleLeft; break; case "MiddleRight": ta = TextAnchor.MiddleRight; break; case "UpperCenter": ta = TextAnchor.UpperCenter; break; case "UpperLeft": ta = TextAnchor.UpperLeft; break; case "UpperRight": ta = TextAnchor.UpperRight; break; default: Debug.LogError("Unknown Alignment"); break; } return(ta); }
public virtual void TestRMNMInfo() { if (!(new FilePath(MiniMRYarnCluster.Appjar)).Exists()) { Log.Info("MRAppJar " + MiniMRYarnCluster.Appjar + " not found. Not running test." ); return; } RMContext rmc = mrCluster.GetResourceManager().GetRMContext(); ResourceScheduler rms = mrCluster.GetResourceManager().GetResourceScheduler(); RMNMInfo rmInfo = new RMNMInfo(rmc, rms); string liveNMs = rmInfo.GetLiveNodeManagers(); ObjectMapper mapper = new ObjectMapper(); JsonNode jn = mapper.ReadTree(liveNMs); NUnit.Framework.Assert.AreEqual("Unexpected number of live nodes:", Numnodemanagers , jn.Size()); IEnumerator <JsonNode> it = jn.GetEnumerator(); while (it.HasNext()) { JsonNode n = it.Next(); NUnit.Framework.Assert.IsNotNull(n.Get("HostName")); NUnit.Framework.Assert.IsNotNull(n.Get("Rack")); NUnit.Framework.Assert.IsTrue("Node " + n.Get("NodeId") + " should be RUNNING", n .Get("State").AsText().Contains("RUNNING")); NUnit.Framework.Assert.IsNotNull(n.Get("NodeHTTPAddress")); NUnit.Framework.Assert.IsNotNull(n.Get("LastHealthUpdate")); NUnit.Framework.Assert.IsNotNull(n.Get("HealthReport")); NUnit.Framework.Assert.IsNotNull(n.Get("NodeManagerVersion")); NUnit.Framework.Assert.IsNotNull(n.Get("NumContainers")); NUnit.Framework.Assert.AreEqual(n.Get("NodeId") + ": Unexpected number of used containers" , 0, n.Get("NumContainers").AsInt()); NUnit.Framework.Assert.AreEqual(n.Get("NodeId") + ": Unexpected amount of used memory" , 0, n.Get("UsedMemoryMB").AsInt()); NUnit.Framework.Assert.IsNotNull(n.Get("AvailableMemoryMB")); } }