Search in sources :

Example 1 with KieRepositoryScannerImpl

use of org.kie.scanner.KieRepositoryScannerImpl in project drools by kiegroup.

the class KieScannerMBeanTest method testKScannerMBean.

@Test
public void testKScannerMBean() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "scanner-mbean-test", "1.0-SNAPSHOT");
    InternalKieModule kJar1 = createKieJar(ks, releaseId, "rule1", "rule2");
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    KieMavenRepository repository = getKieMavenRepository();
    repository.installArtifact(releaseId, kJar1, createKPom(fileManager, releaseId));
    // create a ksesion and check it works as expected
    KieSession ksession = kieContainer.newKieSession("KSession1");
    checkKSession(ksession, "rule1", "rule2");
    KieRepositoryScannerImpl scanner = (KieRepositoryScannerImpl) ks.newKieScanner(kieContainer);
    KieScannerMBeanImpl mBean = (KieScannerMBeanImpl) scanner.getMBean();
    ObjectName mbeanName = mBean.getMBeanName();
    // we want to check that the mbean is register in the server and exposing the correct attribute values
    // so we fetch the attributes from the server
    Assert.assertEquals(releaseId.toExternalForm(), MBeanUtils.getAttribute(mbeanName, "ScannerReleaseId"));
    Assert.assertEquals(releaseId.toExternalForm(), MBeanUtils.getAttribute(mbeanName, "CurrentReleaseId"));
    Assert.assertEquals(InternalKieScanner.Status.STOPPED.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
    MBeanUtils.invoke(mbeanName, "start", new Object[] { Long.valueOf(10000) }, new String[] { "long" });
    Assert.assertEquals(InternalKieScanner.Status.RUNNING.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
    MBeanUtils.invoke(mbeanName, "stop", new Object[] {}, new String[] {});
    Assert.assertEquals(InternalKieScanner.Status.STOPPED.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
    // create a new kjar
    InternalKieModule kJar2 = createKieJar(ks, releaseId, "rule2", "rule3");
    // deploy it on maven
    repository.installArtifact(releaseId, kJar2, createKPom(fileManager, releaseId));
    MBeanUtils.invoke(mbeanName, "scanNow", new Object[] {}, new String[] {});
    // create a ksesion and check it works as expected
    KieSession ksession2 = kieContainer.newKieSession("KSession1");
    checkKSession(ksession2, "rule2", "rule3");
    MBeanUtils.invoke(mbeanName, "shutdown", new Object[] {}, new String[] {});
    Assert.assertEquals(InternalKieScanner.Status.SHUTDOWN.toString(), MBeanUtils.getAttribute(mbeanName, "Status"));
    ks.getRepository().removeKieModule(releaseId);
}
Also used : KieRepositoryScannerImpl(org.kie.scanner.KieRepositoryScannerImpl) KieMavenRepository.getKieMavenRepository(org.kie.scanner.KieMavenRepository.getKieMavenRepository) KieMavenRepository(org.kie.scanner.KieMavenRepository) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) KieContainer(org.kie.api.runtime.KieContainer) ObjectName(javax.management.ObjectName) Test(org.junit.Test) AbstractKieCiTest(org.kie.scanner.AbstractKieCiTest)

Aggregations

ObjectName (javax.management.ObjectName)1 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)1 Test (org.junit.Test)1 KieServices (org.kie.api.KieServices)1 ReleaseId (org.kie.api.builder.ReleaseId)1 KieContainer (org.kie.api.runtime.KieContainer)1 KieSession (org.kie.api.runtime.KieSession)1 AbstractKieCiTest (org.kie.scanner.AbstractKieCiTest)1 KieMavenRepository (org.kie.scanner.KieMavenRepository)1 KieMavenRepository.getKieMavenRepository (org.kie.scanner.KieMavenRepository.getKieMavenRepository)1 KieRepositoryScannerImpl (org.kie.scanner.KieRepositoryScannerImpl)1