Search in sources :

Example 6 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class ConcurrencyChaosMonkeyTest method chaosMonkeyTestManyThreads.

// many threads, one context
@Test
public void chaosMonkeyTestManyThreads() throws Exception {
    long startTime = System.nanoTime();
    URI mappingURI = generateMappingURI();
    Status twitterStatus = generateTwitterStatus();
    AtlasContext context = atlasContextFactory.createContext(mappingURI);
    for (int i = 0; i < 256; i++) {
        Thread chaosMonkeyThread = new Thread("ChaosMonkeyThread-" + i) {

            public void run() {
                LOG.info(this.getName() + " starting.");
                for (int j = 0; j < 100000; j++) {
                    try {
                        AtlasSession session = context.createSession();
                        session.setDefaultSourceDocument(twitterStatus);
                        context.process(session);
                        Random rand = new Random(System.currentTimeMillis() % 13);
                        int randSleep;
                        randSleep = rand.nextInt(20000);
                        Thread.sleep(randSleep);
                        context.process(session);
                        Thread.sleep(randSleep);
                    } catch (Throwable e) {
                        LOG.error("ERROR", e);
                    }
                }
                LOG.info(this.getName() + " thread completed.");
            }
        };
        chaosMonkeyThread.start();
    }
    Thread.sleep(600000L);
    long difference = System.nanoTime() - startTime;
    LOG.info(String.format("Total time: %d minutes to process 100000 mappings with one context shared with 256 threads", TimeUnit.NANOSECONDS.toMinutes(difference)));
}
Also used : Status(twitter4j.Status) Random(java.util.Random) AtlasContext(io.atlasmap.api.AtlasContext) URI(java.net.URI) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test)

Example 7 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class ConcurrencyChaosMonkeyTest method chaosMonkeyTestManyContexts.

// one thread, many contexts
@Test
public void chaosMonkeyTestManyContexts() throws Exception {
    long startTime = System.nanoTime();
    URI mappingURI = generateMappingURI();
    Status twitterStatus = generateTwitterStatus();
    for (int i = 0; i < 256; i++) {
        Thread chaosMonkeyThread = new Thread("ChaosMonkeyThread-" + i) {

            public void run() {
                LOG.info(this.getName() + " starting.");
                for (int j = 0; j < 100000; j++) {
                    try {
                        AtlasContext context = atlasContextFactory.createContext(mappingURI);
                        AtlasSession session = context.createSession();
                        session.setDefaultSourceDocument(twitterStatus);
                        context.process(session);
                        Random rand = new Random(System.currentTimeMillis() % 13);
                        int randSleep;
                        randSleep = rand.nextInt(20000);
                        Thread.sleep(randSleep);
                        context.process(session);
                        Thread.sleep(randSleep);
                    } catch (Throwable e) {
                        LOG.error("ERROR", e);
                    }
                }
                LOG.info(this.getName() + " thread completed.");
            }
        };
        chaosMonkeyThread.start();
    }
    Thread.sleep(600000L);
    long difference = System.nanoTime() - startTime;
    LOG.info(String.format("Total time: %d minutes to process 100000 mappings with one context per execution", TimeUnit.NANOSECONDS.toMinutes(difference)));
}
Also used : Status(twitter4j.Status) Random(java.util.Random) AtlasContext(io.atlasmap.api.AtlasContext) URI(java.net.URI) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test)

Example 8 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class DefaultAtlasContextTest method testProcessAtlasExceptionOtherContext.

@Test(expected = AtlasException.class)
public void testProcessAtlasExceptionOtherContext() throws AtlasException {
    AtlasSession session = new DefaultAtlasSession(mapping);
    session.setAtlasContext(new DefaultAtlasContext(DefaultAtlasContextFactory.getInstance(), mapping));
    context.process(session);
}
Also used : AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test)

Example 9 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class DefaultAtlasContextTest method testProcessValidationAtlasException.

@Test(expected = AtlasException.class)
public void testProcessValidationAtlasException() throws AtlasException {
    File file = Paths.get("src" + File.separator + "test" + File.separator + "resources" + File.separator + "atlasmapping.xml").toFile();
    DefaultAtlasContextFactory factory = new DefaultAtlasContextFactory();
    factory.init();
    DefaultAtlasContext context = new DefaultAtlasContext(factory, file.toURI());
    context.init();
    AtlasSession mockAtlasSession = mock(AtlasSession.class);
    context.processValidation(mockAtlasSession);
}
Also used : File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test)

Example 10 with AtlasSession

use of io.atlasmap.api.AtlasSession in project atlasmap by atlasmap.

the class JavaJavaFlatMappingTest method testProcessJavaJavaFlatFieldMappingPrimitivesBoxedValues.

@Test
public void testProcessJavaJavaFlatFieldMappingPrimitivesBoxedValues() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-flatprimitive.xml").toURI());
    AtlasSession session = context.createSession();
    BaseFlatPrimitiveClass sourceClass = generateFlatPrimitiveClassPrimitiveFieldsBoxedValues(SourceFlatPrimitiveClass.class);
    session.setDefaultSourceDocument(sourceClass);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertTrue(object instanceof TargetFlatPrimitiveClass);
    validateFlatPrimitiveClassPrimitiveFields((TargetFlatPrimitiveClass) object);
    Validations validations = session.getValidations();
    for (Validation v : validations.getValidation()) {
        printValidation(v);
    }
}
Also used : Validation(io.atlasmap.v2.Validation) Validations(io.atlasmap.v2.Validations) TargetFlatPrimitiveClass(io.atlasmap.java.test.TargetFlatPrimitiveClass) AtlasContext(io.atlasmap.api.AtlasContext) BaseFlatPrimitiveClass(io.atlasmap.java.test.BaseFlatPrimitiveClass) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest) Test(org.junit.Test)

Aggregations

AtlasSession (io.atlasmap.api.AtlasSession)157 AtlasContext (io.atlasmap.api.AtlasContext)140 Test (org.junit.Test)134 File (java.io.File)129 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)123 TargetContact (io.atlasmap.java.test.TargetContact)31 BaseContact (io.atlasmap.java.test.BaseContact)26 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)25 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)24 TargetFlatPrimitive (io.atlasmap.json.test.TargetFlatPrimitive)13 BaseOrder (io.atlasmap.java.test.BaseOrder)12 TargetOrder (io.atlasmap.java.test.TargetOrder)11 TargetTestClass (io.atlasmap.java.test.TargetTestClass)11 AtlasMapping (io.atlasmap.v2.AtlasMapping)9 XmlContactAttribute (io.atlasmap.xml.test.v2.XmlContactAttribute)9 AtlasJsonTestRootedMapper (io.atlasmap.json.test.AtlasJsonTestRootedMapper)8 BaseFlatPrimitiveClass (io.atlasmap.java.test.BaseFlatPrimitiveClass)7 SourceFlatPrimitiveClass (io.atlasmap.java.test.SourceFlatPrimitiveClass)7 URL (java.net.URL)4 Message (org.apache.camel.Message)4