Search in sources :

Example 6 with SessionInfo

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());
    }
}
Also used : Path(org.uberfire.backend.vfs.Path) BuildResults(org.guvnor.common.services.project.builder.model.BuildResults) InvalidateDMOModuleCacheEvent(org.guvnor.common.services.project.builder.events.InvalidateDMOModuleCacheEvent) SessionInfo(org.uberfire.rpc.SessionInfo) URL(java.net.URL) ExecutorService(java.util.concurrent.ExecutorService) KieModule(org.kie.workbench.common.services.shared.project.KieModule) Test(org.junit.Test)

Example 7 with SessionInfo

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();
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) SafeSessionInfo(org.guvnor.common.services.backend.config.SafeSessionInfo) SessionInfo(org.uberfire.rpc.SessionInfo) File(java.io.File) FileInputStream(java.io.FileInputStream) SourceGenerationFailedException(org.kie.workbench.common.services.shared.source.SourceGenerationFailedException) IOException(java.io.IOException) DecisionTableParseException(org.drools.template.parser.DecisionTableParseException)

Example 8 with SessionInfo

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);
    }
}
Also used : OutputStream(java.io.OutputStream) SafeSessionInfo(org.guvnor.common.services.backend.config.SafeSessionInfo) SessionInfo(org.uberfire.rpc.SessionInfo)

Aggregations

SessionInfo (org.uberfire.rpc.SessionInfo)8 Test (org.junit.Test)3 Path (org.uberfire.backend.vfs.Path)3 OutputStream (java.io.OutputStream)2 URL (java.net.URL)2 SafeSessionInfo (org.guvnor.common.services.backend.config.SafeSessionInfo)2 InvalidateDMOModuleCacheEvent (org.guvnor.common.services.project.builder.events.InvalidateDMOModuleCacheEvent)2 NewModuleEvent (org.guvnor.common.services.project.events.NewModuleEvent)2 UserImpl (org.jboss.errai.security.shared.api.identity.UserImpl)2 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ExecutorService (java.util.concurrent.ExecutorService)1 Predicate (java.util.function.Predicate)1 CreationalContext (javax.enterprise.context.spi.CreationalContext)1 Bean (javax.enterprise.inject.spi.Bean)1