Search in sources :

Example 51 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class DslExpansionTest method testDSLExpansion_MessageImplNPE.

@Test
public void testDSLExpansion_MessageImplNPE() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId releaseId = ks.newReleaseId("org.kie", "dsl-test", "1.0-SNAPSHOT");
    final KieModuleModel kproj = ks.newKieModuleModel();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(kproj.toXML()).writePomXML(generatePomXml(releaseId)).write("src/main/resources/KBase1/test-dsl.dsl", createDSL()).write("src/main/resources/KBase1/test-rule.dslr", createDRL());
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    final List<Message> messages = kieBuilder.buildAll().getResults().getMessages();
    if (!messages.isEmpty()) {
        for (final Message m : messages) {
            System.out.println(m.getText());
        }
    }
    assertTrue(messages.isEmpty());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 52 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class WireChannelTest method testWireChannel.

@Test
public void testWireChannel() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "listener-test", "1.0-SNAPSHOT");
    build(ks, releaseId);
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieSession ksession = kieContainer.newKieSession();
    ksession.fireAllRules();
    assertEquals(1, channelMessages.size());
    assertEquals("Test Message", channelMessages.get(0));
}
Also used : KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 53 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class KieModuleRepoTest method newerVersionDeployOverwritesTest.

// 2. simultaneous deploy requests
// - multitenant UI
// - duplicate REST requests
@Test(timeout = 5000)
public void newerVersionDeployOverwritesTest() throws Exception {
    // setup
    final ReleaseIdImpl releaseId = new ReleaseIdImpl("org", "deployTwiceAfterUpdateDependency", "1.0-SNAPSHOT");
    final InternalKieModule originalOldKieModule = new InternalKieModuleStub();
    final ReleaseId dependentReleaseid = new ReleaseIdImpl("org", "deployTwiceAfterUpdate", "1.0-SNAPSHOT");
    final KieContainerImpl kieContainer = createMockKieContainer(dependentReleaseid, kieModuleRepo);
    // 1. deploy
    kieModuleRepo.store(originalOldKieModule);
    // 2. another project is dependent on this project
    kieContainer.updateDependencyToVersion(releaseId, releaseId);
    final InternalKieModule newKieModule = mock(InternalKieModule.class);
    when(newKieModule.getReleaseId()).thenReturn(releaseId);
    when(newKieModule.getCreationTimestamp()).thenReturn(10l);
    final CyclicBarrier storeOperationBarrier = new CyclicBarrier(2);
    final CyclicBarrier storeSerializationBarrier = new CyclicBarrier(2);
    final CyclicBarrier threadsFinishedBarrier = new CyclicBarrier(3);
    final Runnable deployRunnable = () -> {
        waitFor(storeOperationBarrier);
        // Second thread waits with store until the first one finishes with it.
        if (Thread.currentThread().getName().equals("two")) {
            waitFor(storeSerializationBarrier);
        }
        kieModuleRepo.store(newKieModule);
        if (Thread.currentThread().getName().equals("one")) {
            waitFor(storeSerializationBarrier);
        }
        waitFor(threadsFinishedBarrier);
    };
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    // 2. remove and redploy
    final Thread deployThread = new Thread(deployRunnable);
    deployThread.setName("one");
    executor.submit(deployThread);
    final Thread secondDeployThread = new Thread(deployRunnable);
    secondDeployThread.setName("two");
    executor.submit(secondDeployThread);
    try {
        waitFor(threadsFinishedBarrier);
    } finally {
        executor.shutdownNow();
    }
    // never gets this far, but this is a good check
    final KieModule oldKieModule = kieModuleRepo.oldKieModules.get(releaseId);
    final long oldKieModuleTimeStamp = ((InternalKieModule) oldKieModule).getCreationTimestamp();
    final long originalKieModuleTimestamp = originalOldKieModule.getCreationTimestamp();
    assertEquals("The old kie module in the repo is not the originally deployed module!", originalKieModuleTimestamp, oldKieModuleTimeStamp);
}
Also used : ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) ExecutorService(java.util.concurrent.ExecutorService) ReleaseId(org.kie.api.builder.ReleaseId) KieModule(org.kie.api.builder.KieModule) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 54 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class ReleaseIdTest method testDecendingSort.

@Test
public void testDecendingSort() {
    List<ReleaseId> list = newUnsortedList();
    list.sort(new ReleaseIdComparator(DESCENDING));
    assertSame(gav7, list.get(0));
    assertSame(gav6, list.get(1));
    assertSame(gav5, list.get(2));
    assertSame(gav4, list.get(3));
    assertSame(gav3, list.get(4));
    assertSame(gav2, list.get(5));
    assertSame(gav1, list.get(6));
    assertSame(gav0, list.get(7));
}
Also used : ReleaseId(org.kie.api.builder.ReleaseId) ReleaseIdComparator(org.kie.api.builder.ReleaseIdComparator) Test(org.junit.Test)

Example 55 with ReleaseId

use of org.kie.api.builder.ReleaseId in project drools by kiegroup.

the class ReleaseIdTest method testAscendingSort.

@Test
public void testAscendingSort() {
    List<ReleaseId> list = newUnsortedList();
    list.sort(new ReleaseIdComparator(ASCENDING));
    assertSame(gav0, list.get(0));
    assertSame(gav1, list.get(1));
    assertSame(gav2, list.get(2));
    assertSame(gav3, list.get(3));
    assertSame(gav4, list.get(4));
    assertSame(gav5, list.get(5));
    assertSame(gav6, list.get(6));
    assertSame(gav7, list.get(7));
}
Also used : ReleaseId(org.kie.api.builder.ReleaseId) ReleaseIdComparator(org.kie.api.builder.ReleaseIdComparator) Test(org.junit.Test)

Aggregations

ReleaseId (org.kie.api.builder.ReleaseId)273 Test (org.junit.Test)219 KieServices (org.kie.api.KieServices)214 KieContainer (org.kie.api.runtime.KieContainer)176 KieSession (org.kie.api.runtime.KieSession)137 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)117 KieModule (org.kie.api.builder.KieModule)84 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)73 KieFileSystem (org.kie.api.builder.KieFileSystem)64 KieModuleModel (org.kie.api.builder.model.KieModuleModel)40 KieBuilder (org.kie.api.builder.KieBuilder)34 ArrayList (java.util.ArrayList)32 Message (org.drools.compiler.Message)32 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)27 Resource (org.kie.api.io.Resource)23 Results (org.kie.api.builder.Results)20 KieBaseModel (org.kie.api.builder.model.KieBaseModel)20 InternalKieScanner (org.drools.compiler.kie.builder.impl.InternalKieScanner)18 KieScanner (org.kie.api.builder.KieScanner)18 IncrementalResults (org.kie.internal.builder.IncrementalResults)18