Search in sources :

Example 1 with RuntimeBindReleaseService

use of org.jboss.as.naming.deployment.RuntimeBindReleaseService in project wildfly by wildfly.

the class WritableServiceBasedNamingStoreTestCase method testMultipleOwnersBindingReferences.

@Test
public void testMultipleOwnersBindingReferences() throws Exception {
    final Name name = new CompositeName("test");
    final ServiceName serviceName = store.buildServiceName(name);
    final Object value = new Object();
    // ensure bind does not exists
    try {
        store.lookup(name);
        fail("Should have thrown name not found");
    } catch (NameNotFoundException expect) {
    }
    // ensure the owners RuntimeBindReleaseService have no reference to the future bind
    final RuntimeBindReleaseService.References fooDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_FOO)).getValue();
    assertFalse(fooDuBindingReferences.contains(serviceName));
    final RuntimeBindReleaseService.References barDuBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_BAR)).getValue();
    assertFalse(barDuBindingReferences.contains(serviceName));
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        // Foo's RuntimeBindReleaseService should now have a reference to the new bind
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // Bar's RuntimeBindReleaseService reference to the bind should not exist
        assertFalse(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_BAR);
    try {
        store.rebind(name, value);
        // after rebind, Foo's RuntimeBindReleaseService reference to the bind should still exist
        assertTrue(fooDuBindingReferences.contains(serviceName));
        // after rebind, Bar's RuntimeBindReleaseService reference to the bind should now exist
        assertTrue(barDuBindingReferences.contains(serviceName));
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.unbind(name);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Example 2 with RuntimeBindReleaseService

use of org.jboss.as.naming.deployment.RuntimeBindReleaseService in project wildfly by wildfly.

the class WritableServiceBasedNamingStoreTestCase method installOwnerService.

private void installOwnerService(ServiceName owner) throws InterruptedException {
    final CountDownLatch latch1 = new CountDownLatch(1);
    container.addService(JndiNamingDependencyProcessor.serviceName(owner), new RuntimeBindReleaseService()).setInitialMode(ServiceController.Mode.ACTIVE).addListener(new AbstractServiceListener<Object>() {

        public void transition(ServiceController<?> controller, ServiceController.Transition transition) {
            switch(transition) {
                case STARTING_to_UP:
                    {
                        latch1.countDown();
                        break;
                    }
                case STARTING_to_START_FAILED:
                    {
                        latch1.countDown();
                        fail("Did not install store service - " + controller.getStartException().getMessage());
                        break;
                    }
                default:
                    break;
            }
        }
    }).install();
    latch1.await(10, TimeUnit.SECONDS);
}
Also used : AbstractServiceListener(org.jboss.msc.service.AbstractServiceListener) ServiceController(org.jboss.msc.service.ServiceController) CountDownLatch(java.util.concurrent.CountDownLatch) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService)

Example 3 with RuntimeBindReleaseService

use of org.jboss.as.naming.deployment.RuntimeBindReleaseService in project wildfly by wildfly.

the class WritableServiceBasedNamingStoreTestCase method testOwnerBindingReferences.

@Test
public void testOwnerBindingReferences() throws Exception {
    final Name name = new CompositeName("test");
    final ServiceName serviceName = store.buildServiceName(name);
    final Object value = new Object();
    // ensure bind does not exists
    try {
        store.lookup(name);
        fail("Should have thrown name not found");
    } catch (NameNotFoundException expect) {
    }
    final RuntimeBindReleaseService.References duBindingReferences = (RuntimeBindReleaseService.References) container.getService(JndiNamingDependencyProcessor.serviceName(OWNER_FOO)).getValue();
    WritableServiceBasedNamingStore.pushOwner(OWNER_FOO);
    try {
        store.bind(name, value);
        // Foo's RuntimeBindReleaseService should now have a reference to the new bind
        assertTrue(duBindingReferences.contains(serviceName));
        store.rebind(name, value);
        // after rebind, Foo's RuntimeBindReleaseService should continue to have a reference to the bind
        assertTrue(duBindingReferences.contains(serviceName));
        store.unbind(name);
    } finally {
        WritableServiceBasedNamingStore.popOwner();
    }
}
Also used : ServiceName(org.jboss.msc.service.ServiceName) NameNotFoundException(javax.naming.NameNotFoundException) CompositeName(javax.naming.CompositeName) RuntimeBindReleaseService(org.jboss.as.naming.deployment.RuntimeBindReleaseService) CompositeName(javax.naming.CompositeName) Name(javax.naming.Name) ServiceName(org.jboss.msc.service.ServiceName) Test(org.junit.Test)

Aggregations

RuntimeBindReleaseService (org.jboss.as.naming.deployment.RuntimeBindReleaseService)3 CompositeName (javax.naming.CompositeName)2 Name (javax.naming.Name)2 NameNotFoundException (javax.naming.NameNotFoundException)2 ServiceName (org.jboss.msc.service.ServiceName)2 Test (org.junit.Test)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AbstractServiceListener (org.jboss.msc.service.AbstractServiceListener)1 ServiceController (org.jboss.msc.service.ServiceController)1