001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package org.apache.geronimo.openejb.cluster.infra;
021:
022: import java.net.URI;
023: import java.util.Collections;
024: import java.util.Set;
025:
026: import junit.framework.TestCase;
027:
028: /**
029: *
030: * @version $Rev:$ $Date:$
031: */
032: public class BasicNetworkConnectorTrackerTest extends TestCase {
033:
034: public void testRegistration() throws Exception {
035: BasicNetworkConnectorTracker tracker = new BasicNetworkConnectorTracker();
036: String deploymentId = "deploymentId";
037:
038: URI uri1 = new URI("uri1");
039: tracker.registerNetworkConnectorLocations(deploymentId,
040: "nodeName", Collections.singleton(uri1));
041: Set<URI> connectorURIs = tracker.getConnectorURIs(deploymentId);
042: assertEquals(1, connectorURIs.size());
043: assertTrue(connectorURIs.contains(uri1));
044:
045: URI uri2 = new URI("uri2");
046: tracker.registerNetworkConnectorLocations(deploymentId,
047: "nodeName2", Collections.singleton(uri2));
048: connectorURIs = tracker.getConnectorURIs(deploymentId);
049: assertEquals(2, connectorURIs.size());
050: assertTrue(connectorURIs.contains(uri1));
051: assertTrue(connectorURIs.contains(uri2));
052: }
053:
054: public void testUnregistration() throws Exception {
055: BasicNetworkConnectorTracker tracker = new BasicNetworkConnectorTracker();
056: String deploymentId = "deploymentId";
057:
058: URI uri1 = new URI("uri1");
059: URI uri2 = new URI("uri2");
060: tracker.registerNetworkConnectorLocations(deploymentId,
061: "nodeName", Collections.singleton(uri1));
062: tracker.registerNetworkConnectorLocations(deploymentId,
063: "nodeName", Collections.singleton(uri2));
064: tracker.unregisterNetworkConnectorLocations(deploymentId,
065: "nodeName", Collections.singleton(uri2));
066: Set<URI> connectorURIs = tracker.getConnectorURIs(deploymentId);
067: assertEquals(1, connectorURIs.size());
068: assertTrue(connectorURIs.contains(uri1));
069: }
070:
071: public void testUnregistrationForAllURIs() throws Exception {
072: BasicNetworkConnectorTracker tracker = new BasicNetworkConnectorTracker();
073: String deploymentId = "deploymentId";
074:
075: URI uri1 = new URI("uri1");
076: tracker.registerNetworkConnectorLocations(deploymentId,
077: "nodeName", Collections.singleton(uri1));
078: tracker.unregisterNetworkConnectorLocations(deploymentId,
079: "nodeName", Collections.singleton(uri1));
080: try {
081: tracker.getConnectorURIs(deploymentId);
082: fail();
083: } catch (NetworkConnectorTrackerException e) {
084: }
085: }
086:
087: public void testUnregistrationForNode() throws Exception {
088: BasicNetworkConnectorTracker tracker = new BasicNetworkConnectorTracker();
089: String deploymentId = "deploymentId";
090:
091: URI uri1 = new URI("uri1");
092: tracker.registerNetworkConnectorLocations(deploymentId,
093: "nodeName", Collections.singleton(uri1));
094: tracker.unregisterNetworkConnectorLocations("nodeName");
095: try {
096: tracker.getConnectorURIs(deploymentId);
097: fail();
098: } catch (NetworkConnectorTrackerException e) {
099: }
100: }
101:
102: public void testGetConnectorURIsThrowsNCEWhenNoURIsForDeploymentId()
103: throws Exception {
104: BasicNetworkConnectorTracker tracker = new BasicNetworkConnectorTracker();
105: try {
106: tracker.getConnectorURIs("deploymentId");
107: fail();
108: } catch (NetworkConnectorTrackerException e) {
109: }
110: }
111:
112: }
|