本文整理汇总了Java中com.ibm.as400.access.AS400.resetAllServices方法的典型用法代码示例。如果您正苦于以下问题:Java AS400.resetAllServices方法的具体用法?Java AS400.resetAllServices怎么用?Java AS400.resetAllServices使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.ibm.as400.access.AS400
的用法示例。
在下文中一共展示了AS400.resetAllServices方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConnectTimeout
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testConnectTimeout() throws Exception
{
As400OriginDataSource ds = new As400OriginDataSource();
ds.setProperty(As400DataSource.USERNAME, "username");
ds.setProperty(As400DataSource.PASSWORD, "password");
ds.setProperty(As400DataSource.HOSTNAME, "10.254.254.254");
AS400 conn = null;
ds.setProperty(As400DataSource.CONNECT_TIMEOUT, "1"); // set to one second
long start = System.nanoTime();
try {
conn = ds.getConnection();
fail("Data Source getConnection should not have had sufficient time to connect");
} catch(DataSourceException de) {
long end = System.nanoTime();
assertEquals("connection.timedout", de.getMessage());
assertTrue(SECONDS.convert((end - start), NANOSECONDS) < 2);
} finally {
if(conn != null) conn.resetAllServices();
}
}
示例2: testAvailable
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testAvailable() throws Exception
{
As400OriginDataSource ds = new As400OriginDataSource();
ds.setProperty(As400DataSource.USERNAME, "username");
ds.setProperty(As400DataSource.PASSWORD, "password");
ds.setProperty(As400DataSource.HOSTNAME, "unknown.man.cox.com");
AS400 conn = null;
try {
conn = ds.getConnection();
} catch(Exception e) {
assertEquals("Should have received a connect failure", "connect.failure", e.getMessage());
assertFalse("Datasource should not be available after conn failure", ds.isAvailable());
} finally {
if(conn != null) conn.resetAllServices();
}
ds.close();
}
示例3: testCreateDateAndLastAccessDate
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testCreateDateAndLastAccessDate() throws Exception
{
As400OriginDataSource origin = createOriginDataSource();
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
Assert.assertTrue("Dates don't match", ds.getCreateDate().equals(ds.getLastAccessDate()));
ThreadUtils.sleep(100); // java system clock only has resolution of 20ms
AS400 conn = null;
try {
conn = ds.getConnection();
} finally {
if(conn != null) conn.resetAllServices();
}
assertFalse("Dates match", ds.getCreateDate().equals(ds.getLastAccessDate()));
Assert.assertTrue("Dates wrong", ds.getCreateDate().before(ds.getLastAccessDate()));
} finally {
ds.close();
}
}
示例4: testMaxLife
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testMaxLife() throws Exception
{
As400OriginDataSource origin = createOriginDataSource();
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.MAX_LIFE_TIME, "1");
AS400 conn = null;
try {
conn = ds.getConnection();
assertEquals("Active count is wrong", 1, ds.getActiveCount());
assertEquals("Busy count is wrong", 1, ds.getBusyCount());
assertEquals("Idle count is wrong", 0, ds.getIdleCount());
ThreadUtils.sleep(1500);
} finally {
if(conn != null) conn.resetAllServices();
}
assertEquals("Active count is wrong", 0, ds.getActiveCount());
assertEquals("Busy count is wrong", 0, ds.getBusyCount());
assertEquals("Idle count is wrong", 0, ds.getIdleCount());
} finally {
ds.close();
}
assertEquals("Expected the pool to be empty", 0, ds.getActiveCount());
}
示例5: testMaxIdle
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testMaxIdle() throws Exception
{
As400OriginDataSource origin = createOriginDataSource();
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.MAX_IDLE, "1");
assertEquals("Expected different value for property max-idle", "1", ds.getProperty(PoolingDataSource.MAX_IDLE));
AS400 one = null;
AS400 two = null;
try {
one = ds.getConnection();
two = ds.getConnection();
assertEquals("Active count is wrong", 2, ds.getActiveCount());
assertEquals("Busy count is wrong", 2, ds.getBusyCount());
assertEquals("Idle count is wrong", 0, ds.getIdleCount());
} catch(DataSourceException de) {
assertContains(de.getMessage(), "exhausted", true);
} finally {
if(one != null) one.resetAllServices();
if(two != null) two.resetAllServices();
}
assertEquals("Active count is wrong", 1, ds.getActiveCount());
assertEquals("Busy count is wrong", 0, ds.getBusyCount());
assertEquals("Idle count is wrong", 1, ds.getIdleCount());
} finally {
ds.close();
}
assertEquals("Expected the pool to be empty", 0, ds.getActiveCount());
}
示例6: testOnReturn
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testOnReturn() throws Exception
{
PooledAs400 connOne = mock(PooledAs400.class);
doCallRealMethod().when(connOne).resetAllServices();
doCallRealMethod().when(connOne).setResource(any(PooledResource.class));
when(connOne.isConnected()).thenReturn(true);
when(origin.getConnection()).thenReturn(connOne);
when(origin.isAvailable()).thenReturn(true);
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.TEST_SCHEME, PoolingDataSource.TestScheme.Return.toString());
AS400 conn = null;
try {
conn = ds.getConnection();
verify(connOne, times(0)).connectService(eq(AS400.SIGNON));
assertEquals("Active count is wrong", 1, ds.getActiveCount());
assertEquals("Busy count is wrong", 1, ds.getBusyCount());
assertEquals("Idle count is wrong", 0, ds.getIdleCount());
} finally {
if(conn != null) conn.resetAllServices();
}
verify(connOne, times(1)).connectService(eq(AS400.SIGNON));
assertEquals("Active count is wrong", 1, ds.getActiveCount());
assertEquals("Busy count is wrong", 0, ds.getBusyCount());
assertEquals("Idle count is wrong", 1, ds.getIdleCount());
} finally {
ds.close();
}
}
示例7: testOnReturnWithError
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testOnReturnWithError() throws Exception
{
PooledAs400 connOne = mock(PooledAs400.class);
doCallRealMethod().when(connOne).resetAllServices();
doCallRealMethod().when(connOne).setResource(any(PooledResource.class));
when(connOne.isConnected()).thenReturn(true);
doThrow(new IOException()).when(connOne).connectService(anyInt());
when(origin.getConnection()).thenReturn(connOne);
when(origin.isAvailable()).thenReturn(true);
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.TEST_SCHEME, PoolingDataSource.TestScheme.Return.toString());
AS400 conn = null;
try {
conn = ds.getConnection();
verify(connOne, times(0)).connectService(eq(AS400.SIGNON));
assertEquals("Active count is wrong", 1, ds.getActiveCount());
assertEquals("Busy count is wrong", 1, ds.getBusyCount());
assertEquals("Idle count is wrong", 0, ds.getIdleCount());
} finally {
if(conn != null) conn.resetAllServices();
}
verify(connOne, times(1)).connectService(eq(AS400.SIGNON));
assertEquals("Active count is wrong", 0, ds.getActiveCount());
assertEquals("Busy count is wrong", 0, ds.getBusyCount());
assertEquals("Idle count is wrong", 0, ds.getIdleCount());
} finally {
ds.close();
}
}
示例8: testOnBorrow
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testOnBorrow() throws Exception
{
PooledAs400 connOne = mock(PooledAs400.class);
doCallRealMethod().when(connOne).resetAllServices();
doCallRealMethod().when(connOne).setResource(any(PooledResource.class));
when(connOne.isConnected()).thenReturn(true);
when(origin.getConnection()).thenReturn(connOne);
when(origin.isAvailable()).thenReturn(true);
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.TEST_SCHEME, PoolingDataSource.TestScheme.Borrow.toString());
AS400 conn = null;
try {
conn = ds.getConnection();
verify(connOne, times(1)).connectService(eq(AS400.SIGNON));
} finally {
if(conn != null) conn.resetAllServices();
}
verify(connOne, times(1)).connectService(eq(AS400.SIGNON));
assertEquals("Active count is wrong", 1, ds.getActiveCount());
assertEquals("Busy count is wrong", 0, ds.getBusyCount());
assertEquals("Idle count is wrong", 1, ds.getIdleCount());
} finally {
ds.close();
}
}
示例9: testOnBorrowWithErrorAvoidInfiniteLoop
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test(expected = DataSourceException.class)
public void testOnBorrowWithErrorAvoidInfiniteLoop() throws Exception
{
PooledAs400 connOne = mock(PooledAs400.class);
doCallRealMethod().when(connOne).resetAllServices();
doCallRealMethod().when(connOne).setResource(any(PooledResource.class));
when(connOne.isConnected()).thenReturn(true);
doThrow(new IOException()).when(connOne).connectService(anyInt());
when(origin.getConnection()).thenReturn(connOne);
when(origin.isAvailable()).thenReturn(true);
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.TEST_SCHEME, PoolingDataSource.TestScheme.Borrow.toString());
AS400 conn = null;
try {
conn = ds.getConnection();
} finally {
if(conn != null) conn.resetAllServices();
}
} finally {
ds.close();
}
}
示例10: testAlways
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testAlways() throws Exception
{
PooledAs400 connOne = mock(PooledAs400.class);
doCallRealMethod().when(connOne).resetAllServices();
doCallRealMethod().when(connOne).setResource(any(PooledResource.class));
when(connOne.isConnected()).thenReturn(true);
when(origin.getConnection()).thenReturn(connOne);
when(origin.isAvailable()).thenReturn(true);
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.TEST_SCHEME, PoolingDataSource.TestScheme.Always.toString());
AS400 conn = null;
try {
conn = ds.getConnection();
verify(connOne, times(1)).connectService(eq(AS400.SIGNON));
} finally {
if(conn != null) conn.resetAllServices();
}
verify(connOne, times(2)).connectService(eq(AS400.SIGNON));
assertEquals("Active count is wrong", 1, ds.getActiveCount());
assertEquals("Busy count is wrong", 0, ds.getBusyCount());
assertEquals("Idle count is wrong", 1, ds.getIdleCount());
} finally {
ds.close();
}
}
示例11: testCacheHitRatio
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testCacheHitRatio() throws Exception
{
As400OriginDataSource origin = createOriginDataSource();
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.MAX_IDLE, "1");
ds.setProperty(PoolingDataSource.MIN_CONNECTIONS, "1");
assertEquals("Cache hit ratio is wrong", 0, ds.getCacheHitRatio());
AS400 connOne = null;
AS400 connTwo = null;
AS400 connThree = null;
try {
connOne = ds.getConnection();
assertEquals("Cache hit ratio is wrong", 100, ds.getCacheHitRatio()); // 1 for 1
connTwo = ds.getConnection();
assertEquals("Cache hit ratio is wrong", 50, ds.getCacheHitRatio()); // 1 for 2
connThree = ds.getConnection();
assertEquals("Cache hit ratio is wrong", 33, ds.getCacheHitRatio()); // 1 for 3
} finally {
if(connOne != null) connOne.resetAllServices();
if(connTwo != null) connTwo.resetAllServices();
if(connThree != null) connThree.resetAllServices();
}
} finally {
ds.close();
}
}
示例12: testMaxIdleWithSmallerMaxConnections
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testMaxIdleWithSmallerMaxConnections() throws Exception
{
As400OriginDataSource origin = createOriginDataSource();
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.MAX_IDLE, "15");
ds.setProperty(PoolingDataSource.MAX_CONNECTIONS, "2");
ds.setProperty(PoolingDataSource.MAX_WAIT_TIME, "500");
assertEquals("Expected different value for property max-connections", "2",
ds.getProperty(PoolingDataSource.MAX_CONNECTIONS));
assertEquals("Expected different value for property max-wait-time", "500", ds.getProperty(PoolingDataSource.MAX_WAIT_TIME));
assertEquals("Expected different value for property max-idle", "15",
ds.getProperty(PoolingDataSource.MAX_IDLE));
AS400 one = null;
AS400 two = null;
AS400 three = null;
try {
one = ds.getConnection();
two = ds.getConnection();
assertEquals("Active count is wrong", 2, ds.getActiveCount());
assertEquals("Busy count is wrong", 2, ds.getBusyCount());
assertEquals("Idle count is wrong", 0, ds.getIdleCount());
three = ds.getConnection();
fail();
} catch(DataSourceException de) {
assertContains(de.getMessage(), "exhausted", true);
} finally {
if(one != null) one.resetAllServices();
if(two != null) two.resetAllServices();
if(three != null) three.resetAllServices();
}
verify(origin, times(2)).getConnection();
assertEquals("Idle count is wrong", 2, ds.getIdleCount());
} finally {
ds.close();
}
assertEquals("Expected the pool to be empty", 0, ds.getActiveCount());
}
示例13: testOnBorrowWithError
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testOnBorrowWithError() throws Exception
{
PooledAs400 connOne = mock(PooledAs400.class);
doCallRealMethod().when(connOne).resetAllServices();
doCallRealMethod().when(connOne).setResource(any(PooledResource.class));
when(connOne.isConnected()).thenReturn(true);
doThrow(new IOException()).when(connOne).connectService(anyInt());
PooledAs400 connTwo = mock(PooledAs400.class);
doCallRealMethod().when(connTwo).resetAllServices();
doCallRealMethod().when(connTwo).setResource(any(PooledResource.class));
when(connTwo.isConnected()).thenReturn(true);
when(origin.getConnection()).thenReturn(connOne, connTwo);
when(origin.isAvailable()).thenReturn(true);
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.TEST_SCHEME, PoolingDataSource.TestScheme.Borrow.toString());
AS400 conn = null;
try {
conn = ds.getConnection();
verify(connOne, times(1)).connectService(eq(AS400.SIGNON));
verify(connTwo, times(1)).connectService(eq(AS400.SIGNON));
} finally {
if(conn != null) conn.resetAllServices();
}
verify(connOne, times(1)).connectService(eq(AS400.SIGNON));
verify(connTwo, times(1)).connectService(eq(AS400.SIGNON));
assertEquals("Active count is wrong", 1, ds.getActiveCount());
assertEquals("Busy count is wrong", 0, ds.getBusyCount());
assertEquals("Idle count is wrong", 1, ds.getIdleCount());
} finally {
ds.close();
}
}
示例14: testMaxConnectionsAndMaxWaitTime
import com.ibm.as400.access.AS400; //导入方法依赖的package包/类
@Test
public void testMaxConnectionsAndMaxWaitTime() throws Exception
{
As400OriginDataSource origin = createOriginDataSource();
As400PoolingDataSource ds = new As400PoolingDataSource(origin);
try {
ds.setProperty(PoolingDataSource.MAX_CONNECTIONS, "2");
ds.setProperty(PoolingDataSource.MAX_WAIT_TIME, "100");
assertEquals("Expected different value for property max-connections", "2",
ds.getProperty(PoolingDataSource.MAX_CONNECTIONS));
assertEquals("Expected different value for property max-wait-time", "100",
ds.getProperty(PoolingDataSource.MAX_WAIT_TIME));
AS400 connOne = null;
AS400 connTwo = null;
AS400 connThree = null;
try {
connOne = ds.getConnection();
connTwo = ds.getConnection();
assertEquals("Active count is wrong", 2, ds.getActiveCount());
assertEquals("Busy count is wrong", 2, ds.getBusyCount());
assertEquals("Idle count is wrong", 0, ds.getIdleCount());
connThree = ds.getConnection();
fail("Should not have gotten a thirds connection");
} catch(DataSourceException de) {
assertContains(de.getMessage(), "exhausted", true);
} finally {
if(connOne != null) connOne.resetAllServices();
if(connTwo != null) connTwo.resetAllServices();
if(connThree != null) connThree.resetAllServices();
}
assertEquals("Idle count is wrong", 2, ds.getIdleCount());
} finally {
ds.close();
}
assertEquals("Expected the pool to be empty", 0, ds.getActiveCount());
}