PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/tier/sockets/RedundancyLevelPart3DUnitTest.java

https://gitlab.com/kidaa/incubator-geode
Java | 239 lines | 192 code | 11 blank | 36 comment | 7 complexity | cfb1dce0d91111155369af66f7058418 MD5 | raw file
  1. /*=========================================================================
  2. * Copyright (c) 2010-2014 Pivotal Software, Inc. All Rights Reserved.
  3. * This product is protected by U.S. and international copyright
  4. * and intellectual property laws. Pivotal products are covered by
  5. * one or more patents listed at http://www.pivotal.io/patents.
  6. *=========================================================================
  7. */
  8. package com.gemstone.gemfire.internal.cache.tier.sockets;
  9. import com.gemstone.gemfire.internal.cache.BridgeObserverAdapter;
  10. import com.gemstone.gemfire.internal.cache.BridgeObserverHolder;
  11. import com.gemstone.gemfire.cache.client.internal.PoolImpl;
  12. import dunit.DistributedTestCase;
  13. import dunit.Host;
  14. /**
  15. * Tests Redundancy Level Functionality
  16. *
  17. * @author Suyog Bhokare
  18. *
  19. */
  20. public class RedundancyLevelPart3DUnitTest extends RedundancyLevelTestBase
  21. {
  22. /** constructor */
  23. public RedundancyLevelPart3DUnitTest(String name) {
  24. super(name);
  25. }
  26. public static void caseSetUp() throws Exception {
  27. DistributedTestCase.disconnectAllFromDS();
  28. }
  29. /**
  30. * This tests failing of a primary server in a situation where teh rest of the server are all redundant.
  31. * After every failure, the order, the dispatcher, the interest registration and the makePrimary calls
  32. * are verified. The failure detection in these tests could be either through CCU or cache operation,
  33. * whichever occurs first
  34. *
  35. */
  36. public void testRegisterInterestAndMakePrimaryWithFullRedundancy()
  37. {
  38. try {
  39. CacheServerTestUtil.disableShufflingOfEndpoints();
  40. createClientCache(getServerHostName(Host.getHost(0)), PORT1, PORT2, PORT3, PORT4, 3);
  41. createEntriesK1andK2();
  42. registerK1AndK2();
  43. assertEquals(3, pool.getRedundantNames().size());
  44. server0.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  45. server1.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsNotAlive");
  46. server2.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsNotAlive");
  47. server3.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsNotAlive");
  48. server0.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  49. server1.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  50. server2.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  51. server3.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  52. PoolImpl.BEFORE_REGISTER_CALLBACK_FLAG = true;
  53. PoolImpl.BEFORE_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = true;
  54. PoolImpl.BEFORE_RECOVER_INTEREST_CALLBACK_FLAG = true;
  55. registerInterestCalled = false;
  56. makePrimaryCalled = false;
  57. BridgeObserverHolder.setInstance(new BridgeObserverAdapter() {
  58. public void beforeInterestRegistration()
  59. {
  60. registerInterestCalled = true;
  61. }
  62. public void beforeInterestRecovery()
  63. {
  64. registerInterestCalled = true;
  65. }
  66. public void beforePrimaryIdentificationFromBackup()
  67. {
  68. makePrimaryCalled = true;
  69. }
  70. });
  71. server0.invoke(RedundancyLevelTestBase.class, "stopServer");
  72. doPuts();
  73. server1.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  74. server2.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsNotAlive");
  75. server3.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsNotAlive");
  76. verifyLiveAndRedundantServers(3, 2);
  77. if(registerInterestCalled){
  78. fail("register interest should not have been called since we failed to a redundant server !");
  79. }
  80. if(!makePrimaryCalled){
  81. fail("make primary should have been called since primary did fail and a new primary was to be chosen ");
  82. }
  83. assertEquals(2, pool.getRedundantNames().size());
  84. makePrimaryCalled = false;
  85. server1.invoke(RedundancyLevelTestBase.class, "stopServer");
  86. doPuts();
  87. server2.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  88. server3.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsNotAlive");
  89. verifyLiveAndRedundantServers(2, 1);
  90. if(registerInterestCalled){
  91. fail("register interest should not have been called since we failed to a redundant server !");
  92. }
  93. if(!makePrimaryCalled){
  94. fail("make primary should have been called since primary did fail and a new primary was to be chosen ");
  95. }
  96. assertEquals(1, pool.getRedundantNames().size());
  97. makePrimaryCalled = false;
  98. server2.invoke(RedundancyLevelTestBase.class, "stopServer");
  99. doPuts();
  100. server3.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  101. verifyLiveAndRedundantServers(1, 0);
  102. if(registerInterestCalled){
  103. fail("register interest should not have been called since we failed to a redundant server !");
  104. }
  105. if(!makePrimaryCalled){
  106. fail("make primary should have been called since primary did fail and a new primary was to be chosen ");
  107. }
  108. assertEquals(0, pool.getRedundantNames().size());
  109. server3.invoke(RedundancyLevelTestBase.class, "stopServer");
  110. server0.invoke(RedundancyLevelTestBase.class, "startServer");
  111. doPuts();
  112. server0.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  113. server0.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  114. verifyLiveAndRedundantServers(1, 0);
  115. if(!registerInterestCalled){
  116. fail("register interest should have been called since a recovered server came up!");
  117. }
  118. assertEquals(0, pool.getRedundantNames().size());
  119. PoolImpl.BEFORE_REGISTER_CALLBACK_FLAG = false;
  120. PoolImpl.BEFORE_PRIMARY_IDENTIFICATION_FROM_BACKUP_CALLBACK_FLAG = false;
  121. PoolImpl.BEFORE_RECOVER_INTEREST_CALLBACK_FLAG = false;
  122. }
  123. catch (Exception ex) {
  124. ex.printStackTrace();
  125. fail(
  126. "test failed due to exception in test testRedundancySpecifiedMoreThanEPs ",
  127. ex);
  128. }
  129. }
  130. /**
  131. * This tests failing of a primary server in a situation where the rest of the server are all non redundant.
  132. * After every failure, the order, the dispatcher, the interest registration and the makePrimary calls
  133. * are verified. The failure detection in these tests could be either through CCU or cache operation,
  134. * whichever occurs first
  135. *
  136. */
  137. public void testRegisterInterestAndMakePrimaryWithZeroRedundancy()
  138. {
  139. try {
  140. CacheServerTestUtil.disableShufflingOfEndpoints();
  141. createClientCache(getServerHostName(Host.getHost(0)), PORT1, PORT2, PORT3, PORT4, 0);
  142. createEntriesK1andK2();
  143. registerK1AndK2();
  144. assertEquals(0, pool.getRedundantNames().size());
  145. server0.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  146. server0.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  147. server0.invoke(RedundancyLevelTestBase.class, "stopServer");
  148. doPuts();
  149. server1.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  150. server1.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  151. verifyLiveAndRedundantServers(3, 0);
  152. assertEquals(0, pool.getRedundantNames().size());
  153. server1.invoke(RedundancyLevelTestBase.class, "stopServer");
  154. doPuts();
  155. server2.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  156. server2.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  157. verifyLiveAndRedundantServers(2, 0);
  158. assertEquals(0, pool.getRedundantNames().size());
  159. server2.invoke(RedundancyLevelTestBase.class, "stopServer");
  160. doPuts();
  161. server3.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  162. server3.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  163. verifyLiveAndRedundantServers(1, 0);
  164. assertEquals(0, pool.getRedundantNames().size());
  165. server3.invoke(RedundancyLevelTestBase.class, "stopServer");
  166. server0.invoke(RedundancyLevelTestBase.class, "startServer");
  167. doPuts();
  168. server0.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  169. server0.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  170. verifyLiveAndRedundantServers(1, 0);
  171. assertEquals(0, pool.getRedundantNames().size());
  172. }
  173. catch (Exception ex) {
  174. ex.printStackTrace();
  175. fail(
  176. "test failed due to exception in test testRedundancySpecifiedMoreThanEPs ",
  177. ex);
  178. }
  179. }
  180. /**
  181. * This tests failing of a primary server in a situation where only one of the rest of teh servers is redundant.
  182. * After every failure, the order, the dispatcher, the interest registration and the makePrimary calls
  183. * are verified. The failure detection in these tests could be either through CCU or cache operation,
  184. * whichever occurs first
  185. *
  186. */
  187. public void testRegisterInterestAndMakePrimaryWithRedundancyOne()
  188. {
  189. try {
  190. // long maxWaitTime = 60000;
  191. CacheServerTestUtil.disableShufflingOfEndpoints();
  192. createClientCache(getServerHostName(Host.getHost(0)), PORT1, PORT2, PORT3, PORT4, 1);
  193. createEntriesK1andK2();
  194. registerK1AndK2();
  195. assertEquals(1, pool.getRedundantNames().size());
  196. server0.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  197. server0.invoke(RedundancyLevelTestBase.class, "stopServer");
  198. doPuts();
  199. server1.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  200. server2.invoke(RedundancyLevelTestBase.class, "verifyCCP");
  201. server2.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  202. verifyLiveAndRedundantServers(3, 1);
  203. assertEquals(1, pool.getRedundantNames().size());
  204. server1.invoke(RedundancyLevelTestBase.class, "stopServer");
  205. doPuts();
  206. server2.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  207. server2.invoke(RedundancyLevelTestBase.class, "stopServer");
  208. doPuts();
  209. server3.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  210. server3.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  211. verifyLiveAndRedundantServers(1, 0);
  212. assertEquals(0, pool.getRedundantNames().size());
  213. server3.invoke(RedundancyLevelTestBase.class, "stopServer");
  214. server0.invoke(RedundancyLevelTestBase.class, "startServer");
  215. doPuts();
  216. server0.invoke(RedundancyLevelTestBase.class, "verifyDispatcherIsAlive");
  217. server0.invoke(RedundancyLevelTestBase.class, "verifyInterestRegistration");
  218. verifyLiveAndRedundantServers(1, 0);
  219. assertEquals(0, pool.getRedundantNames().size());
  220. }
  221. catch (Exception ex) {
  222. ex.printStackTrace();
  223. fail(
  224. "test failed due to exception in test testRedundancySpecifiedMoreThanEPs ",
  225. ex);
  226. }
  227. }
  228. }