use of org.kie.util.maven.support.ReleaseIdImpl 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");
final InternalKieModule originalOldKieModule = new InternalKieModuleStub();
final ReleaseId dependentReleaseid = new ReleaseIdImpl("org", "deployTwiceAfterUpdate", "1.0");
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);
try {
// 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);
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);
}
use of org.kie.util.maven.support.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) {
ReleaseId releaseId = new ReleaseIdImpl(groupId, artifactId, version);
internalCreateAndDeployKjarToMaven(releaseId, kbaseName, ksessionName, resourceFilePaths, null, null);
}
use of org.kie.util.maven.support.ReleaseIdImpl in project drools by kiegroup.
the class KieModuleDeploymentHelperImpl method internalCreateKieJar.
/**
* Create a KJar for deployment;
*
* @param releaseId Release (deployment) id.
* @param resourceFilePaths List of resource file paths
* @param kbaseName The name of the {@link KieBase}
* @param ksessionName The name of the {@link KieSession}.
* @param dependencies List of dependencies to add
*
* @return The {@link InternalKieModule} which represents the KJar.
*/
private synchronized KieModule internalCreateKieJar(ReleaseId releaseId, String kbaseName, String ksessionName, List<String> resourceFilePaths, List<Class<?>> classes, List<String> dependencies) {
ReleaseId[] releaseIds = {};
if (dependencies != null && dependencies.size() > 0) {
List<ReleaseId> depReleaseIds = new ArrayList<>();
for (String dep : dependencies) {
String[] gav = dep.split(":");
if (gav.length != 3) {
throw new IllegalArgumentException("Dependendency id '" + dep + "' does not conform to the format <groupId>:<artifactId>:<version> (Classifiers are not accepted).");
}
depReleaseIds.add(new ReleaseIdImpl(gav[0], gav[1], gav[2]));
}
releaseIds = depReleaseIds.toArray(new ReleaseId[depReleaseIds.size()]);
}
config.pomText = getPomText(releaseId, releaseIds);
KieFileSystem kfs = createKieFileSystemWithKProject();
kfs.writePomXML(this.config.pomText);
List<KJarResource> resourceFiles = loadResources(resourceFilePaths);
for (KJarResource resource : resourceFiles) {
kfs.write("src/main/resources/" + kbaseName + "/" + resource.name, resource.content);
}
if (classes != null) {
for (Class<?> userClass : classes) {
addClass(userClass, kfs);
}
}
KieBuilder kieBuilder = config.getKieServicesInstance().newKieBuilder(kfs);
int buildMsgs = 0;
for (Message buildMsg : kieBuilder.buildAll().getResults().getMessages()) {
System.out.println(buildMsg.getPath() + " : " + buildMsg.getText());
++buildMsgs;
}
if (buildMsgs > 0) {
throw new RuntimeException("Unable to build KieModule, see the " + buildMsgs + " messages above.");
}
return kieBuilder.getKieModule();
}
use of org.kie.util.maven.support.ReleaseIdImpl in project drools by kiegroup.
the class AccumulateTest method testImportAccumulateFunction.
private void testImportAccumulateFunction(final String drl) {
final ReleaseId releaseId = new ReleaseIdImpl("foo", "bar", "1.0");
KieUtil.getKieModuleFromDrls(releaseId, kieBaseTestConfiguration, drl);
final KieContainer kc = KieServices.get().newKieContainer(releaseId);
final KieSession ksession = kc.newKieSession();
try {
final AgendaEventListener ael = mock(AgendaEventListener.class);
ksession.addEventListener(ael);
ksession.insert("x");
ksession.fireAllRules();
final ArgumentCaptor<AfterMatchFiredEvent> ac = ArgumentCaptor.forClass(AfterMatchFiredEvent.class);
verify(ael).afterMatchFired(ac.capture());
assertThat(ac.getValue().getMatch().getDeclarationValue("$v"), is(1));
} finally {
ksession.dispose();
}
}
use of org.kie.util.maven.support.ReleaseIdImpl in project drools by kiegroup.
the class PMMLRuntimeFactoryInternalTest method testGetPMMLRuntimeFromFileAndReleaseId.
@Test
public void testGetPMMLRuntimeFromFileAndReleaseId() {
File pmmlFile = getFile("MiningModel_Mixed.pmml");
ReleaseId releaseId = new ReleaseIdImpl("org.dummy:dummy-artifact:1-0");
PMMLRuntime retrieved = PMMLRuntimeFactoryInternal.getPMMLRuntime(pmmlFile, releaseId);
commonValidatePMMLRuntime(retrieved);
}
Aggregations