private Bench runBenchmark(Class<? extends Lookup> cls, int count) throws Exception { System.err.println("* Running " + count + " iterations for " + cls.getSimpleName() + " ..."); System.err.println(" - warm-up 10 iterations..."); for (int i = 0; i < 10; i++) { System.runFinalization(); System.gc(); Lookup lookup = cls.newInstance(); _benchmark(lookup, null, false, null); lookup = null; } Bench b = new Bench(); System.err.print(" - main iterations:"); System.err.flush(); for (int i = 0; i < count; i++) { System.runFinalization(); System.gc(); Lookup lookup = cls.newInstance(); _benchmark(lookup, null, false, b); lookup = null; if (i > 0 && (i % 10 == 0)) { System.err.print(" " + i); System.err.flush(); } } System.err.println(); return b; }
@Test public void acceptedCommandsCanBeSerializedTest() throws Exception { Field commandsField = JaxbCommandsRequest.class.getDeclaredField("commands"); XmlElements xmlElemsAnno = (XmlElements) commandsField.getAnnotations()[0]; XmlElement[] xmlElems = xmlElemsAnno.value(); Set<Class> cmdSet = new HashSet<Class>(AcceptedCommands.getSet()); assertEquals(cmdSet.size(), xmlElems.length); Set<String> xmlElemNameSet = new HashSet<String>(); for (XmlElement xmlElemAnno : xmlElems) { Class cmdClass = xmlElemAnno.type(); String name = xmlElemAnno.name(); assertTrue(name + " is used twice as a name.", xmlElemNameSet.add(name)); assertTrue( cmdClass.getSimpleName() + " is present in " + JaxbCommandsRequest.class.getSimpleName() + " but not in " + AcceptedCommands.class.getSimpleName(), cmdSet.remove(cmdClass)); } for (Class cmdClass : cmdSet) { System.out.println("Missing: " + cmdClass.getSimpleName()); } assertTrue( "See output for classes in " + AcceptedCommands.class.getSimpleName() + " that are not in " + JaxbCommandsRequest.class.getSimpleName(), cmdSet.size() == 0); }
private void getMergedAnnotationAttributesWithHalfConventionBasedAndHalfAliasedComposedAnnotation( Class<?> clazz) { String[] expected = asArray("explicitDeclaration"); String name = ContextConfig.class.getName(); String simpleName = clazz.getSimpleName(); AnnotationAttributes attributes = getMergedAnnotationAttributes(clazz, name); assertNotNull("Should find @ContextConfig on " + simpleName, attributes); assertArrayEquals( "locations for class [" + clazz.getSimpleName() + "]", expected, attributes.getStringArray("locations")); assertArrayEquals( "value for class [" + clazz.getSimpleName() + "]", expected, attributes.getStringArray("value")); // Verify contracts between utility methods: assertTrue(isAnnotated(clazz, name)); }
private void assertGetMergedAnnotation(Class<?> element, String... expected) { String name = ContextConfig.class.getName(); ContextConfig contextConfig = getMergedAnnotation(element, ContextConfig.class); assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), contextConfig); assertArrayEquals("locations", expected, contextConfig.locations()); assertArrayEquals("value", expected, contextConfig.value()); assertArrayEquals("classes", new Class<?>[0], contextConfig.classes()); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
@Test public void getMergedAnnotationAttributesWithAliasedValueComposedAnnotation() { Class<?> element = AliasedValueComposedContextConfigClass.class; String name = ContextConfig.class.getName(); AnnotationAttributes attributes = getMergedAnnotationAttributes(element, name); assertNotNull("Should find @ContextConfig on " + element.getSimpleName(), attributes); assertArrayEquals("locations", asArray("test.xml"), attributes.getStringArray("locations")); assertArrayEquals("value", asArray("test.xml"), attributes.getStringArray("value")); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
@Test public void getMergedAnnotationWithImplicitAliasesInMetaAnnotationOnComposedAnnotation() { Class<?> element = ComposedImplicitAliasesContextConfigClass.class; String name = ImplicitAliasesContextConfig.class.getName(); ImplicitAliasesContextConfig config = getMergedAnnotation(element, ImplicitAliasesContextConfig.class); String[] expected = asArray("A.xml", "B.xml"); assertNotNull( "Should find @ImplicitAliasesContextConfig on " + element.getSimpleName(), config); assertArrayEquals("groovyScripts", expected, config.groovyScripts()); assertArrayEquals("xmlFiles", expected, config.xmlFiles()); assertArrayEquals("locations", expected, config.locations()); assertArrayEquals("value", expected, config.value()); // Verify contracts between utility methods: assertTrue(isAnnotated(element, name)); }
public static Path getResultPath(Class clazz, String fileName) { return new Path(getResourcePath("results", clazz.getSimpleName()), fileName); }
@Test public void testInvalidClasses() { Set<String> exceptionMessages = new HashSet<String>(); for (Triplet<HBRecord, String, Class<? extends IllegalArgumentException>> p : invalidRecordsAndErrorMessages) { HBRecord record = p.getValue0(); Class recordClass = record.getClass(); assertFalse( "Object mapper couldn't detect invalidity of class " + recordClass.getName(), hbMapper.isValid(recordClass)); String errorMessage = p.getValue1() + " (" + recordClass.getName() + ") should have thrown an " + IllegalArgumentException.class.getName(); String exMsgObjToResult = null, exMsgObjToPut = null, exMsgResultToObj = null, exMsgPutToObj = null; try { hbMapper.writeValueAsResult(record); fail(errorMessage + " while converting bean to Result"); } catch (IllegalArgumentException ex) { assertEquals( "Mismatch in type of exception thrown for " + recordClass.getSimpleName(), p.getValue2(), ex.getClass()); exMsgObjToResult = ex.getMessage(); } try { hbMapper.writeValueAsPut(record); fail(errorMessage + " while converting bean to Put"); } catch (IllegalArgumentException ex) { assertEquals( "Mismatch in type of exception thrown for " + recordClass.getSimpleName(), p.getValue2(), ex.getClass()); exMsgObjToPut = ex.getMessage(); } try { hbMapper.readValue(someResult, recordClass); fail(errorMessage + " while converting Result to bean"); } catch (IllegalArgumentException ex) { assertEquals( "Mismatch in type of exception thrown for " + recordClass.getSimpleName(), p.getValue2(), ex.getClass()); exMsgResultToObj = ex.getMessage(); } try { hbMapper.readValue( new ImmutableBytesWritable(someResult.getRow()), someResult, recordClass); fail(errorMessage + " while converting Result to bean"); } catch (IllegalArgumentException ex) { assertEquals( "Mismatch in type of exception thrown for " + recordClass.getSimpleName(), p.getValue2(), ex.getClass()); } try { hbMapper.readValue(somePut, recordClass); fail(errorMessage + " while converting Put to bean"); } catch (IllegalArgumentException ex) { assertEquals( "Mismatch in type of exception thrown for " + recordClass.getSimpleName(), p.getValue2(), ex.getClass()); exMsgPutToObj = ex.getMessage(); } try { hbMapper.readValue(new ImmutableBytesWritable(somePut.getRow()), somePut, recordClass); fail(errorMessage + " while converting row key and Put combo to bean"); } catch (IllegalArgumentException ex) { assertEquals("Mismatch in type of exception thrown", p.getValue2(), ex.getClass()); } assertEquals( "Validation for 'conversion to Result' and 'conversion to Put' differ in code path", exMsgObjToResult, exMsgObjToPut); assertEquals( "Validation for 'conversion from Result' and 'conversion from Put' differ in code path", exMsgResultToObj, exMsgPutToObj); assertEquals( "Validation for 'conversion from bean' and 'conversion to bean' differ in code path", exMsgObjToResult, exMsgResultToObj); System.out.printf( "%s threw below Exception as expected:\n%s\n%n", p.getValue1(), exMsgObjToResult); if (!exceptionMessages.add(exMsgObjToPut)) { fail("Same error message for different invalid inputs"); } } }