StaticIdentitySequenceNumberService extends AbstractJdbcSequenceNumberService { public void setIdentity(String id) { identity = id; }  String getIdentity(); void setIdentity(String id);  }
@Test public void testService_NullIdentity_Overflows() throws Exception { try { StaticIdentitySequenceNumberService service = createServiceForTests(); service.setResetStatement(NULL_RESET_STATEMENT); service.setInsertStatement(NULL_INSERT_STATEMENT); service.setUpdateStatement(NULL_UPDATE_STATEMENT); service.setSelectStatement(NULL_SELECT_STATEMENT); service.setIdentity(null); createDatabase(); populateDatabase("abc", 10000); AdaptrisMessage msg = createMessageForTests(); service.setNumberFormat("0000"); service.setOverflowBehaviour(AbstractJdbcSequenceNumberService.OverflowBehaviour.Continue); execute(service, msg); assertTrue(msg.containsKey(DEFAULT_METADATA_KEY)); assertEquals("10000", msg.getMetadataValue(DEFAULT_METADATA_KEY)); assertEquals(10001, getCurrentSequenceNumber("abc")); } finally { } }
@Test public void testService_NullIdentity_Insert() throws Exception { try { createDatabase(); AdaptrisMessage msg = createMessageForTests(); StaticIdentitySequenceNumberService service = createServiceForTests(); service.setResetStatement(NULL_RESET_STATEMENT); service.setInsertStatement(NULL_INSERT_STATEMENT); service.setUpdateStatement(NULL_UPDATE_STATEMENT); service.setSelectStatement(NULL_SELECT_STATEMENT); service.setIdentity(null); service.setAlwaysReplaceMetadata(true); execute(service, msg); assertTrue(msg.containsKey(DEFAULT_METADATA_KEY)); assertEquals("000000001", msg.getMetadataValue(DEFAULT_METADATA_KEY)); assertEquals(2, getCurrentSequenceNumber("abc")); } finally { } }
@Test public void testService_NullIdentity_SelectUpdate() throws Exception { try { StaticIdentitySequenceNumberService service = createServiceForTests(); service.setIdentity(null); service.setResetStatement(NULL_RESET_STATEMENT); service.setInsertStatement(NULL_INSERT_STATEMENT); service.setUpdateStatement(NULL_UPDATE_STATEMENT); service.setSelectStatement(NULL_SELECT_STATEMENT); createDatabase(); populateDatabase("abc", 15); AdaptrisMessage msg = createMessageForTests(); execute(service, msg); assertTrue(msg.containsKey(DEFAULT_METADATA_KEY)); assertEquals("000000015", msg.getMetadataValue(DEFAULT_METADATA_KEY)); assertEquals(16, getCurrentSequenceNumber("abc")); } finally { } }
@Test public void testService_NullIdentity_DefaultStatements() throws Exception { try { createDatabase(); AdaptrisMessage msg = createMessageForTests(); StaticIdentitySequenceNumberService service = createServiceForTests(); service.setIdentity(null); execute(service, msg); fail(); } catch (ServiceException expected) { } finally { } }
@Test public void testService_PooledConnection() throws Exception { int maxServices = 5; final int iterations = 5; int poolsize = maxServices - 1; createDatabase(); List<Service> serviceList = new ArrayList<Service>(); String name = Thread.currentThread().getName(); Thread.currentThread().setName(getName()); JdbcPooledConnection conn = PooledConnectionHelper.createPooledConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), poolsize); try { for (int i = 0; i < maxServices; i++) { StaticIdentitySequenceNumberService service = createServiceForTests(false); service.setConnection(conn); service.setIdentity(new GuidGenerator().safeUUID()); serviceList.add(service); start(service); } PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() { @Override public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception { return createMessageForTests(); } }); assertEquals(0, conn.currentBusyConnectionCount()); assertEquals(poolsize, conn.currentIdleConnectionCount()); assertEquals(poolsize, conn.currentConnectionCount()); } finally { stop(serviceList.toArray(new ComponentLifecycle[0])); Thread.currentThread().setName(name); } }
@Test public void testService_AdvancedPooledConnection() throws Exception { int maxServices = 5; final int iterations = 5; int poolsize = maxServices - 1; createDatabase(); List<Service> serviceList = new ArrayList<Service>(); String name = Thread.currentThread().getName(); Thread.currentThread().setName(getName()); AdvancedJdbcPooledConnection conn = PooledConnectionHelper.createAdvancedPooledConnection(PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_DRIVER), PROPERTIES.getProperty(JDBC_SEQUENCENUMBER_URL), poolsize); try { for (int i = 0; i < maxServices; i++) { StaticIdentitySequenceNumberService service = createServiceForTests(false); service.setConnection(conn); service.setIdentity(new GuidGenerator().safeUUID()); serviceList.add(service); start(service); } PooledConnectionHelper.executeTest(serviceList, iterations, new PooledConnectionHelper.MessageCreator() { @Override public AdaptrisMessage createMsgForPooledConnectionTest() throws Exception { return createMessageForTests(); } }); assertEquals(0, conn.currentBusyConnectionCount()); assertEquals(poolsize, conn.currentIdleConnectionCount()); assertEquals(poolsize, conn.currentConnectionCount()); } finally { stop(serviceList.toArray(new ComponentLifecycle[0])); Thread.currentThread().setName(name); } }