protected void setUp() throws Exception { super.setUp(); for (final String configuration : CACHEONIX_CONFIGURATIONS) { final Cacheonix manager = Cacheonix.getInstance(TestUtils.getTestFile(configuration).toString()); cacheonixList.add(manager); } // Let the cluster form Thread.sleep(1000L); }
public void setUp() throws Exception { super.setUp(); final ConfigurationReader configurationReader = new ConfigurationReader(); final String configurationPath = TestUtils.getTestFile("cacheonix-config-DataSourceConfigurationTest.xml") .getCanonicalPath(); final CacheonixConfiguration configuration = configurationReader.readConfiguration(configurationPath); local = configuration.getLocal(); }
public void testParseCacheonixLocal() throws ParserConfigurationException, IOException, SAXException { // Parse final Document document; final InputStream testFileInputStream = TestUtils.getTestFileInputStream("new-config-example-local.xml"); try { document = parse(testFileInputStream); } finally { IOUtils.closeHard(testFileInputStream); } assertNotNull(document); }
/** * Tests that server configuration auto-creates a cache member. * * @throws Exception if an unexpected error occurred. */ public void testServerCreatesCache() throws Exception { // Startup caches final List<Cacheonix> cacheManagerList = new ArrayList<Cacheonix>(5); try { for (int i = 0; i < NODE_COUNT; i++) { final String configurationPath = TestUtils.getTestFile(NODE_CONFIGURATIONS[i]).toString(); cacheManagerList.add(Cacheonix.getInstance(configurationPath)); } // Wait for cluster to stabilize //noinspection ControlFlowStatementWithoutBraces if (LOG.isDebugEnabled()) LOG.debug("======= Begin waiting for a cache processor to create ======= "); // NOPMD final Timeout timeoutForOwnersToArrive = new Timeout(10000L).reset(); while (!timeoutForOwnersToArrive.isExpired() && cacheManagerList.get(0).getCache(DISTRIBUTED_CACHE_NAME).getKeyOwners().size() != NODE_COUNT) { Thread.sleep(100L); } //noinspection ControlFlowStatementWithoutBraces if (LOG.isDebugEnabled()) LOG.debug("======= End waiting for a cache processor to create ======= "); // NOPMD // Assert key owners size - should be number of configs though // the server configuration does not define the named node. assertEquals( NODE_COUNT, cacheManagerList.get(0).getCache(DISTRIBUTED_CACHE_NAME).getKeyOwners().size()); } catch (final Exception e) { LOG.error(e, e); throw e; } finally { // Shutdown caches for (final Cacheonix cacheonix : cacheManagerList) { cacheonix.shutdown(ShutdownMode.GRACEFUL_SHUTDOWN, true); } cacheManagerList.clear(); } }
/** Tester for ReleaseLockRequest. */ public class ReleaseLockRequestTest extends CacheonixTestCase { private static final String TEST_LOCK = "test.lock"; private static final String TEST_LOCK_REGION = "test.lock.region"; private ReleaseLockRequest request; private int threadID; private String threadName; private static final boolean READ_LOCK = false; private static final ClusterNodeAddress OWNER_ADDRESS = TestUtils.createTestAddress(1); public void testToString() throws Exception { assertNotNull(request.toString()); } /** Tests that no exceptions occur when creating the object using a default constructor. */ public void testDefaultConstructor() { assertNotNull(new ReleaseLockRequest().toString()); } public void testHashCode() throws IOException, ClassNotFoundException { assertTrue(request.hashCode() != 0); } public void testSerializeDeserialize() throws IOException, ClassNotFoundException { final Serializer ser = SerializerFactory.getInstance().getSerializer(Serializer.TYPE_JAVA); assertEquals(request, ser.deserialize(ser.serialize(request))); } public void testGetReceiver() { assertFalse(request.isReceiverSet()); } public void testGetThreadName() { assertEquals(threadName, request.getOwnerThreadName()); } public void testGetThreadID() { assertEquals(threadID, request.getOwnerThreadID()); } public void testGetLockKey() { assertEquals(TEST_LOCK_REGION, request.getLockRegionName()); } public void testGetLockRegion() { assertEquals(toBinary(TEST_LOCK), request.getLockKey()); } public void testGetWireableType() { assertEquals(Wireable.TYPE_RELEASE_LOCK_REQUEST, request.getWireableType()); } public void testIsReadLock() { assertEquals(READ_LOCK, request.isReadLock()); } protected void setUp() throws Exception { super.setUp(); final Thread currentThread = Thread.currentThread(); threadID = System.identityHashCode(currentThread); threadName = currentThread.getName(); request = new ReleaseLockRequest( TEST_LOCK_REGION, toBinary(TEST_LOCK), OWNER_ADDRESS, threadID, threadName, READ_LOCK); request.setSender(OWNER_ADDRESS); } }