use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class DurableClientTestCase method setBridgeObeserverForAfterPrimaryRecovered.
public static void setBridgeObeserverForAfterPrimaryRecovered() {
DurableClientTestCase.isPrimaryRecovered = false;
PoolImpl.AFTER_PRIMARY_RECOVERED_CALLBACK_FLAG = true;
ClientServerObserver bo = ClientServerObserverHolder.setInstance(new ClientServerObserverAdapter() {
public void afterPrimaryRecovered(ServerLocation location) {
DurableClientTestCase.isPrimaryRecovered = true;
PoolImpl.AFTER_PRIMARY_RECOVERED_CALLBACK_FLAG = false;
}
});
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class HAStartupAndFailoverDUnitTest method createClientCacheWithLargeRetryIntervalAndWithoutCallbackConnection.
public static void createClientCacheWithLargeRetryIntervalAndWithoutCallbackConnection(String testName, String host) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new HAStartupAndFailoverDUnitTest().createCache(props);
CacheServerTestUtil.disableShufflingOfEndpoints();
PoolImpl p;
try {
p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1.intValue()).addServer(host, PORT2.intValue()).addServer(host, PORT3.intValue()).setPingInterval(500).create("HAStartupAndFailoverDUnitTestPool");
} finally {
CacheServerTestUtil.enableShufflingOfEndpoints();
}
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(p.getName());
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
pool = p;
// since the default minConnections is 1 we currently have a connection to
// server1 (vm_0). Now we create a connection to server2 (vm_1)
conn = pool.acquireConnection(new ServerLocation(Host.getHost(0).getHostName(), PORT2));
// assert that the conn is to server2 since the tests assume that this is so
assertNotNull(conn);
assertTrue(conn.getEndpoint().getLocation().getPort() == PORT2);
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class UniversalMembershipListenerAdapterDUnitTest method testNoDuplicates.
/**
* Tests use of history to prevent duplicate events.
*/
@Test
public void testNoDuplicates() throws Exception {
getSystem();
final boolean[] fired = new boolean[3];
final DistributedMember[] member = new DistributedMember[3];
final String[] memberId = new String[3];
UniversalMembershipListenerAdapter listener = new UniversalMembershipListenerAdapter() {
@Override
public synchronized void memberJoined(MembershipEvent event) {
assertFalse(fired[JOINED]);
assertNull(member[JOINED]);
assertNull(memberId[JOINED]);
fired[JOINED] = true;
member[JOINED] = event.getDistributedMember();
memberId[JOINED] = event.getMemberId();
notify();
}
@Override
public synchronized void memberLeft(MembershipEvent event) {
assertFalse(fired[LEFT]);
assertNull(member[LEFT]);
assertNull(memberId[LEFT]);
fired[LEFT] = true;
member[LEFT] = event.getDistributedMember();
memberId[LEFT] = event.getMemberId();
notify();
}
@Override
public synchronized void memberCrashed(MembershipEvent event) {
// assures no dupes
assertFalse(fired[CRASHED]);
assertNull(member[CRASHED]);
assertNull(memberId[CRASHED]);
fired[CRASHED] = true;
member[CRASHED] = event.getDistributedMember();
memberId[CRASHED] = event.getMemberId();
notify();
}
};
DistributedMember memberA = new TestDistributedMember("memberA");
ServerLocation serverA = new ServerLocation("serverA", 0);
// first join
InternalClientMembership.notifyClientJoined(memberA);
synchronized (listener) {
if (!fired[JOINED]) {
listener.wait(SYNC_ASYNC_EVENT_WAIT_MILLIS);
}
}
assertTrue(fired[JOINED]);
assertEquals(memberA, member[JOINED]);
assertEquals(memberA.getId(), memberId[JOINED]);
fired[JOINED] = false;
member[JOINED] = null;
memberId[JOINED] = null;
// duplicate join
InternalClientMembership.notifyClientJoined(memberA);
Wait.pause(BRIEF_PAUSE_MILLIS);
assertFalse(fired[JOINED]);
assertNull(member[JOINED]);
assertNull(memberId[JOINED]);
// first left
InternalClientMembership.notifyClientLeft(memberA);
synchronized (listener) {
if (!fired[LEFT]) {
listener.wait(SYNC_ASYNC_EVENT_WAIT_MILLIS);
}
}
assertTrue(fired[LEFT]);
assertEquals(memberA, member[LEFT]);
assertEquals(memberA.getId(), memberId[LEFT]);
fired[LEFT] = false;
member[LEFT] = null;
memberId[LEFT] = null;
// duplicate left
InternalClientMembership.notifyClientLeft(memberA);
Wait.pause(BRIEF_PAUSE_MILLIS);
assertFalse(fired[LEFT]);
assertNull(member[LEFT]);
assertNull(memberId[LEFT]);
// rejoin
InternalClientMembership.notifyClientJoined(memberA);
synchronized (listener) {
if (!fired[JOINED]) {
listener.wait(SYNC_ASYNC_EVENT_WAIT_MILLIS);
}
}
assertTrue(fired[JOINED]);
assertEquals(memberA, member[JOINED]);
assertEquals(memberA.getId(), memberId[JOINED]);
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class LocatorJUnitTest method testServerLocationOnDifferentHostsShouldNotTestEqual.
/**
* Make sure two ServerLocation objects on different hosts but with the same port are not equal
* <p/>
* TRAC #42040: LoadBalancing directs all traffic to a single cache server if all servers are
* started on the same port
*/
@Test
public void testServerLocationOnDifferentHostsShouldNotTestEqual() {
ServerLocation sl1 = new ServerLocation("host1", 777);
ServerLocation sl2 = new ServerLocation("host2", 777);
if (sl1.equals(sl2)) {
fail("ServerLocation instances on different hosts should not test equal");
}
}
use of org.apache.geode.distributed.internal.ServerLocation in project geode by apache.
the class SingleHopClientExecutor method submitGetAll.
static Map<ServerLocation, Object> submitGetAll(Map<ServerLocation, HashSet> serverToFilterMap, List callableTasks, ClientMetadataService cms, LocalRegion region) {
if (callableTasks != null && !callableTasks.isEmpty()) {
Map<ServerLocation, Object> resultMap = new HashMap<ServerLocation, Object>();
List futures = null;
try {
futures = execService.invokeAll(callableTasks);
} catch (RejectedExecutionException rejectedExecutionEx) {
throw rejectedExecutionEx;
} catch (InterruptedException e) {
throw new InternalGemFireException(e.getMessage());
}
if (futures != null) {
Iterator futureItr = futures.iterator();
Iterator taskItr = callableTasks.iterator();
while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
Future fut = (Future) futureItr.next();
SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
List keys = ((GetAllOpImpl) task.getOperation()).getKeyList();
ServerLocation server = task.getServer();
try {
VersionedObjectList valuesFromServer = (VersionedObjectList) fut.get();
valuesFromServer.setKeys(keys);
for (VersionedObjectList.Iterator it = valuesFromServer.iterator(); it.hasNext(); ) {
VersionedObjectList.Entry entry = it.next();
Object key = entry.getKey();
Object value = entry.getValue();
if (!entry.isKeyNotOnServer()) {
if (value instanceof Throwable) {
logger.warn(LocalizedMessage.create(LocalizedStrings.GetAll_0_CAUGHT_THE_FOLLOWING_EXCEPTION_ATTEMPTING_TO_GET_VALUE_FOR_KEY_1, new Object[] { value, key }), (Throwable) value);
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("GetAllOp#got result from {}: {}", server, valuesFromServer);
}
resultMap.put(server, valuesFromServer);
} catch (InterruptedException e) {
throw new InternalGemFireException(e.getMessage());
} catch (ExecutionException ee) {
if (ee.getCause() instanceof ServerOperationException) {
if (logger.isDebugEnabled()) {
logger.debug("GetAllOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
}
throw (ServerOperationException) ee.getCause();
} else if (ee.getCause() instanceof ServerConnectivityException) {
if (logger.isDebugEnabled()) {
logger.debug("GetAllOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
}
try {
cms = region.getCache().getClientMetadataService();
} catch (CacheClosedException e) {
return null;
}
cms.removeBucketServerLocation(server);
cms.scheduleGetPRMetaData((LocalRegion) region, false);
resultMap.put(server, ee.getCause());
} else {
throw executionThrowable(ee.getCause());
}
}
}
return resultMap;
}
}
return null;
}
Aggregations