TEST(PathUtils, decompose) {
    static const struct {
        const char* path;
        const ComponentList components[kHostTypeCount];
    } kData[] = {
        { "", { { NULL }, { NULL } } },
        { "foo", {
            { "foo", NULL },
            { "foo", NULL } } },
        { "foo/", {
            { "foo", NULL },
            { "foo", NULL } } },
        { "foo/bar", {
            { "foo", "bar", NULL },
            { "foo", "bar", NULL } } },
        { "foo//bar/zoo", {
            { "foo", "bar", "zoo", NULL },
            { "foo", "bar", "zoo", NULL } } },
        { "\\foo\\bar\\", {
            { "\\foo\\bar\\", NULL },
            { "\\", "foo", "bar", NULL } } },
        { "C:foo\\bar", {
            { "C:foo\\bar", NULL },
            { "C:", "foo", "bar", NULL } } },
        { "C:/foo", {
            { "C:", "foo", NULL },
            { "C:/", "foo", NULL } } },
        { "/foo", {
            { "/", "foo", NULL },
            { "/", "foo", NULL } } },
        { "\\foo", {
            { "\\foo", NULL },
            { "\\", "foo", NULL } } },
    };
    for (size_t n = 0; n < ARRAY_SIZE(kData); ++n) {
        const char* path = kData[n].path;
        checkComponents(kData[n].components[kHostPosix],
                        PathUtils::decompose(path, kHostPosix),
                        "posix",
                        path);

        checkComponents(kData[n].components[kHostWin32],
                        PathUtils::decompose(path, kHostWin32),
                        "win32",
                        path);

        checkComponents(kData[n].components[kHostType],
                        PathUtils::decompose(path),
                        "host",
                        path);
    }
}
Beispiel #2
0
//-------------------------------------------------------------------------------------		
void Components::addComponent(int32 uid, const char* username, 
			COMPONENT_TYPE componentType, COMPONENT_ID componentID, 
			uint32 intaddr, uint16 intport, 
			uint32 extaddr, uint16 extport, 
			Mercury::Channel* pChannel)
{
	COMPONENTS& components = getComponents(componentType);

	if(!checkComponents(uid, componentID))
		return;

	ComponentInfos* cinfos = findComponent(componentType, uid, componentID);
	if(cinfos != NULL)
	{
		WARNING_MSG("Components::addComponent[%s]: uid:%d, username:%s, "
			"componentType:%d, componentID:%"PRAppID" is exist!\n", 
			COMPONENT_NAME[(uint8)componentType], uid, username, (int32)componentType, componentID);
		return;
	}
	
	ComponentInfos componentInfos;

	componentInfos.pIntAddr.reset(new Mercury::Address(intaddr, intport));
	componentInfos.pExtAddr.reset(new Mercury::Address(extaddr, extport));
	componentInfos.uid = uid;
	componentInfos.cid = componentID;
	componentInfos.pChannel = pChannel;
	componentInfos.componentType = componentType;

	strncpy(componentInfos.username, username, MAX_NAME);

	if(cinfos == NULL)
		components.push_back(componentInfos);
	else
		*cinfos = componentInfos;

	_globalOrderLog[uid]++;

	switch(componentType)
	{
	case BASEAPP_TYPE:
		_baseappGrouplOrderLog[uid]++;
		break;
	case CELLAPP_TYPE:
		_cellappGrouplOrderLog[uid]++;
		break;
	case LOGINAPP_TYPE:
		_loginappGrouplOrderLog[uid]++;
		break;
	default:
		break;
	};

	INFO_MSG("Components::addComponent[%s], uid:%d, "
		"componentID:%"PRAppID", totalcount=%d\n", 
			COMPONENT_NAME[(uint8)componentType], uid, 
			componentID, components.size());
}
static void testBreakUpComponentGreedily(CuTest *testCase) {
    //return;
    for (int64_t test = 0; test < 100; test++) {
        st_logInfo("Starting break up giant components random test %" PRIi64 "\n", test);
        setup();
        stList *edgesToDelete = stCaf_breakupComponentGreedily(nodes, edges, maxComponentSize);
        stSortedSet *edgesSet = stList_getSortedSet(edges, (int(*)(const void *, const void *)) stIntTuple_cmpFn);
        stSortedSet *edgesToDeleteSet = stList_getSortedSet(edgesToDelete, (int(*)(const void *, const void *)) stIntTuple_cmpFn);
        stSortedSet *filteredEdgesSet = stSortedSet_getDifference(edgesSet, edgesToDeleteSet);
        stList *filteredEdges = stSortedSet_getList(filteredEdgesSet);
        assert(stSortedSet_size(edgesToDeleteSet) + stSortedSet_size(filteredEdgesSet) == stSortedSet_size(edgesSet));
        checkComponents(testCase, filteredEdges);
        stSortedSet_destruct(edgesSet);
        stSortedSet_destruct(edgesToDeleteSet);
        stSortedSet_destruct(filteredEdgesSet);
        stList_destruct(filteredEdges);
        stList_destruct(edgesToDelete);
        teardown();
    }
}
Beispiel #4
0
//-------------------------------------------------------------------------------------		
void Components::addComponent(int32 uid, const char* username, 
			COMPONENT_TYPE componentType, COMPONENT_ID componentID, COMPONENT_ORDER globalorderid, COMPONENT_ORDER grouporderid, COMPONENT_GUS gus,
			uint32 intaddr, uint16 intport, uint32 extaddr, uint16 extport, std::string& extaddrEx, uint32 pid,
			float cpu, float mem, uint32 usedmem, uint64 extradata, uint64 extradata1, uint64 extradata2, uint64 extradata3,
			Network::Channel* pChannel)
{
	COMPONENTS& components = getComponents(componentType);

	if(!checkComponents(uid, componentID, pid))
		return;

	ComponentInfos* cinfos = findComponent(componentType, uid, componentID);
	if(cinfos != NULL)
	{
		WARNING_MSG(fmt::format("Components::addComponent[{}]: uid:{}, username:{}, "
			"componentType:{}, componentID:{} is exist!\n",
			COMPONENT_NAME_EX(componentType), uid, username, (int32)componentType, componentID));
		return;
	}
	
	// 如果该uid下没有已经运行的任何相关组件,那么重置计数器
	if (getGameSrvComponentsSize(uid) == 0)
	{
		_globalOrderLog[uid] = 0;
		_baseappGrouplOrderLog[uid] = 0;
		_cellappGrouplOrderLog[uid] = 0;
		_loginappGrouplOrderLog[uid] = 0;

		INFO_MSG(fmt::format("Components::addComponent: reset orderLog, uid={}!\n",
			uid));
	}

	ComponentInfos componentInfos;

	componentInfos.pIntAddr.reset(new Network::Address(intaddr, intport));
	componentInfos.pExtAddr.reset(new Network::Address(extaddr, extport));

	if(extaddrEx.size() > 0)
		strncpy(componentInfos.externalAddressEx, extaddrEx.c_str(), MAX_NAME);
	
	componentInfos.uid = uid;
	componentInfos.cid = componentID;
	componentInfos.pChannel = pChannel;
	componentInfos.componentType = componentType;
	componentInfos.groupOrderid = 1;
	componentInfos.globalOrderid = 1;

	componentInfos.mem = mem;
	componentInfos.cpu = cpu;
	componentInfos.usedmem = usedmem;
	componentInfos.extradata = extradata;
	componentInfos.extradata1 = extradata1;
	componentInfos.extradata2 = extradata2;
	componentInfos.extradata3 = extradata3;
	componentInfos.pid = pid;

	if(pChannel)
		pChannel->componentID(componentID);

	strncpy(componentInfos.username, username, MAX_NAME);

	_globalOrderLog[uid]++;

	switch(componentType)
	{
	case BASEAPP_TYPE:
		_baseappGrouplOrderLog[uid]++;
		componentInfos.groupOrderid = _baseappGrouplOrderLog[uid];
		break;
	case CELLAPP_TYPE:
		_cellappGrouplOrderLog[uid]++;
		componentInfos.groupOrderid = _cellappGrouplOrderLog[uid];
		break;
	case LOGINAPP_TYPE:
		_loginappGrouplOrderLog[uid]++;
		componentInfos.groupOrderid = _loginappGrouplOrderLog[uid];
		break;
	default:
		break;
	};
	
	if(grouporderid > 0)
		componentInfos.groupOrderid = grouporderid;

	if(globalorderid > 0)
		componentInfos.globalOrderid = globalorderid;
	else
		componentInfos.globalOrderid = _globalOrderLog[uid];

	componentInfos.gus = gus;

	if(cinfos == NULL)
		components.push_back(componentInfos);
	else
		*cinfos = componentInfos;

	INFO_MSG(fmt::format("Components::addComponent[{}], uid={}, "
		"componentID={}, globalorderid={}, grouporderid={}, totalcount={}\n",
			COMPONENT_NAME_EX(componentType), 
			uid,
			componentID, 
			((int32)componentInfos.globalOrderid),
			((int32)componentInfos.groupOrderid),
			components.size()));
	
	if(_pHandler)
		_pHandler->onAddComponent(&componentInfos);
}