Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.kie.workbench.common.services.datamodel.backend.server;
  
  import java.net.URL;
  import  javax.enterprise.event.Event;
  import  javax.inject.Inject;
 import  javax.inject.Named;
 
 import  org.apache.commons.lang.exception.ExceptionUtils;
 import  org.guvnor.common.services.builder.ResourceChangeIncrementalBuilder;
 import  org.guvnor.common.services.project.builder.events.InvalidateDMOProjectCacheEvent;
 import  org.guvnor.common.services.project.builder.model.BuildResults;
 import  org.guvnor.common.services.project.builder.service.BuildService;
 import  org.jboss.arquillian.container.test.api.Deployment;
 import  org.jboss.arquillian.junit.Arquillian;
 import  org.jboss.shrinkwrap.api.Archive;
 import  org.jboss.shrinkwrap.api.ArchivePaths;
 import  org.jboss.shrinkwrap.api.ShrinkWrap;
 import  org.jboss.shrinkwrap.api.spec.JavaArchive;
 import  org.junit.Test;
 import  org.junit.runner.RunWith;
 import  org.kie.workbench.common.services.datamodel.backend.server.service.DataModelService;
 import  org.kie.workbench.common.services.shared.project.KieProject;
 import  org.kie.workbench.common.services.shared.project.KieProjectService;
 import  org.uberfire.backend.server.util.Paths;
 import  org.uberfire.backend.vfs.Path;
 import  org.uberfire.io.IOService;
 import  org.uberfire.rpc.SessionInfo;
 
 import static org.junit.Assert.*;
 
 @RunWith(Arquillian.class)
 
     @Deployment()
     public static Archive<?> createDeployment() {
         return ShrinkWrap.create( JavaArchive.class,
                                   "builder.jar" )
                 .addPackage( "org.kie.commons.java.nio.fs.jgit" )
                 .addPackage( "org.kie.workbench.common.services.datamodel.backend.server" )
                 .addPackage( "org.kie.workbench.common.services.datamodel.backend.server.cache" )
                 .addPackage( "org.guvnor.m2repo.backend.server" )
                 .addPackage( "org.guvnor.m2repo.backend.server.helpers" )
                 .addPackage( "org.guvnor.structure.backend.config" )
                 .addPackage( "org.guvnor.common.services.project.service" )
                 .addPackage( "org.guvnor.common.services.project.backend.server" )
                 .addPackage( "org.guvnor.common.services.builder" )
                 .addPackage( "org.guvnor.common.services.backend.file" )
                 .addPackage( "org.guvnor.common.services.backend.metadata" )
                 .addPackage( "org.guvnor.common.services.backend.config" )
                 .addPackage( "org.guvnor.common.services.backend.rulenames" )
                 .addPackage( "org.guvnor.common.services.shared.metadata" )
                 .addPackage( "org.guvnor.common.services.shared.config" )
                 .addPackage( "org.guvnor.common.services.shared.rulenames" )
                 .addPackage( "javax.servlet" )
                 .addPackage( "javax.servlet.http" )
                 .addPackage( "org.guvnor.structure.repositories" )
                 .addPackage( "org.guvnor.structure.repositories.impl.git" )
                 .addPackage( "org.guvnor.structure.backend.repositories" )
                 .addPackage( "org.guvnor.structure.backend.repositories.git" )
                 .addPackage( "org.guvnor.structure.organizationalunit" )
                 .addPackage( "org.guvnor.structure.organizationalunit.impl" )
                 .addPackage( "org.guvnor.structure.backend.organizationalunit" )
                 .addPackage( "org.uberfire.commons.cluster" )
                 .addPackage( "org.uberfire.backend.server.util" )
                 .addPackage( "org.uberfire.backend.server.config" )
                 .addPackage( "org.uberfire.backend.server.io" )
                 .addPackage( "org.uberfire.backend.server.cluster" )
                 .addPackage( "org.kie.workbench.common.services.backend.project" )
                 .addPackage( "org.kie.workbench.common.services.backend.builder" )
                 .addAsManifestResource( "META-INF/beans.xml",
                                         ArchivePaths.create( "beans.xml" ) );
     }
 
     @Inject
     private Paths paths;
 
     @Inject
 
     @Inject
     private BuildService buildService;
 
     @Inject
     private KieProjectService projectService;
 
     @Inject
     private DataModelService dataModelService;
 
     @Inject
     private ResourceChangeIncrementalBuilder buildChangeListener;
 
     @Inject
     private SessionInfo sessionInfo;
 
     @Inject
    @Named("ioStrategy")
    private IOService ioService;
    @Inject
    private Event<InvalidateDMOProjectCacheEvent> invalidateDMOProjectCacheEvent;
    @Test
    public void testConcurrentResourceUpdates() throws URISyntaxException {
        final URL pomUrl = this.getClass().getResource"/DataModelBackendTest1/pom.xml" );
        final org.uberfire.java.nio.file.Path nioPomPath = .get( pomUrl.toURI() );
        final Path pomPath = .convert( nioPomPath );
        final URL resourceUrl = this.getClass().getResource"/DataModelBackendTest1/src/main/resources/empty.rdrl" );
        final org.uberfire.java.nio.file.Path nioResourcePath = .get( resourceUrl.toURI() );
        final Path resourcePath = .convert( nioResourcePath );
        //Force full build before attempting incremental changes
        final KieProject project = .resolveProject( resourcePath );
        final BuildResults buildResults = .build( project );
        assertNotNull( buildResults );
        assertEquals( 0,
                      buildResults.getMessages().size() );
        //Perform incremental build
        final int THREADS = 200;
        final Result result = new Result();
        ExecutorService es = Executors.newCachedThreadPool();
        for ( int i = 0; i < THREADSi++ ) {
            final int operation = ( i % 3 );
            switch ( operation ) {
                case 0:
                    es.executenew Runnable() {
                        @Override
                        public void run() {
                            try {
                                ..println"[Thread: " + Thread.currentThread().getName() + "] Request to update POM received" );
                                invalidateCachesproject,
                                                  pomPath );
                                .updateResource( pomPath );
                                ..println"[Thread: " + Thread.currentThread().getName() + "] POM update completed" );
                            } catch ( Throwable e ) {
                                result.setFailedtrue );
                                result.setMessagee.getMessage() );
                                ..println( ExceptionUtils.getFullStackTrace( e ) );
                            }
                        }
                    } );
                    break;
                case 1:
                    es.executenew Runnable() {
                        @Override
                        public void run() {
                            try {
                                ..println"[Thread: " + Thread.currentThread().getName() + "] Request to update Resource received" );
                                invalidateCachesproject,
                                                  resourcePath );
                                .addResource( resourcePath );
                                ..println"[Thread: " + Thread.currentThread().getName() + "] Resource update completed" );
                            } catch ( Throwable e ) {
                                result.setFailedtrue );
                                result.setMessagee.getMessage() );
                                ..println( ExceptionUtils.getFullStackTrace( e ) );
                            }
                        }
                    } );
                    break;
                case 2:
                    es.executenew Runnable() {
                        @Override
                        public void run() {
                            try {
                                ..println"[Thread: " + Thread.currentThread().getName() + "] Request for DataModel received" );
                                .getDataModel( resourcePath );
                                ..println"[Thread: " + Thread.currentThread().getName() + "] DataModel request completed" );
                            } catch ( Throwable e ) {
                                result.setFailedtrue );
                                result.setMessagee.getMessage() );
                                ..println( ExceptionUtils.getFullStackTrace( e ) );
                            }
                        }
                    } );
            }
        }
        es.shutdown();
        try {
            es.awaitTermination( 5,
                                 . );
        } catch ( InterruptedException e ) {
        }
        if ( result.isFailed() ) {
            failresult.getMessage() );
        }
    }
    private void invalidateCachesfinal KieProject project,
                                   final Path resourcePath ) {
        .fire( new InvalidateDMOProjectCacheEvent( ,
                                                                                 project,
                                                                                 resourcePath ) );
    }
    private static class Result {
        private boolean failed = false;
        private String message = "";
        public synchronized boolean isFailed() {
            return ;
        }
        public synchronized void setFailedboolean failed ) {
            this. = failed;
        }
        public synchronized String getMessage() {
            return ;
        }
        public synchronized void setMessageString message ) {
            this. = message;
        }
    }
New to GrepCode? Check out our FAQ X