use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository in project droolsjbpm-integration by kiegroup.
the class AbstractKieServerImplTest method testPersistScannerState.
@Test
public // https://issues.jboss.org/browse/RHBPMS-4087
void testPersistScannerState() {
String containerId = "persist-scanner-state";
createEmptyKjar(containerId);
// create the container and update the scanner
KieContainerResource kieContainerResource = new KieContainerResource(containerId, new ReleaseId(releaseId));
kieServer.createContainer(containerId, kieContainerResource);
KieScannerResource kieScannerResource = new KieScannerResource(KieScannerStatus.STARTED, 20000L);
kieServer.updateScanner(containerId, kieScannerResource);
KieServerStateRepository stateRepository = new KieServerStateFileRepository(REPOSITORY_DIR);
KieServerState state = stateRepository.load(KIE_SERVER_ID);
Set<KieContainerResource> containers = state.getContainers();
Assertions.assertThat(containers).hasSize(1);
KieContainerResource container = containers.iterator().next();
Assertions.assertThat(container.getScanner()).isEqualTo(kieScannerResource);
KieScannerResource updatedKieScannerResource = new KieScannerResource(KieScannerStatus.DISPOSED);
kieServer.updateScanner(containerId, updatedKieScannerResource);
// create new state repository instance to avoid caching via 'knownStates'
// this simulates the server restart (since the status is loaded from filesystem after restart)
stateRepository = new KieServerStateFileRepository(REPOSITORY_DIR);
state = stateRepository.load(KIE_SERVER_ID);
containers = state.getContainers();
Assertions.assertThat(containers).hasSize(1);
container = containers.iterator().next();
Assertions.assertThat(container.getScanner()).isEqualTo(updatedKieScannerResource);
kieServer.disposeContainer(containerId);
}
use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository in project droolsjbpm-integration by kiegroup.
the class AbstractKieServerImplTest method testManagementDisabledConfiguredViaCommandService.
@Test
public void testManagementDisabledConfiguredViaCommandService() {
System.setProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED, "true");
try {
kieServer.destroy();
kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR));
kieServer.init();
KieContainerCommandServiceImpl commandService = new KieContainerCommandServiceImpl(kieServer, kieServer.getServerRegistry());
List<KieServerCommand> commands = new ArrayList<>();
commands.add(new CreateContainerCommand());
commands.add(new DisposeContainerCommand());
commands.add(new UpdateScannerCommand());
commands.add(new UpdateReleaseIdCommand());
CommandScript commandScript = new CommandScript(commands);
ServiceResponsesList responseList = commandService.executeScript(commandScript, MarshallingFormat.JAXB, null);
assertNotNull(responseList);
List<ServiceResponse<?>> responses = responseList.getResponses();
assertEquals(4, responses.size());
for (ServiceResponse<?> forbidden : responses) {
assertForbiddenResponse(forbidden);
}
} finally {
System.clearProperty(KieServerConstants.KIE_SERVER_MGMT_API_DISABLED);
}
}
use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository in project droolsjbpm-integration by kiegroup.
the class AbstractKieServerImplTest method delayedKieServer.
protected KieServerImpl delayedKieServer(CountDownLatch latch, CountDownLatch startedlatch) {
KieServerImpl server = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR)) {
@Override
public void markAsReady() {
super.markAsReady();
startedlatch.countDown();
}
@Override
public KieServerController getController() {
return new DefaultRestControllerImpl(getServerRegistry()) {
@Override
public KieServerSetup connect(KieServerInfo serverInfo) {
try {
if (latch.await(10, TimeUnit.MILLISECONDS)) {
return new KieServerSetup();
}
throw new KieControllerNotConnectedException("Unable to connect to any controller");
} catch (InterruptedException e) {
throw new KieControllerNotConnectedException("Unable to connect to any controller");
}
}
};
}
};
server.init();
return server;
}
use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository in project droolsjbpm-integration by kiegroup.
the class KieServerImplInitTest method testDefaultStartupStrategyFromController.
@Test(timeout = 10000)
public void testDefaultStartupStrategyFromController() throws Exception {
final TestContainerManager testContainerManager = new TestContainerManager();
kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR)) {
@Override
protected ContainerManager getContainerManager() {
return testContainerManager;
}
@Override
public KieServerController getController() {
return new KieServerController() {
@Override
public void disconnect(KieServerInfo serverInfo) {
}
@Override
public KieServerSetup connect(KieServerInfo serverInfo) {
KieServerSetup serverSetup = new KieServerSetup();
KieContainerResource container = new KieContainerResource("test", new ReleaseId("", "", ""), KieContainerStatus.STARTED);
Set<KieContainerResource> containers = new HashSet<>();
containers.add(container);
serverSetup.setContainers(containers);
return serverSetup;
}
};
}
};
kieServer.init();
assertTrue(testContainerManager.isInstalled());
assertEquals(1, testContainerManager.getInstalledContainers().size());
}
use of org.kie.server.services.impl.storage.file.KieServerStateFileRepository in project droolsjbpm-integration by kiegroup.
the class KieServerImplInitTest method testLOcalContainersStartupStrategyFromController.
@Test(timeout = 10000)
public void testLOcalContainersStartupStrategyFromController() throws Exception {
System.setProperty(KieServerConstants.KIE_SERVER_STARTUP_STRATEGY, LocalContainersStartupStrategy.class.getSimpleName());
StartupStrategyProvider.clear();
final TestContainerManager testContainerManager = new TestContainerManager();
kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR)) {
@Override
protected ContainerManager getContainerManager() {
return testContainerManager;
}
@Override
public KieServerController getController() {
return new KieServerController() {
@Override
public void disconnect(KieServerInfo serverInfo) {
}
@Override
public KieServerSetup connect(KieServerInfo serverInfo) {
KieServerSetup serverSetup = new KieServerSetup();
KieContainerResource container = new KieContainerResource("test", new ReleaseId("", "", ""), KieContainerStatus.STARTED);
Set<KieContainerResource> containers = new HashSet<>();
containers.add(container);
serverSetup.setContainers(containers);
return serverSetup;
}
};
}
};
kieServer.init();
assertTrue(testContainerManager.isInstalled());
// even though controller returns containers they should be ignored when LocalContainersStartupStrategy is used
assertEquals(0, testContainerManager.getInstalledContainers().size());
}
Aggregations