Search in sources :

Example 11 with ReleaseIdImpl

use of org.drools.compiler.kproject.ReleaseIdImpl in project drools by kiegroup.

the class KieModuleRepoTest method removeStoreArtifactMapTest.

// remove request followed by a store request on a high load system
// * remove does not completely finish before store starts
@Test(timeout = 5000)
public void removeStoreArtifactMapTest() throws Exception {
    // actual test
    final ReleaseIdImpl releaseId = new ReleaseIdImpl("org", "redeploy", "2.0");
    final InternalKieModule originalKieModule = mock(InternalKieModule.class);
    when(originalKieModule.getReleaseId()).thenReturn(releaseId);
    when(originalKieModule.getCreationTimestamp()).thenReturn(0l);
    final InternalKieModule redeployKieModule = mock(InternalKieModule.class);
    when(redeployKieModule.getReleaseId()).thenReturn(releaseId);
    when(redeployKieModule.getCreationTimestamp()).thenReturn(1l);
    // 1. initial deploy ("long ago")
    kieModuleRepo.store(originalKieModule);
    final CyclicBarrier storeRemoveOperationBarrier = new CyclicBarrier(2);
    final CyclicBarrier operationsSerializationBarrier = new CyclicBarrier(2);
    final CyclicBarrier threadsFinishedBarrier = new CyclicBarrier(3);
    final Runnable removeRunnable = () -> {
        waitFor(storeRemoveOperationBarrier);
        kieModuleRepo.remove(releaseId);
        waitFor(operationsSerializationBarrier);
        waitFor(threadsFinishedBarrier);
    };
    final Runnable redeployRunnable = () -> {
        waitFor(storeRemoveOperationBarrier);
        waitFor(operationsSerializationBarrier);
        kieModuleRepo.store(redeployKieModule);
        waitFor(threadsFinishedBarrier);
    };
    final ExecutorService executor = Executors.newFixedThreadPool(2);
    // 2. remove and redploy
    executor.submit(removeRunnable);
    executor.submit(redeployRunnable);
    try {
        waitFor(threadsFinishedBarrier);
    } finally {
        executor.shutdownNow();
    }
    final String ga = releaseId.getGroupId() + ":" + releaseId.getArtifactId();
    final Map<ComparableVersion, KieModule> artifactMap = kieModuleRepo.kieModules.get(ga);
    assertNotNull("Artifact Map for GA '" + ga + "' not in KieModuleRepo!", artifactMap);
    // never gets this far, but this is a good check
    final KieModule redeployedKieModule = artifactMap.get(new ComparableVersion(releaseId.getVersion()));
    assertNotNull("Redeployed module has disappeared from KieModuleRepo!", redeployedKieModule);
    assertEquals("Original module retrieved instead of redeployed module!", 1l, redeployKieModule.getCreationTimestamp());
}
Also used : ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) ExecutorService(java.util.concurrent.ExecutorService) ComparableVersion(org.kie.api.builder.ReleaseIdComparator.ComparableVersion) KieModule(org.kie.api.builder.KieModule) CyclicBarrier(java.util.concurrent.CyclicBarrier) Test(org.junit.Test)

Example 12 with ReleaseIdImpl

use of org.drools.compiler.kproject.ReleaseIdImpl in project drools by kiegroup.

the class KieModuleDeploymentHelperImpl method createKieJarAndDeployToMaven.

@Override
public void createKieJarAndDeployToMaven(String groupId, String artifactId, String version, String kbaseName, String ksessionName, List<String> resourceFilePaths, List<Class<?>> classesForKjar, List<String> dependencies) {
    ReleaseId releaseId = new ReleaseIdImpl(groupId, artifactId, version);
    internalCreateAndDeployKjarToMaven(releaseId, kbaseName, ksessionName, resourceFilePaths, classesForKjar, dependencies);
}
Also used : ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) ReleaseId(org.kie.api.builder.ReleaseId)

Example 13 with ReleaseIdImpl

use of org.drools.compiler.kproject.ReleaseIdImpl in project drools by kiegroup.

the class KieRepositoryScannerImpl method buildArtifact.

private InternalKieModule buildArtifact(Artifact artifact, ArtifactResolver resolver) {
    DependencyDescriptor dependencyDescriptor = new DependencyDescriptor(artifact);
    ReleaseId releaseId = adapt(dependencyDescriptor.getReleaseId());
    if (releaseId.isSnapshot()) {
        ((ReleaseIdImpl) releaseId).setSnapshotVersion(artifact.getVersion());
    }
    InternalKieModule kieModule = createKieModule(releaseId, artifact.getFile());
    if (kieModule != null) {
        addDependencies(kieModule, resolver, resolver.getArtifactDependecies(dependencyDescriptor.toString()));
        kieModule.build();
    }
    return kieModule;
}
Also used : ReleaseIdImpl(org.drools.compiler.kproject.ReleaseIdImpl) DependencyDescriptor(org.appformer.maven.integration.DependencyDescriptor) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Aggregations

ReleaseIdImpl (org.drools.compiler.kproject.ReleaseIdImpl)13 ReleaseId (org.kie.api.builder.ReleaseId)9 Test (org.junit.Test)8 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)3 KieServices (org.kie.api.KieServices)3 KieModule (org.kie.api.builder.KieModule)3 KieContainer (org.kie.api.runtime.KieContainer)3 CyclicBarrier (java.util.concurrent.CyclicBarrier)2 ExecutorService (java.util.concurrent.ExecutorService)2 KieBuilder (org.kie.api.builder.KieBuilder)2 KieFileSystem (org.kie.api.builder.KieFileSystem)2 ComparableVersion (org.kie.api.builder.ReleaseIdComparator.ComparableVersion)2 AfterMatchFiredEvent (org.kie.api.event.rule.AfterMatchFiredEvent)2 AgendaEventListener (org.kie.api.event.rule.AgendaEventListener)2 KieSession (org.kie.api.runtime.KieSession)2 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 DependencyDescriptor (org.appformer.maven.integration.DependencyDescriptor)1