use of org.testng.annotations.Factory in project pulsar by yahoo.
the class ManagedCursorTest method testOutOfOrderDeletePersistenceWithClose.
@Test(timeOut = 20000)
public void testOutOfOrderDeletePersistenceWithClose() throws Exception {
ManagedLedger ledger = factory.open("my_test_ledger", new ManagedLedgerConfig());
ManagedCursor c1 = ledger.openCursor("c1");
List<Position> addedPositions = new ArrayList<>();
for (int i = 0; i < 20; i++) {
Position p = ledger.addEntry(("dummy-entry-" + i).getBytes(Encoding));
addedPositions.add(p);
}
// Acknowledge few messages leaving holes
c1.delete(addedPositions.get(2));
c1.delete(addedPositions.get(5));
c1.delete(addedPositions.get(7));
c1.delete(addedPositions.get(8));
c1.delete(addedPositions.get(9));
assertEquals(c1.getNumberOfEntriesInBacklog(), 20 - 5);
ledger.close();
factory.shutdown();
// Re-Open
factory = new ManagedLedgerFactoryImpl(bkc, bkc.getZkHandle());
ledger = factory.open("my_test_ledger", new ManagedLedgerConfig());
c1 = ledger.openCursor("c1");
assertEquals(c1.getNumberOfEntriesInBacklog(), 20 - 5);
List<Entry> entries = c1.readEntries(20);
assertEquals(entries.size(), 20 - 5);
List<String> entriesStr = entries.stream().map(e -> new String(e.getDataAndRelease(), Encoding)).collect(Collectors.toList());
assertEquals(entriesStr.get(0), "dummy-entry-0");
assertEquals(entriesStr.get(1), "dummy-entry-1");
// Entry-2 was deleted
assertEquals(entriesStr.get(2), "dummy-entry-3");
assertEquals(entriesStr.get(3), "dummy-entry-4");
// Entry-6 was deleted
assertEquals(entriesStr.get(4), "dummy-entry-6");
assertFalse(c1.hasMoreEntries());
}
use of org.testng.annotations.Factory in project dukescript-presenters by dukescript.
the class GtkKnockoutTest method compatibilityTests.
@Factory
public static Object[] compatibilityTests() throws Exception {
Class[] arr = testClasses();
for (int i = 0; i < arr.length; i++) {
assertEquals(arr[i].getClassLoader(), GtkKnockoutTest.class.getClassLoader(), "All classes loaded by the same classloader");
}
URI uri = DynamicHTTP.initServer();
final BrowserBuilder bb = BrowserBuilder.newBrowser(new WebKitPresenter(true)).loadClass(GtkKnockoutTest.class).loadPage(uri.toString()).invoke("initialized");
Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
bb.showAndWait();
}
});
ClassLoader l = getClassLoader();
List<Object> res = new ArrayList<>();
for (Class oldC : arr) {
Class<?> c = Class.forName(oldC.getName(), true, l);
seekKOTests(c, res);
}
return res.toArray();
}
use of org.testng.annotations.Factory in project dukescript-presenters by dukescript.
the class KoBrowserTest method compatibilityTests.
@Factory
public static Object[] compatibilityTests() throws Exception {
Browser.LOG.setLevel(Level.FINE);
Browser.LOG.addHandler(new ConsoleHandler());
final BrowserBuilder bb = BrowserBuilder.newBrowser(new Browser("KoBrowserTest")).loadClass(KoBrowserTest.class).loadPage("empty.html").invoke("initialized");
Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
bb.showAndWait();
}
});
List<Object> res = new ArrayList<Object>();
Class<? extends Annotation> test = loadClass().getClassLoader().loadClass(KOTest.class.getName()).asSubclass(Annotation.class);
Class[] arr = (Class[]) loadClass().getDeclaredMethod("tests").invoke(null);
final HttpServer s = Browser.findServer(browserPresenter);
ServerConfiguration conf = s.getServerConfiguration();
conf.addHttpHandler(new DynamicHTTP(s), "/dynamic");
for (Class c : arr) {
for (Method m : c.getMethods()) {
if (m.getAnnotation(test) != null) {
res.add(new KOScript(browserPresenter, m));
}
}
}
return res.toArray();
}
use of org.testng.annotations.Factory in project dukescript-presenters by dukescript.
the class BrowserTest method compatibilityTests.
@Factory
public static Object[] compatibilityTests() throws Exception {
final BrowserBuilder bb = BrowserBuilder.newBrowser(new Browser("BrowserTest")).loadClass(BrowserTest.class).loadPage("empty.html").invoke("initialized");
Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
bb.showAndWait();
}
});
List<Object> res = new ArrayList<Object>();
Class<? extends Annotation> test = loadClass().getClassLoader().loadClass(KOTest.class.getName()).asSubclass(Annotation.class);
Class[] arr = (Class[]) loadClass().getDeclaredMethod("tests").invoke(null);
for (Class c : arr) {
for (Method m : c.getMethods()) {
if (m.getAnnotation(test) != null) {
res.add(new KOScript(browserPresenter, m));
}
}
}
return res.toArray();
}
use of org.testng.annotations.Factory in project bioformats by openmicroscopy.
the class FormatWriterTestFactory method createInstances.
// -- TestNG factory methods --
@Factory
public Object[] createInstances() {
List files = new ArrayList();
// parse explicit filename, if any
final String nameProp = "testng.filename";
String filename = System.getProperty(nameProp);
if (filename != null && filename.equals("${" + nameProp + "}")) {
filename = null;
}
if (filename != null && !new File(filename).exists()) {
LOGGER.error("Invalid filename: {}", filename);
return new Object[0];
}
String baseDir = null;
if (filename == null) {
// parse base directory
final String baseDirProp = "testng.directory";
baseDir = System.getProperty(baseDirProp);
if (!new File(baseDir).isDirectory()) {
if (baseDir == null || baseDir.equals("${" + baseDirProp + "}")) {
LOGGER.error("No base directory specified.");
} else
LOGGER.error("Invalid base directory: {}", baseDir);
LOGGER.error("Please specify a directory containing files to test:");
LOGGER.error(" ant -D{}=\"/path/to/data\" test-all", baseDirProp);
return new Object[0];
}
FormatWriterTest.configTree = new ConfigurationTree(baseDir);
LOGGER.info("testng.directory = {}", baseDir);
}
// parse multiplier
final String multProp = "testng.multiplier";
String mult = System.getProperty(multProp);
float multiplier = 1;
if (mult != null && !mult.equals("${" + multProp + "}")) {
try {
multiplier = Float.parseFloat(mult);
} catch (NumberFormatException exc) {
LOGGER.warn("Invalid multiplier: {}", mult);
}
}
LOGGER.info("testng.multiplier = {}", multiplier);
final String toplevelConfigProp = "testng.toplevel-config";
String toplevelConfig = System.getProperty(toplevelConfigProp);
// detect maximum heap size
long maxMemory = Runtime.getRuntime().maxMemory() >> 20;
LOGGER.info("Maximum heap size = {} MB", maxMemory);
// display local information
LOGGER.info("user.language = {}", System.getProperty("user.language"));
LOGGER.info("user.country = {}", System.getProperty("user.country"));
if (filename == null) {
// scan for files
System.out.println("Scanning for files...");
long start = System.currentTimeMillis();
TestTools.getFiles(baseDir, files, FormatWriterTest.configTree, toplevelConfig);
long end = System.currentTimeMillis();
double time = (end - start) / 1000.0;
LOGGER.info(TestTools.DIVIDER);
LOGGER.info("Total files: {}", files.size());
long avg = end - start;
if (files.size() > 0)
avg /= files.size();
LOGGER.info("Scan time: {} s ({} ms/file)", time, avg);
LOGGER.info(TestTools.DIVIDER);
} else {
files.add(filename);
}
// create test class instances
System.out.println("Building list of tests...");
Object[] tests = new Object[files.size()];
for (int i = 0; i < tests.length; i++) {
String id = (String) files.get(i);
tests[i] = new FormatWriterTest(id);
}
if (tests.length == 1)
System.out.println("Ready to test " + files.get(0));
else
System.out.println("Ready to test " + tests.length + " files");
return tests;
}
Aggregations