use of org.uberfire.rpc.SessionInfo in project kie-wb-common by kiegroup.
the class BuilderConcurrencyIntegrationTest method testBuilderConcurrency.
@Test
public // https://bugzilla.redhat.com/show_bug.cgi?id=1145105
void testBuilderConcurrency() throws URISyntaxException {
final URL pomUrl = this.getClass().getResource("/BuilderConcurrencyRepo/pom.xml");
final org.uberfire.java.nio.file.Path nioPomPath = fs.getPath(pomUrl.toURI());
final Path pomPath = paths.convert(nioPomPath);
final URL resourceUrl = this.getClass().getResource("/BuilderConcurrencyRepo/src/main/resources/update.drl");
final org.uberfire.java.nio.file.Path nioResourcePath = fs.getPath(resourceUrl.toURI());
final Path resourcePath = paths.convert(nioResourcePath);
final SessionInfo sessionInfo = mock(SessionInfo.class);
// Force full build before attempting incremental changes
final KieModule project = moduleService.resolveModule(resourcePath);
final BuildResults buildResults = buildService.build(project);
assertNotNull(buildResults);
assertEquals(0, buildResults.getErrorMessages().size());
assertEquals(1, buildResults.getInformationMessages().size());
// Perform incremental build
final int THREADS = 200;
final Result result = new Result();
ExecutorService es = Executors.newCachedThreadPool();
for (int i = 0; i < THREADS; i++) {
switch(i % 3) {
case 0:
es.execute(new Runnable() {
@Override
public void run() {
try {
logger.debug("Thread " + Thread.currentThread().getName() + " has started: BuildService.build( project )");
buildService.build(project);
logger.debug("Thread " + Thread.currentThread().getName() + " has completed.");
} catch (Throwable e) {
result.setFailed(true);
result.setMessage(e.getMessage());
logger.debug(e.getMessage());
}
}
});
break;
case 1:
es.execute(new Runnable() {
@Override
public void run() {
try {
logger.debug("Thread " + Thread.currentThread().getName() + " has started: LRUModuleDataModelOracleCache.invalidateModuleCache(...)");
moduleDMOCache.invalidateModuleCache(new InvalidateDMOModuleCacheEvent(sessionInfo, project, pomPath));
logger.debug("Thread " + Thread.currentThread().getName() + " has completed.");
} catch (Throwable e) {
result.setFailed(true);
result.setMessage(e.getMessage());
logger.debug(e.getMessage());
}
}
});
break;
default:
es.execute(new Runnable() {
@Override
public void run() {
try {
logger.debug("Thread " + Thread.currentThread().getName() + " has started: LRUBuilderCache.assertBuilder( project ).getKieModuleIgnoringErrors();");
builderCache.assertBuilder(project).getKieModuleIgnoringErrors();
logger.debug("Thread " + Thread.currentThread().getName() + " has completed.");
} catch (Throwable e) {
result.setFailed(true);
result.setMessage(e.getMessage());
logger.debug(e.getMessage());
}
}
});
}
}
es.shutdown();
try {
es.awaitTermination(5, TimeUnit.MINUTES);
} catch (InterruptedException e) {
}
if (result.isFailed()) {
fail(result.getMessage());
}
}
use of org.uberfire.rpc.SessionInfo in project drools-wb by kiegroup.
the class DecisionTableXLSServiceImpl method writeToFile.
private Path writeToFile(final Path resource, final InputStream content, final String sessionId, final String comment, boolean create) {
final SessionInfo sessionInfo = getSessionInfo(sessionId);
log.info("USER: {} {} asset [{}]", sessionInfo.getIdentity().getIdentifier(), create ? "CREATING" : "UPDATING", resource.getFileName());
try {
final File tempFile = File.createTempFile("testxls", null);
try (FileOutputStream tempFOS = new FileOutputStream(tempFile)) {
IOUtils.copy(content, tempFOS);
tempFOS.flush();
}
// Validate the xls
validate(tempFile);
final org.uberfire.java.nio.file.Path nioPath = Paths.convert(resource);
ioService.startBatch(nioPath.getFileSystem());
try (FileInputStream tempFIS = new FileInputStream(tempFile)) {
if (create) {
ioService.write(nioPath, IOUtils.toByteArray(tempFIS), commentedOptionFactory.makeCommentedOption(comment, sessionInfo.getIdentity(), sessionInfo));
} else {
try (OutputStream outputStream = ioService.newOutputStream(nioPath, commentedOptionFactory.makeCommentedOption(comment, sessionInfo.getIdentity(), sessionInfo))) {
// InputStream 'content' has been fully read to write to the temp file; so we need to use a new InputStream
// An alternative is to check for content.markSupported() and reset() however since we have a temporary
// file we may as well use it!
IOUtils.copy(tempFIS, outputStream);
outputStream.flush();
}
}
}
// Read Path to ensure attributes have been set
return Paths.convert(nioPath);
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
} finally {
ioService.endBatch();
}
}
use of org.uberfire.rpc.SessionInfo in project drools-wb by kiegroup.
the class ScoreCardXLSServiceImpl method writeToFile.
private Path writeToFile(final Path resource, final InputStream content, final String sessionId, final String comment, boolean create) {
final SessionInfo sessionInfo = getSessionInfo(sessionId);
log.info("USER: {} {} asset [{}]", sessionInfo.getIdentity().getIdentifier(), create ? "CREATING" : "UPDATING", resource.getFileName());
final org.uberfire.java.nio.file.Path nioPath = Paths.convert(resource);
if (create) {
ioService.createFile(nioPath);
}
try (OutputStream outputStream = ioService.newOutputStream(nioPath, commentedOptionFactory.makeCommentedOption(comment, sessionInfo.getIdentity(), sessionInfo))) {
IOUtils.copy(content, outputStream);
outputStream.flush();
return resource;
} catch (Exception e) {
throw ExceptionUtilities.handleException(e);
}
}
Aggregations