Author: rmannibucau
Date: Tue May 22 07:35:20 2018
New Revision: 1832009

URL: http://svn.apache.org/viewvc?rev=1832009&view=rev
Log:
OWB-1245 adding StandaloneContextsService

Added:
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/BaseSeContextsService.java
      - copied, changed from r1832007, 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/StandaloneContextsService.java
    
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/StandaloneContextsServiceTest.java
    openwebbeans/trunk/webbeans-se/src/main/resources/META-INF/openwebbeans/
    
openwebbeans/trunk/webbeans-se/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Modified:
    
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java

Copied: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/BaseSeContextsService.java
 (from r1832007, 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java)
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/BaseSeContextsService.java?p2=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/BaseSeContextsService.java&p1=openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java&r1=1832007&r2=1832009&rev=1832009&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/BaseSeContextsService.java
 Tue May 22 07:35:20 2018
@@ -41,27 +41,22 @@ import org.apache.webbeans.context.Conve
 import org.apache.webbeans.context.DependentContext;
 import org.apache.webbeans.context.RequestContext;
 import org.apache.webbeans.context.SessionContext;
-import org.apache.webbeans.context.SingletonContext;
 import org.apache.webbeans.conversation.ConversationManager;
 import org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler;
 import org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler;
 
 
-public class DefaultContextsService extends AbstractContextsService
+public abstract class BaseSeContextsService extends AbstractContextsService
 {
     private static ThreadLocal<RequestContext> requestContext;
 
     private static ThreadLocal<SessionContext> sessionContext;
 
-    private ApplicationContext applicationContext;
-
     private static ThreadLocal<ConversationContext> conversationContext;
-    
-    private static ThreadLocal<SingletonContext> singletonContext;
 
     private static ThreadLocal<DependentContext> dependentContext;
 
-
+    private ApplicationContext applicationContext;
 
     static
     {
@@ -69,14 +64,19 @@ public class DefaultContextsService exte
         sessionContext = new ThreadLocal<>();
         conversationContext = new ThreadLocal<>();
         dependentContext = new ThreadLocal<>();
-        singletonContext = new ThreadLocal<>();
     }
 
-    public DefaultContextsService(WebBeansContext webBeansContext)
+    protected BaseSeContextsService(final WebBeansContext webBeansContext)
     {
         super(webBeansContext);
     }
 
+    protected abstract void destroySingletonContext();
+
+    protected abstract Context getCurrentSingletonContext();
+
+    protected abstract void createSingletonContext();
+
     /**
      * {@inheritDoc}
      */
@@ -216,17 +216,14 @@ public class DefaultContextsService exte
             conversationContext.remove();
         }
 
-        SingletonContext singletonCtx = singletonContext.get();
-        if (singletonCtx != null)
-        {
-            singletonCtx.destroy();
-            singletonContext.set(null);
-            singletonContext.remove();
-        }
-
         dependentContext.set(null);
         dependentContext.remove();
 
+        destroyGlobalContexts();
+    }
+
+    protected void destroyGlobalContexts()
+    {
         if (applicationContext != null)
         {
             applicationContext.destroy();
@@ -235,7 +232,6 @@ public class DefaultContextsService exte
     }
 
 
-
     private Context getCurrentConversationContext()
     {
         ConversationContext conversationCtx = conversationContext.get();
@@ -282,16 +278,9 @@ public class DefaultContextsService exte
 
     
     private Context getCurrentSessionContext()
-    {        
+    {
         return sessionContext.get();
     }
-
-    
-    private Context getCurrentSingletonContext()
-    {        
-        return singletonContext.get();
-    }
-
     
     private void startApplicationContext()
     {
@@ -355,16 +344,12 @@ public class DefaultContextsService exte
     
     private void startSingletonContext()
     {
-        
-        SingletonContext ctx = new SingletonContext();
-        ctx.setActive(true);
-        
-        singletonContext.set(ctx);
+
+        createSingletonContext();
         webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
             new Object(), InitializedLiteral.INSTANCE_SINGLETON_SCOPED);
     }
 
-    
     private void stopApplicationContext()
     {
         if(applicationContext != null && !applicationContext.isDestroyed())
@@ -440,16 +425,8 @@ public class DefaultContextsService exte
     {
         webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
             new Object(), BeforeDestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
-        if(singletonContext.get() != null)
-        {
-            singletonContext.get().destroy();   
-        }
-
-        singletonContext.set(null);
-        singletonContext.remove();
+        destroySingletonContext();
         webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
             new Object(), DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
     }
-
-
 }

Modified: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java?rev=1832009&r1=1832008&r2=1832009&view=diff
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
 (original)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/DefaultContextsService.java
 Tue May 22 07:35:20 2018
@@ -18,204 +18,29 @@
  */
 package org.apache.webbeans.corespi.se;
 
-import java.lang.annotation.Annotation;
-
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.context.BusyConversationException;
-import javax.enterprise.context.ContextException;
-import javax.enterprise.context.ConversationScoped;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.context.NonexistentConversationException;
-import javax.enterprise.context.RequestScoped;
-import javax.enterprise.context.SessionScoped;
 import javax.enterprise.context.spi.Context;
-import javax.inject.Singleton;
 
-import org.apache.webbeans.annotation.BeforeDestroyedLiteral;
-import org.apache.webbeans.annotation.DestroyedLiteral;
-import org.apache.webbeans.annotation.InitializedLiteral;
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.context.AbstractContextsService;
-import org.apache.webbeans.context.ApplicationContext;
-import org.apache.webbeans.context.ConversationContext;
-import org.apache.webbeans.context.DependentContext;
-import org.apache.webbeans.context.RequestContext;
-import org.apache.webbeans.context.SessionContext;
 import org.apache.webbeans.context.SingletonContext;
-import org.apache.webbeans.conversation.ConversationManager;
-import org.apache.webbeans.intercept.RequestScopedBeanInterceptorHandler;
-import org.apache.webbeans.intercept.SessionScopedBeanInterceptorHandler;
 
 
-public class DefaultContextsService extends AbstractContextsService
+public class DefaultContextsService extends BaseSeContextsService
 {
-    private static ThreadLocal<RequestContext> requestContext;
-
-    private static ThreadLocal<SessionContext> sessionContext;
-
-    private ApplicationContext applicationContext;
-
-    private static ThreadLocal<ConversationContext> conversationContext;
-    
     private static ThreadLocal<SingletonContext> singletonContext;
 
-    private static ThreadLocal<DependentContext> dependentContext;
-
-
-
     static
     {
-        requestContext = new ThreadLocal<>();
-        sessionContext = new ThreadLocal<>();
-        conversationContext = new ThreadLocal<>();
-        dependentContext = new ThreadLocal<>();
         singletonContext = new ThreadLocal<>();
     }
 
-    public DefaultContextsService(WebBeansContext webBeansContext)
+    public DefaultContextsService(final WebBeansContext webBeansContext)
     {
         super(webBeansContext);
     }
 
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void endContext(Class<? extends Annotation> scopeType, Object 
endParameters)
-    {
-        
-        if(scopeType.equals(RequestScoped.class))
-        {
-            stopRequestContext();
-        }
-        else if(scopeType.equals(SessionScoped.class))
-        {
-            stopSessionContext();
-        }
-        else if(scopeType.equals(ApplicationScoped.class))
-        {
-            stopApplicationContext();
-        }
-        else if(scopeType.equals(ConversationScoped.class))
-        {
-            stopConversationContext();
-        }
-        else if(scopeType.equals(Singleton.class))
-        {
-            stopSingletonContext();
-        }
-
-        // do nothing for Dependent.class
-
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
     @Override
-    public Context getCurrentContext(Class<? extends Annotation> scopeType)
+    protected void destroyGlobalContexts()
     {
-        if(scopeType.equals(RequestScoped.class))
-        {
-            return getCurrentRequestContext();
-        }
-        else if(scopeType.equals(SessionScoped.class))
-        {
-            return getCurrentSessionContext();
-        }
-        else if(scopeType.equals(ApplicationScoped.class))
-        {
-            return applicationContext;
-        }
-        else if(scopeType.equals(ConversationScoped.class) && 
supportsConversation)
-        {
-            return getCurrentConversationContext();
-        }
-        else if(scopeType.equals(Dependent.class))
-        {
-            return getCurrentDependentContext();
-        }
-        else if(scopeType.equals(Singleton.class))
-        {
-            return getCurrentSingletonContext();
-        }
-
-        return null;
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void startContext(Class<? extends Annotation> scopeType, Object 
startParameter) throws ContextException
-    {
-        try
-        {
-            if(scopeType.equals(RequestScoped.class))
-            {
-                startRequestContext();
-            }
-            else if(scopeType.equals(SessionScoped.class))
-            {
-                startSessionContext();
-            }
-            else if(scopeType.equals(ApplicationScoped.class))
-            {
-                startApplicationContext();
-            }
-            else if(scopeType.equals(ConversationScoped.class))
-            {
-                startConversationContext();
-            }
-            else if(scopeType.equals(Singleton.class))
-            {
-                startSingletonContext();
-            }
-
-            // do nothing for Dependent.class
-
-        }
-        catch (ContextException ce)
-        {
-            throw ce;
-        }
-        catch (Exception e)
-        {
-            throw new ContextException(e);
-        }        
-    }
-
-    @Override
-    public void destroy(Object destroyObject)
-    {
-        RequestContext requestCtx = requestContext.get();
-        if (requestCtx != null)
-        {
-            requestCtx.destroy();
-            RequestScopedBeanInterceptorHandler.removeThreadLocals();
-            requestContext.set(null);
-            requestContext.remove();
-        }
-
-        SessionContext sessionCtx = sessionContext.get();
-        if (sessionCtx != null)
-        {
-            sessionCtx.destroy();
-            SessionScopedBeanInterceptorHandler.removeThreadLocals();
-            sessionContext.set(null);
-            sessionContext.remove();
-        }
-
-        ConversationContext conversationCtx = conversationContext.get();
-        if (conversationCtx != null)
-        {
-            conversationCtx.destroy();
-            conversationContext.set(null);
-            conversationContext.remove();
-        }
-
         SingletonContext singletonCtx = singletonContext.get();
         if (singletonCtx != null)
         {
@@ -223,223 +48,27 @@ public class DefaultContextsService exte
             singletonContext.set(null);
             singletonContext.remove();
         }
-
-        dependentContext.set(null);
-        dependentContext.remove();
-
-        if (applicationContext != null)
-        {
-            applicationContext.destroy();
-            applicationContext.destroySystemBeans();
-        }
+        super.destroyGlobalContexts();
     }
 
-
-
-    private Context getCurrentConversationContext()
-    {
-        ConversationContext conversationCtx = conversationContext.get();
-        if (conversationCtx == null)
-        {
-            conversationCtx = 
webBeansContext.getConversationManager().getConversationContext(getCurrentSessionContext());
-            conversationContext.set(conversationCtx);
-
-            // check for busy and non-existing conversations
-            String conversationId = 
webBeansContext.getConversationService().getConversationId();
-            if (conversationId != null && 
conversationCtx.getConversation().isTransient())
-            {
-                throw new NonexistentConversationException("Propogated 
conversation with cid=" + conversationId +
-                        " cannot be restored. It creates a new transient 
conversation.");
-            }
-
-            if (conversationCtx.getConversation().iUseIt() > 1)
-            {
-                //Throw Busy exception
-                throw new BusyConversationException("Propogated conversation 
with cid=" + conversationId +
-                        " is used by other request. It creates a new transient 
conversation");
-            }
-        }
-
-        return conversationCtx;
-    }
-
-    
-    private Context getCurrentDependentContext()
-    {        
-        if(dependentContext.get() == null)
-        {
-            dependentContext.set(new DependentContext());
-        }
-        
-        return dependentContext.get();
-    }
-
-    
-    private Context getCurrentRequestContext()
-    {        
-        return requestContext.get();
-    }
-
-    
-    private Context getCurrentSessionContext()
-    {        
-        return sessionContext.get();
-    }
-
-    
-    private Context getCurrentSingletonContext()
+    @Override
+    protected Context getCurrentSingletonContext()
     {        
         return singletonContext.get();
     }
 
-    
-    private void startApplicationContext()
-    {
-        if (applicationContext != null && !applicationContext.isDestroyed())
-        {
-            // applicationContext is already started
-            return;
-        }
-
-        ApplicationContext ctx = new ApplicationContext();
-        ctx.setActive(true);
-
-        applicationContext = ctx;
-
-        // We do ALSO send the @Initialized(ApplicationScoped.class) at this
-        // location but this is WAY to early for userland apps
-        // This also gets sent in the application startup code after 
AfterDeploymentValidation got fired.
-        // see AbstractLifecycle#afterStartApplication
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            new Object(), InitializedLiteral.INSTANCE_APPLICATION_SCOPED);
-    }
-
-    
-    private void startConversationContext()
-    {
-        ConversationManager conversationManager = 
webBeansContext.getConversationManager();
-        ConversationContext ctx = 
conversationManager.getConversationContext(getCurrentSessionContext());
-        ctx.setActive(true);
-        conversationContext.set(ctx);
-
-        if (ctx.getConversation().isTransient())
-        {
-            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-                conversationManager.getLifecycleEventPayload(ctx), 
InitializedLiteral.INSTANCE_CONVERSATION_SCOPED);
-        }
-    }
-
-    
-    private void startRequestContext()
-    {
-        
-        RequestContext ctx = new RequestContext();
-        ctx.setActive(true);
-        
-        requestContext.set(ctx);
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            new Object(), InitializedLiteral.INSTANCE_REQUEST_SCOPED);
-    }
-
-    
-    private void startSessionContext()
-    {
-        SessionContext ctx = new SessionContext();
-        ctx.setActive(true);
-        
-        sessionContext.set(ctx);
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            new Object(), InitializedLiteral.INSTANCE_SESSION_SCOPED);
-    }
-
-    
-    private void startSingletonContext()
+    @Override
+    protected void createSingletonContext()
     {
-        
-        SingletonContext ctx = new SingletonContext();
+        final SingletonContext ctx = new SingletonContext();
         ctx.setActive(true);
         
         singletonContext.set(ctx);
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            new Object(), InitializedLiteral.INSTANCE_SINGLETON_SCOPED);
-    }
-
-    
-    private void stopApplicationContext()
-    {
-        if(applicationContext != null && !applicationContext.isDestroyed())
-        {
-            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-                    new Object(), 
BeforeDestroyedLiteral.INSTANCE_APPLICATION_SCOPED);
-
-            applicationContext.destroy();
-
-            // this is needed to get rid of ApplicationScoped beans which are 
cached inside the proxies...
-            
WebBeansContext.currentInstance().getBeanManagerImpl().clearCacheProxies();
-            webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-                new Object(), DestroyedLiteral.INSTANCE_APPLICATION_SCOPED);
-        }
-    }
-
-    
-    private void stopConversationContext()
-    {
-        if(conversationContext.get() != null)
-        {
-            conversationContext.get().destroy();   
-        }
-
-        conversationContext.set(null);
-        conversationContext.remove();
     }
 
-    
-    private void stopRequestContext()
-    {
-        // cleanup open conversations first
-        if (supportsConversation)
-        {
-            destroyOutdatedConversations(conversationContext.get());
-            conversationContext.set(null);
-            conversationContext.remove();
-        }
-
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-                new Object(), BeforeDestroyedLiteral.INSTANCE_REQUEST_SCOPED);
-        if(requestContext.get() != null)
-        {
-            requestContext.get().destroy();   
-        }
-
-        requestContext.set(null);
-        requestContext.remove();
-        RequestScopedBeanInterceptorHandler.removeThreadLocals();
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            new Object(), DestroyedLiteral.INSTANCE_REQUEST_SCOPED);
-    }
-
-    
-    private void stopSessionContext()
-    {
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-                new Object(), BeforeDestroyedLiteral.INSTANCE_SESSION_SCOPED);
-        if(sessionContext.get() != null)
-        {
-            sessionContext.get().destroy();   
-        }
-
-        sessionContext.set(null);
-        sessionContext.remove();
-        SessionScopedBeanInterceptorHandler.removeThreadLocals();
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            new Object(), DestroyedLiteral.INSTANCE_SESSION_SCOPED);
-    }
-
-    
-    private void stopSingletonContext()
+    @Override
+    protected void destroySingletonContext()
     {
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            new Object(), BeforeDestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
         if(singletonContext.get() != null)
         {
             singletonContext.get().destroy();   
@@ -447,9 +76,5 @@ public class DefaultContextsService exte
 
         singletonContext.set(null);
         singletonContext.remove();
-        webBeansContext.getBeanManagerImpl().fireContextLifecyleEvent(
-            new Object(), DestroyedLiteral.INSTANCE_SINGLETON_SCOPED);
     }
-
-
 }

Added: 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/StandaloneContextsService.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/StandaloneContextsService.java?rev=1832009&view=auto
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/StandaloneContextsService.java
 (added)
+++ 
openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/corespi/se/StandaloneContextsService.java
 Tue May 22 07:35:20 2018
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.corespi.se;
+
+import javax.enterprise.context.spi.Context;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.context.SingletonContext;
+
+public class StandaloneContextsService extends BaseSeContextsService
+{
+    private SingletonContext singletonContext;
+
+    public StandaloneContextsService(final WebBeansContext webBeansContext)
+    {
+        super(webBeansContext);
+    }
+
+    @Override
+    protected void createSingletonContext()
+    {
+        singletonContext = new SingletonContext();
+        singletonContext.setActive(true);
+    }
+
+    @Override
+    protected Context getCurrentSingletonContext()
+    {
+        return singletonContext;
+    }
+
+    @Override
+    protected void destroySingletonContext()
+    {
+        singletonContext.destroy();
+    }
+}

Added: 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/StandaloneContextsServiceTest.java
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/StandaloneContextsServiceTest.java?rev=1832009&view=auto
==============================================================================
--- 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/StandaloneContextsServiceTest.java
 (added)
+++ 
openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/contexts/StandaloneContextsServiceTest.java
 Tue May 22 07:35:20 2018
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.webbeans.test.contexts;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+import javax.inject.Singleton;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.corespi.se.StandaloneContextsService;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.junit.Test;
+
+public class StandaloneContextsServiceTest extends AbstractUnitTest
+{
+    @Test
+    public void ensureSingletonScopeIsUnique() throws ExecutionException, 
InterruptedException
+    {
+        addService(ContextsService.class, new 
StandaloneContextsService(WebBeansContext.getInstance()));
+        startContainer(Unique.class);
+        final Unique instance = getInstance(Unique.class);
+        final long id = instance.id(); // ensure it can be called = there is a 
context
+        final ExecutorService es = Executors.newSingleThreadExecutor();
+
+        // ContextNotActiveException: @Singleton does not exist within current 
thread with default
+        assertEquals(id, es.submit(() -> 
getInstance(Unique.class).id()).get().longValue());
+        es.shutdownNow();
+    }
+
+    @Singleton
+    public static class Unique
+    {
+        private final long instance = System.identityHashCode(this);
+
+        public long id()
+        {
+            return instance;
+        }
+    }
+}

Added: 
openwebbeans/trunk/webbeans-se/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: 
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-se/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1832009&view=auto
==============================================================================
--- 
openwebbeans/trunk/webbeans-se/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
 (added)
+++ 
openwebbeans/trunk/webbeans-se/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
 Tue May 22 07:35:20 2018
@@ -0,0 +1,18 @@
+#Licensed to the Apache Software Foundation (ASF) under one
+#or more contributor license agreements.  See the NOTICE file
+#distributed with this work for additional information
+#regarding copyright ownership.  The ASF licenses this file
+#to you under the Apache License, Version 2.0 (the
+#"License"); you may not use this file except in compliance
+#with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+#Unless required by applicable law or agreed to in writing,
+#software distributed under the License is distributed on an
+#"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#KIND, either express or implied.  See the License for the
+#specific language governing permissions and limitations
+#under the License.
+configuration.ordinal=11
+org.apache.webbeans.spi.ContextsService = 
org.apache.webbeans.corespi.se.StandaloneContextsService
\ No newline at end of file


Reply via email to