use of org.kie.server.services.impl.KieServerRegistryImpl in project droolsjbpm-integration by kiegroup.
the class KieControllerCrashIntegrationTest method testCrashAfterRegistered.
@Test
public void testCrashAfterRegistered() throws Exception {
final String SERVER_TEMPLATE_ID = "template-id";
final String SERVER_NAME = "server-name";
KieServerEnvironment.setServerId(SERVER_TEMPLATE_ID);
ServerTemplate serverTemplate = new ServerTemplate(SERVER_TEMPLATE_ID, SERVER_NAME);
controllerClient.saveServerTemplate(serverTemplate);
ServerTemplateList instanceList = controllerClient.listServerTemplates();
assertEquals(1, instanceList.getServerTemplates().length);
// Register kie server in controller.
KieServerInfo kieServerInfo = new KieServerInfo(SERVER_TEMPLATE_ID, "1.0.0");
kieServerInfo.setLocation("http://127.0.0.1:20000");
kieServerInfo.setMode(KieServerMode.PRODUCTION);
kieServerInfo.setName(SERVER_NAME);
KieServerRegistry registry = new KieServerRegistryImpl();
KieServerStateRepository dummyKieServerStateRepository = new KieServerStateRepository() {
@Override
public void store(String serverId, KieServerState kieServerState) {
}
@Override
public KieServerState load(String serverId) {
KieServerState kieServerState = new KieServerState();
kieServerState.setControllers(Collections.singleton(TestConfig.getControllerHttpUrl()));
kieServerState.setConfiguration(new KieServerConfig());
if (TestConfig.isLocalServer()) {
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_USER, "", null));
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_PASSWORD, "", null));
} else {
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_USER, TestConfig.getUsername(), null));
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_PASSWORD, TestConfig.getPassword(), null));
}
return kieServerState;
}
};
registry.registerStateRepository(dummyKieServerStateRepository);
KieServerController controller = new DefaultRestControllerImpl(registry);
controller.connect(kieServerInfo);
// Check that kie server is registered.
serverUp.await(5, TimeUnit.SECONDS);
ServerInstanceKeyList list = controllerClient.getServerInstances(instanceList.getServerTemplates()[0].getId());
if (list.getServerInstanceKeys().length == 0) {
// Race condition when health check deleted server instance sooner than we were able to check. Resubmitting server instance again.
serverUp = new CountDownLatch(1);
serverDown = new CountDownLatch(1);
controller.connect(kieServerInfo);
serverUp.await(5, TimeUnit.SECONDS);
list = controllerClient.getServerInstances(instanceList.getServerTemplates()[0].getId());
}
assertNotNull(list.getServerInstanceKeys());
assertEquals(1, list.getServerInstanceKeys().length);
// Check that kie server is deregistered automatically.
serverDown.await(5, TimeUnit.SECONDS);
list = controllerClient.getServerInstances(instanceList.getServerTemplates()[0].getId());
assertNotNull(list.getServerInstanceKeys());
assertEquals(0, list.getServerInstanceKeys().length);
}
use of org.kie.server.services.impl.KieServerRegistryImpl in project droolsjbpm-integration by kiegroup.
the class KieControllerValidationIntegrationTest method init.
@Before
public void init() {
dummyKieServerStateRepository = new KieServerStateRepository() {
@Override
public void store(String serverId, KieServerState kieServerState) {
}
@Override
public KieServerState load(String serverId) {
KieServerState kieServerState = new KieServerState();
kieServerState.setControllers(Collections.singleton(TestConfig.getControllerHttpUrl()));
kieServerState.setConfiguration(new KieServerConfig());
if (TestConfig.isLocalServer()) {
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_USER, "", null));
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_PASSWORD, "", null));
} else {
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_USER, TestConfig.getUsername(), null));
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_PASSWORD, TestConfig.getPassword(), null));
}
return kieServerState;
}
};
registry = new KieServerRegistryImpl();
registry.registerStateRepository(dummyKieServerStateRepository);
}
use of org.kie.server.services.impl.KieServerRegistryImpl in project droolsjbpm-integration by kiegroup.
the class KeepLatestContainerOnlyPolicyTest method testDisposeOldContainer.
@Test
public void testDisposeOldContainer() {
KieServerRegistry kieServerRegistry = new KieServerRegistryImpl();
KieContainerInstanceImpl kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_ONE, KieContainerStatus.STARTED, kieContainerOne);
kieServerRegistry.registerContainer(CONTAINER_ONE, kieContainerInstance);
kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_TWO, KieContainerStatus.STARTED, kieContainerTwo);
kieServerRegistry.registerContainer(CONTAINER_TWO, kieContainerInstance);
KeepLatestContainerOnlyPolicy policy = new KeepLatestContainerOnlyPolicy();
policy.apply(kieServerRegistry, kieServer);
verify(kieServer).disposeContainer(CONTAINER_ONE);
}
use of org.kie.server.services.impl.KieServerRegistryImpl in project droolsjbpm-integration by kiegroup.
the class KeepLatestContainerOnlyPolicyTest method testDoNotDisposeNewerCreatedContainer.
@Test
public void testDoNotDisposeNewerCreatedContainer() {
KieServerRegistry kieServerRegistry = new KieServerRegistryImpl();
KieContainerInstanceImpl kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_ONE, KieContainerStatus.STARTED, kieContainerOne);
kieServerRegistry.registerContainer(CONTAINER_ONE, kieContainerInstance);
kieContainerInstance = new KieContainerInstanceImpl(CONTAINER_TWO, KieContainerStatus.CREATING, kieContainerTwo);
kieServerRegistry.registerContainer(CONTAINER_TWO, kieContainerInstance);
KeepLatestContainerOnlyPolicy policy = new KeepLatestContainerOnlyPolicy();
policy.apply(kieServerRegistry, kieServer);
verify(kieServer, never()).disposeContainer(anyString());
}
use of org.kie.server.services.impl.KieServerRegistryImpl in project droolsjbpm-integration by kiegroup.
the class JbpmKieServerExtensionTest method init.
@Before
public void init() {
KieServerEnvironment.setServerId(UUID.randomUUID().toString());
context = new KieServerRegistryImpl();
context.registerStateRepository(new KieServerStateFileRepository(new File("target")));
kieServices = (KieServicesImpl) KieServices.Factory.get();
when(kieServerInfo.getMode()).thenAnswer(invocationOnMock -> mode);
when(kieServer.getInfo()).thenReturn(new ServiceResponse<KieServerInfo>(KieServiceResponse.ResponseType.SUCCESS, "", kieServerInfo));
extension = spy(new JbpmKieServerExtension() {
{
this.deploymentService = JbpmKieServerExtensionTest.this.deploymentService;
this.runtimeDataService = JbpmKieServerExtensionTest.this.runtimeDataService;
this.kieServer = JbpmKieServerExtensionTest.this.kieServer;
}
});
when(deploymentService.isDeployed(anyString())).thenAnswer((Answer<Boolean>) invocation -> deployed);
doAnswer(invocation -> {
deployed = false;
return null;
}).when(deploymentService).undeploy(any(), any());
doAnswer(invocation -> {
deployed = false;
return null;
}).when(deploymentService).undeploy(any());
doAnswer((Answer<Void>) invocation -> {
deploymentUnit = (DeploymentUnit) invocation.getArguments()[0];
deployed = true;
return null;
}).when(deploymentService).deploy(any());
when(deploymentService.getDeployedUnit(anyString())).thenAnswer((Answer<DeployedUnit>) invocation -> {
deployedUnit = new DeployedUnitImpl(deploymentUnit);
runimeManager = mock(RuntimeManager.class);
engine = mock(RuntimeEngine.class);
when(runimeManager.getRuntimeEngine(any())).thenReturn(engine);
session = mock(KieSession.class);
when(engine.getKieSession()).thenReturn(session);
deployedUnit.setRuntimeManager(runimeManager);
return deployedUnit;
});
extension.setQueryService(queryService);
extension.setContext(context);
when(runtimeDataService.getProcessInstancesByDeploymentId(anyString(), anyList(), any())).thenReturn(activeProcessInstances);
}
Aggregations