Search in sources :

Example 1 with Factory

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());
}
Also used : ZNodeProtobufFormat(org.apache.bookkeeper.mledger.impl.MetaStoreImplZookeeper.ZNodeProtobufFormat) Arrays(java.util.Arrays) Assert.assertNull(org.testng.Assert.assertNull) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) MockedBookKeeperTestCase(org.apache.bookkeeper.test.MockedBookKeeperTestCase) Entry(org.apache.bookkeeper.mledger.Entry) LoggerFactory(org.slf4j.LoggerFactory) Assert.assertEquals(org.testng.Assert.assertEquals) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Callable(java.util.concurrent.Callable) Test(org.testng.annotations.Test) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Lists(com.google.common.collect.Lists) Charset(java.nio.charset.Charset) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Assert.assertFalse(org.testng.Assert.assertFalse) ExecutorService(java.util.concurrent.ExecutorService) Charsets(com.google.common.base.Charsets) Assert.assertNotEquals(org.testng.Assert.assertNotEquals) CyclicBarrier(java.util.concurrent.CyclicBarrier) Logger(org.slf4j.Logger) Factory(org.testng.annotations.Factory) Assert.fail(org.testng.Assert.fail) Set(java.util.Set) Position(org.apache.bookkeeper.mledger.Position) IndividualDeletedEntries(org.apache.bookkeeper.mledger.ManagedCursor.IndividualDeletedEntries) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) BKException(org.apache.bookkeeper.client.BKException) Sets(com.google.common.collect.Sets) AddEntryCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.AddEntryCallback) TimeUnit(java.util.concurrent.TimeUnit) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) MarkDeleteCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.MarkDeleteCallback) Assert.assertTrue(org.testng.Assert.assertTrue) Collections(java.util.Collections) ReadEntriesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ReadEntriesCallback) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) Position(org.apache.bookkeeper.mledger.Position) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ArrayList(java.util.ArrayList) ManagedCursor(org.apache.bookkeeper.mledger.ManagedCursor) Entry(org.apache.bookkeeper.mledger.Entry) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Test(org.testng.annotations.Test)

Example 2 with Factory

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();
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) BrowserBuilder(net.java.html.boot.BrowserBuilder) Factory(org.testng.annotations.Factory)

Example 3 with Factory

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();
}
Also used : ServerConfiguration(org.glassfish.grizzly.http.server.ServerConfiguration) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) ConsoleHandler(java.util.logging.ConsoleHandler) BrowserBuilder(net.java.html.boot.BrowserBuilder) HttpServer(org.glassfish.grizzly.http.server.HttpServer) Factory(org.testng.annotations.Factory)

Example 4 with Factory

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();
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) BrowserBuilder(net.java.html.boot.BrowserBuilder) Factory(org.testng.annotations.Factory)

Example 5 with Factory

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;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) File(java.io.File) Factory(org.testng.annotations.Factory) LoggerFactory(org.slf4j.LoggerFactory)

Aggregations

ArrayList (java.util.ArrayList)7 Factory (org.testng.annotations.Factory)7 BrowserBuilder (net.java.html.boot.BrowserBuilder)4 Method (java.lang.reflect.Method)3 LoggerFactory (org.slf4j.LoggerFactory)3 File (java.io.File)2 List (java.util.List)2 Charsets (com.google.common.base.Charsets)1 Lists (com.google.common.collect.Lists)1 Sets (com.google.common.collect.Sets)1 IOException (java.io.IOException)1 URI (java.net.URI)1 Charset (java.nio.charset.Charset)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 CountDownLatch (java.util.concurrent.CountDownLatch)1