Search in sources :

Example 6 with AtlasContext

use of io.atlasmap.api.AtlasContext 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 7 with AtlasContext

use of io.atlasmap.api.AtlasContext 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)

Example 8 with AtlasContext

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

the class JavaJavaMultiSourceTest method testProcessBasic.

@Test
public void testProcessBasic() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-multisource-basic.xml").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    BaseAddress sourceAddress = AtlasTestUtil.generateAddress(SourceAddress.class);
    session.setSourceDocument("con", sourceContact);
    session.setSourceDocument("addr", sourceAddress);
    context.process(session);
    assertFalse(printAudit(session), session.hasErrors());
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertEquals(TargetContact.class.getName(), object.getClass().getName());
    TargetContact targetContact = (TargetContact) object;
    assertEquals("Ozzie", targetContact.getFirstName());
    assertNull(targetContact.getLastName());
    assertNull(targetContact.getPhoneNumber());
    assertEquals("90210", targetContact.getZipCode());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) TargetContact(io.atlasmap.java.test.TargetContact) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) BaseAddress(io.atlasmap.java.test.BaseAddress) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 9 with AtlasContext

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

the class JavaJavaSeparateTest method testProcessSeparateSkip.

@Test
public void testProcessSeparateSkip() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-separate-skip.xml").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    sourceContact.setFirstName("Dr. Mr. Ozzie L. Smith Jr.");
    sourceContact.setLastName(null);
    session.setDefaultSourceDocument(sourceContact);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertEquals(TargetContact.class.getName(), object.getClass().getName());
    TargetContact targetContact = (TargetContact) object;
    AtlasTestUtil.validateContact(targetContact);
    assertFalse(session.hasErrors());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) TargetContact(io.atlasmap.java.test.TargetContact) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Example 10 with AtlasContext

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

the class JavaJavaSeparateTest method testProcessSeparateOutOfOrder.

@Test
public void testProcessSeparateOutOfOrder() throws Exception {
    AtlasContext context = atlasContextFactory.createContext(new File("src/test/resources/javaToJava/atlasmapping-separate-outoforder.xml").toURI());
    AtlasSession session = context.createSession();
    BaseContact sourceContact = AtlasTestUtil.generateContact(SourceContact.class);
    sourceContact.setFirstName("Dr. Mr. Ozzie L. Smith Jr.");
    sourceContact.setLastName(null);
    session.setDefaultSourceDocument(sourceContact);
    context.process(session);
    Object object = session.getDefaultTargetDocument();
    assertNotNull(object);
    assertEquals(TargetContact.class.getName(), object.getClass().getName());
    TargetContact targetContact = (TargetContact) object;
    AtlasTestUtil.validateContact(targetContact);
    assertFalse(session.hasErrors());
}
Also used : BaseContact(io.atlasmap.java.test.BaseContact) TargetContact(io.atlasmap.java.test.TargetContact) AtlasContext(io.atlasmap.api.AtlasContext) File(java.io.File) AtlasSession(io.atlasmap.api.AtlasSession) Test(org.junit.Test) AtlasMappingBaseTest(io.atlasmap.reference.AtlasMappingBaseTest)

Aggregations

AtlasContext (io.atlasmap.api.AtlasContext)138 AtlasSession (io.atlasmap.api.AtlasSession)138 File (java.io.File)128 Test (org.junit.Test)119 AtlasMappingBaseTest (io.atlasmap.reference.AtlasMappingBaseTest)111 BaseContact (io.atlasmap.java.test.BaseContact)25 AtlasJsonTestUnrootedMapper (io.atlasmap.json.test.AtlasJsonTestUnrootedMapper)25 TargetFlatPrimitiveClass (io.atlasmap.java.test.TargetFlatPrimitiveClass)24 TargetContact (io.atlasmap.java.test.TargetContact)19 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 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 AtlasMapping (io.atlasmap.v2.AtlasMapping)7 TargetOrder (io.atlasmap.json.test.TargetOrder)4 XmlFlatPrimitiveElement (io.atlasmap.xml.test.v2.XmlFlatPrimitiveElement)4