1 22 package org.jboss.test.jca.test; 23 24 import org.jboss.test.JBossTestCase; 25 import org.jboss.test.jca.interfaces.HAConnectionSessionHome; 26 import org.jboss.resource.adapter.jdbc.local.HALocalManagedConnectionFactory; 27 28 import java.util.Arrays ; 29 30 import junit.framework.Test; 31 32 33 37 public class HAConnectionFactoryUnitTestCase 38 extends JBossTestCase 39 { 40 45 public HAConnectionFactoryUnitTestCase(String name) 46 { 47 super(name); 48 } 49 50 public static Test suite() throws Exception 51 { 52 Test t; 53 t = getDeploySetup(HAConnectionFactoryUnitTestCase.class, "jcatest.jar"); 54 t = getDeploySetup(t, "test-ha-ds.xml"); 55 t = getDeploySetup(t, "test-ha-xa-ds.xml"); 56 t = getDeploySetup(t, "jbosstestadapter.rar"); 57 58 return t; 65 } 66 67 public void testFailoverLocalMCF() throws Exception 68 { 69 HAConnectionSessionHome home = (HAConnectionSessionHome)getInitialContext().lookup("HAConnectionSession"); 70 home.create().testHaLocalConnection(); 71 } 72 73 public void testFailoverXaMCF() throws Exception 74 { 75 HAConnectionSessionHome home = (HAConnectionSessionHome)getInitialContext().lookup("HAConnectionSession"); 76 home.create().testHaXaConnection(); 77 } 78 79 public void testURLSelector() throws Exception 80 { 81 Object [] urls = new Object []{"url1", "url2", "url3"}; 82 HALocalManagedConnectionFactory.URLSelector selector = new HALocalManagedConnectionFactory.URLSelector( 83 Arrays.asList(urls) 84 ); 85 86 String url = selector.getUrl(); 87 assertEquals(urls[0], url); 88 url = selector.getUrl(); 89 assertEquals(urls[0], url); 90 url = selector.getUrl(); 91 assertEquals(urls[0], url); 92 93 selector.failedUrl(url); 94 url = selector.getUrl(); 95 assertEquals(urls[1], url); 96 url = selector.getUrl(); 97 assertEquals(urls[1], url); 98 99 selector.failedUrl(url); 100 url = selector.getUrl(); 101 assertEquals(urls[2], url); 102 url = selector.getUrl(); 103 assertEquals(urls[2], url); 104 105 for(int i = 0; i < 10; ++i) 106 { 107 selector.failedUrl(url); 108 url = selector.getUrl(); 109 assertEquals(urls[i % 3], url); 110 } 111 } 112 } 113 | Popular Tags |