下面列出了javax.management.openmbean.TabularData#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
@Test
public void stepExecutions() throws Exception {
final TabularData instance = TabularData.class.cast(result("getStepExecutions", id));
assertEquals(1, instance.size());
final CompositeData cd = instance.get(List.class.cast(instance.keySet().iterator().next()).toArray());
assertEquals(id, cd.get("stepExecutionId"));
assertEquals("jmx-step", cd.get("stepName"));
assertEquals("mock", cd.get("Exit status"));
assertEquals("COMPLETED", cd.get("Batch status"));
assertEquals(0L, cd.get("Commit"));
}
@Test
public void jobExecution() throws Exception {
final TabularData instance = TabularData.class.cast(result("getJobExecution", id));
assertEquals(1, instance.size());
final CompositeData cd = instance.get(List.class.cast(instance.keySet().iterator().next()).toArray());
assertEquals(id, cd.get("executionId"));
assertEquals("jmx", cd.get("jobName"));
assertEquals("COMPLETED", cd.get("Exit status"));
assertEquals("COMPLETED", cd.get("Batch status"));
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
private static String getProperty(TabularData td, String propName) {
CompositeData cd = td.get(new Object[] { propName});
if (cd != null) {
String key = (String) cd.get("key");
if (!propName.equals(key)) {
throw new RuntimeException("TEST FAILED: " +
key + " property found" +
" but expected to be " + propName);
}
return (String) cd.get("value");
}
return null;
}
@Test
public void properlyAggregateMapsByKeyAccordingToTheirValueAggregationPolicy() throws Exception {
Map<String, Integer> map_1 = new HashMap<>();
map_1.put("a", 1);
map_1.put("b", 2);
map_1.put("c", 100);
Map<String, Integer> map_2 = new HashMap<>();
map_2.put("b", 2);
map_2.put("c", 200);
map_2.put("d", 5);
MBeanWithMap mBeanWithMap_1 = new MBeanWithMap(map_1);
MBeanWithMap mBeanWithMap_2 = new MBeanWithMap(map_2);
DynamicMBean mbean = createDynamicMBeanFor(mBeanWithMap_1, mBeanWithMap_2);
TabularData tabularData = (TabularData) mbean.getAttribute("nameToNumber");
assertEquals(4, tabularData.size());
CompositeData row_1 = tabularData.get(keyForTabularData("a"));
assertEquals(1, row_1.get("value"));
CompositeData row_2 = tabularData.get(keyForTabularData("b"));
assertEquals(2, row_2.get("value"));
CompositeData row_3 = tabularData.get(keyForTabularData("c"));
assertNull(row_3.get("value"));
CompositeData row_4 = tabularData.get(keyForTabularData("d"));
assertEquals(5, row_4.get("value"));
}
public static Map<List<?>, Map<String, Object>> tabularDataToMapOfMaps(TabularData table) {
Map<List<?>, Map<String, Object>> result = Maps.newLinkedHashMap();
for (Object k : table.keySet()) {
final Object[] kValues = ((List<?>)k).toArray();
CompositeData v = table.get(kValues);
result.put((List<?>)k, compositeDataToMap(v));
}
return result;
}
private static MBeanDump.MBeanValue getTabularDataValue(TabularData tabularData) {
// linked hash map used to preserve row ordering
List<MBeanDump.MBeanValueMapEntry> outerEntries = Lists.newArrayList();
Set<String> attributeNames = tabularData.getTabularType().getRowType().keySet();
for (Object key : tabularData.keySet()) {
// TabularData.keySet() returns "Set<List<?>> but is declared Set<?> for
// compatibility reasons" (see javadocs) so safe to cast to List<?>
List<?> keyList = (List<?>) key;
@SuppressWarnings("argument.type.incompatible")
String keyString = Joiner.on(", ").join(keyList);
@SuppressWarnings("argument.type.incompatible")
CompositeData compositeData = tabularData.get(keyList.toArray());
// linked hash map used to preserve attribute ordering
List<MBeanDump.MBeanValueMapEntry> innerEntries = Lists.newArrayList();
for (String attributeName : attributeNames) {
innerEntries.add(MBeanDump.MBeanValueMapEntry.newBuilder()
.setKey(attributeName)
.setValue(getMBeanAttributeValue(compositeData.get(attributeName)))
.build());
}
outerEntries.add(MBeanDump.MBeanValueMapEntry.newBuilder()
.setKey(keyString)
.setValue(MBeanDump.MBeanValue.newBuilder()
.setMap(MBeanDump.MBeanValueMap.newBuilder()
.addAllEntry(innerEntries))
.build())
.build());
}
return MBeanDump.MBeanValue.newBuilder()
.setMap(MBeanDump.MBeanValueMap.newBuilder()
.addAllEntry(outerEntries))
.build();
}
@Test
public void jobInstances() throws Exception {
final TabularData instance = TabularData.class.cast(result("getJobInstances", "jmx", 0, 1));
assertEquals(1, instance.size());
final CompositeData cd = instance.get(new Object[]{"jmx", id});
assertEquals(id, cd.get("instanceId"));
assertEquals("jmx", cd.get("jobName"));
}
@Test
public void parameters() throws Exception {
final TabularData instance = TabularData.class.cast(result("getParameters", id));
assertEquals(1, instance.size());
final CompositeData cd = instance.get(List.class.cast(instance.keySet().iterator().next()).toArray());
assertEquals("foo", cd.get("key"));
assertEquals("bar", cd.get("value"));
}
@Test
public void jobInstance() throws Exception {
final TabularData instance = TabularData.class.cast(result("getJobInstance", id));
assertEquals(1, instance.size());
final CompositeData cd = instance.get(new Object[]{"jmx", id});
assertEquals(id, cd.get("instanceId"));
assertEquals("jmx", cd.get("jobName"));
}
@Test
public void jobExecutions() throws Exception {
final TabularData instance = TabularData.class.cast(result("getJobExecutions", id, "jmx"));
assertEquals(1, instance.size());
final CompositeData cd = instance.get(List.class.cast(instance.keySet().iterator().next()).toArray());
assertEquals(id, cd.get("executionId"));
assertEquals("jmx", cd.get("jobName"));
assertEquals("COMPLETED", cd.get("Exit status"));
assertEquals("COMPLETED", cd.get("Batch status"));
}