use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.
the class MethodMapTest method test.
@Test
public void test() {
MethodMap<Integer> map = new MethodMap(0);
Assert.assertEquals(0, map.size());
Method m = new Method("org.apache.avro.Schema", "toString");
Assert.assertNull(map.get(m));
Assert.assertNull(map.get(null));
map.forEachEntry((a, b) -> true);
map.forEachKey((a) -> true);
map.forEachValue((a) -> true);
Assert.assertTrue(map.entrySet().isEmpty());
Assert.assertTrue(map.values().isEmpty());
Assert.assertTrue(map.keySet().isEmpty());
Method m2 = new Method("org.apache.avro.Schema", "toString2");
map.put(m2, Integer.MIN_VALUE);
map.put(m, Integer.MAX_VALUE);
Assert.assertEquals(2, map.size());
Assert.assertEquals((Integer) Integer.MIN_VALUE, map.get(m2));
Assert.assertEquals((Integer) Integer.MAX_VALUE, map.get(m));
}
use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.
the class MethodMapTest method test2.
@Test
public void test2() {
MethodMap<Integer> map = new MethodMap(0);
Assert.assertEquals(0, map.capacity());
Method m1 = new Method("x", "m1");
map.put(m1, 0);
Assert.assertEquals(3, map.capacity());
Assert.assertEquals(1, map._size);
map.put(m1, 1);
Assert.assertEquals(3, map.capacity());
Assert.assertEquals(1, map._size);
Assert.assertEquals(2, map._maxSize);
Method m2 = new Method("x", "m2");
map.put(m2, 2);
Assert.assertEquals(3, map.capacity());
Assert.assertEquals(2, map._size);
Assert.assertEquals(2, map._maxSize);
Method m3 = new Method("x", "m3");
map.put(m3, 3);
Assert.assertEquals(7, map.capacity());
Assert.assertEquals(3, map._size);
Assert.assertEquals(4, map._maxSize);
Assert.assertEquals((Integer) 1, map.get(m1));
Assert.assertEquals((Integer) 2, map.get(m2));
Assert.assertEquals((Integer) 3, map.get(m3));
Method ym3 = new Method("y", "m3");
Assert.assertNull(map.get(ym3));
map.put(ym3, 13);
Assert.assertEquals((Integer) 13, map.get(ym3));
List<Integer> values = new ArrayList<>();
map.forEachEntry((k, v) -> {
values.add(v);
return true;
});
Assert.assertEquals(4, values.size());
}
use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.
the class MethodsTest method testSomeMethod.
@Test
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
public void testSomeMethod() {
Method m1 = Methods.getMethod("a", "b");
Method m2 = Methods.getMethod("a", "b");
Assert.assertSame(m1, m2);
Assert.assertEquals(m2, m1);
Assert.assertEquals("a", m1.getDeclaringClass());
Assert.assertEquals("b", m1.getName());
Assert.assertEquals(m1, Methods.from(Methods.toString(m1)));
}
use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.
the class SampleNodeTest method testSampleNode.
@Test
@SuppressFBWarnings("PRMC_POSSIBLY_REDUNDANT_METHOD_CALLS")
public void testSampleNode() throws IOException {
LOG.debug("sample");
StackTraceElement[] st1 = newSt1();
SampleNode node1 = SampleNode.createSampleNode(st1);
LOG.debug("Node 1", node1);
Assert.assertEquals(4, node1.getNrNodes());
StackTraceElement[] st2 = newSt2();
SampleNode.addToSampleNode(node1, st2);
LOG.debug("Node 1", node1);
Assert.assertEquals(5, node1.getNrNodes());
StackTraceElement[] st3 = newSt3();
SampleNode.addToSampleNode(node1, st3);
LOG.debug("Node 1", node1);
StackTraceElement[] st4 = newSt4();
SampleNode.addToSampleNode(node1, st4);
SampleNode.addToSampleNode(node1, st1);
LOG.debug("Node 1", node1);
SampleNode agg = SampleNode.aggregate(node1, node1);
LOG.debug("n1 + n2", agg);
Assert.assertEquals(node1.getSampleCount() * 2, agg.getSampleCount());
final Method method = Methods.getMethod("C1", "m3");
Assert.assertEquals(node1.getSubNodes().get(method).getSampleCount() * 2, agg.getSubNodes().get(method).getSampleCount());
StringBuilder sb = new StringBuilder();
node1.writeTo(sb);
LOG.debug("Serialized String", sb);
SampleNode into = new SampleNode();
SampleNode.parseInto(new StringReader(sb.toString()), into);
Pair<Method, SampleNode> parsed = SampleNode.parse(new StringReader(sb.toString()));
Assert.assertEquals(node1, parsed.getSecond());
Assert.assertEquals(node1, Objects.clone(node1));
Assert.assertEquals(node1, into);
SampleNode node1Clone = SampleNode.clone(node1);
Assert.assertEquals(node1, node1Clone);
node1Clone.addToCount(5);
Assert.assertNotEquals(node1, node1Clone);
StringBuilder sb2 = new StringBuilder();
node1.writeD3JsonTo(sb2);
LOG.debug("Serialized D3 String", sb2);
Pair<Method, SampleNode> parsed2 = SampleNode.parseD3Json(new StringReader(sb2.toString()));
Assert.assertEquals(node1, parsed2.getSecond());
SampleNode.traverse(parsed.getFirst(), parsed.getSecond(), (f, t, s) -> {
LOG.debug("{} -> {} sampled {} times", f, t, s);
return true;
});
}
use of org.spf4j.base.avro.Method in project spf4j by zolyfarkas.
the class SLF4JBridgeHandler method callLocationAwareLogger.
private static void callLocationAwareLogger(final LocationAwareLogger lal, final LogRecord record) {
int julLevelValue = record.getLevel().intValue();
int slf4jLevel;
if (julLevelValue <= TRACE_LEVEL_THRESHOLD) {
if (!lal.isTraceEnabled()) {
return;
}
slf4jLevel = LocationAwareLogger.TRACE_INT;
} else if (julLevelValue <= DEBUG_LEVEL_THRESHOLD) {
if (!lal.isDebugEnabled()) {
return;
}
slf4jLevel = LocationAwareLogger.DEBUG_INT;
} else if (julLevelValue <= INFO_LEVEL_THRESHOLD) {
if (!lal.isInfoEnabled()) {
return;
}
slf4jLevel = LocationAwareLogger.INFO_INT;
} else if (julLevelValue <= WARN_LEVEL_THRESHOLD) {
if (!lal.isWarnEnabled()) {
return;
}
slf4jLevel = LocationAwareLogger.WARN_INT;
} else {
if (!lal.isErrorEnabled()) {
return;
}
slf4jLevel = LocationAwareLogger.ERROR_INT;
}
Pair<String, Object[]> messageArgs = getMessageI18N(record);
Method m = getSourceMethodInfo(record);
if (m != null) {
lal.log(null, m.toString(), slf4jLevel, messageArgs.getFirst(), messageArgs.getSecond(), record.getThrown());
} else {
lal.log(null, FQCN, slf4jLevel, messageArgs.getFirst(), messageArgs.getSecond(), record.getThrown());
}
}
Aggregations