void EndpointServiceProxy::updateConfig(boost::shared_ptr<ZKManager> zkManagerPtr){ vector<string> serverNameList; vector<ServerNode> serverList; if(!zkManagerPtr->getChildren(zkPath_, serverNameList)){ LOG_ERROR("EndpointServiceProxy::updateConfig => get serverName failure : path = " << zkPath_); initProxy(serverList); return; } std::vector<int> indexList; std::map<int, std::string> serverMap; for(size_t i = 0; i < serverNameList.size(); ++i){ size_t p = serverNameList[i].find('-'); if(p == string::npos){ LOG_ERROR("EndpointServiceProxy::updateConfig => serverName format error : name = [" << serverNameList[i] << "]"); continue; } int index = 0; try{ index = boost::lexical_cast<int>(serverNameList[i].substr(p + 1)); } catch (boost::bad_lexical_cast &){ LOG_ERROR("EndpointServiceProxy::updateConfig => convert server index failure : index = [" << serverNameList[i].substr(p + 1) << "]"); continue; } std::string childPath(zkPath_); childPath.append("/"); childPath.append(serverNameList[i]); std::string server; if(zkManagerPtr->get(childPath, server)){ indexList.push_back(index); serverMap[index] = server; } else { LOG_ERROR("EndpointServiceProxy::updateConfig => get server node failure : path = " << childPath); } } sort(indexList.begin(), indexList.end()); for(size_t i = 0; i < indexList.size(); ++i){ ServerNode node; node.index = indexList[i]; node.address = serverMap[node.index]; serverList.push_back(node); } initProxy(serverList); }
int testBoincProxy(BoincTest * test) { int failed = 0; boincTestInitMajor(test, "BoincProxy"); boincHttpInit(); BoincProxyTest proxytest; memset(&proxytest, 0, sizeof(BoincProxyTest)); boincTestRunMinor(test, "BoincProxy create&destroy", testBoincProxyCreate, &proxytest); proxytest.proxy = initProxy(&proxytest); boincTestRunMinor(test, "BoincProxy authenticate error", testBoincProxyAuthenticateError, &proxytest); boincTestRunMinor(test, "BoincProxy authenticate", testBoincProxyAuthenticate, &proxytest); failed = boincTestRunMinor(test, "BoincProxy workunit", testBoincProxyGetWorkUnit, &proxytest); if (!failed) { boincTestRunMinor(test, "BoincProxy uploadfile", testBoincProxyUploadFile, &proxytest); boincTestRunMinor(test, "BoincProxy downloadfile", testBoincProxyDownloadFile, &proxytest); } boincTestRunMinor(test, "BoincProxy destroy", testBoincProxyDestroyAll, &proxytest); cleanupProxy(&proxytest); //boincTestRunMinor(test, "BoincProxy load status", testBoincProxyLoadStatus, NULL); boincTestEndMajor(test); return 0; }
void testDriverStruct (void) { initProxy(&_sillyDriver); }