Esempio n. 1
0
ThreadReturnType PEGASUS_THREAD_CDECL createSubscriptionFunc(void *parm)
{
    Thread* my_handle = reinterpret_cast<Thread *>(parm);
    Boolean cimExceptionCaught = false;
    CIMClient client;
    CIMException theCIMException;
    try
    {
        client.connectLocal();
        SubscriptionPath = CreateSbscriptionInstance(client, HandlerPath,
            FilterPath, PEGASUS_NAMESPACENAME_INTEROP);
    }
    catch (CIMException& e)
    {
        PEGASUS_TEST_ASSERT(e.getCode() == CIM_ERR_ALREADY_EXISTS ||
            e.getCode() == CIM_ERR_FAILED);
        exceptionCount++;
    }
    catch (Exception& e)
    {
        cout << e.getMessage() << endl;
    }

    return ThreadReturnType(0);
}
Esempio n. 2
0
void _testDuplicate(CIMClient &client)
{
    CIMObjectPath filterPath;
    CIMObjectPath handlerPath;
    CIMObjectPath subscriptionPath;

    try
    {
        handlerPath = CreateHandler1Instance(client,
            PEGASUS_NAMESPACENAME_INTEROP);
        filterPath = CreateFilterInstance(client,
            QUERY1, "WQL", "Filter1",
            PEGASUS_NAMESPACENAME_INTEROP);
        subscriptionPath = CreateSbscriptionInstance(client, handlerPath,
            filterPath, PEGASUS_NAMESPACENAME_INTEROP);

        _createDuplicate(client, String::EMPTY, CIMNamespaceName(),
            filterPath, String::EMPTY, CIMNamespaceName(), handlerPath);

        _createDuplicate(client, String::EMPTY,
            PEGASUS_NAMESPACENAME_INTEROP, filterPath,
            String::EMPTY,PEGASUS_NAMESPACENAME_INTEROP, handlerPath);

        _createDuplicate(client, "127.0.0.1",
            PEGASUS_NAMESPACENAME_INTEROP, filterPath,
            String::EMPTY, CIMNamespaceName(), handlerPath);

        _createDuplicate(client, "127.0.0.1",PEGASUS_NAMESPACENAME_INTEROP,
            filterPath, "127.0.0.1", PEGASUS_NAMESPACENAME_INTEROP,
            handlerPath);

        _createDuplicate(client, String::EMPTY, CIMNamespaceName(),
            filterPath, "127.0.0.1", PEGASUS_NAMESPACENAME_INTEROP,
            handlerPath);
        _checkSubscriptionCount(client);
        DeleteInstance(client, subscriptionPath, PEGASUS_NAMESPACENAME_INTEROP);
        DeleteInstance(client, filterPath, PEGASUS_NAMESPACENAME_INTEROP);
        DeleteInstance(client, handlerPath, PEGASUS_NAMESPACENAME_INTEROP);
    }
    catch (const CIMException &e)
    {
        PEGASUS_STD(cerr) << "Exception: " << e.getMessage()
                          << PEGASUS_STD (endl);
        PEGASUS_TEST_ASSERT(0);
    }
}
Esempio n. 3
0
void _createDuplicate(CIMClient &client,
    const String &filterHost,
    const CIMNamespaceName &filterNameSpace,
    CIMObjectPath &filterPath,
    const String &handlerHost,
    const CIMNamespaceName &handlerNameSpace,
    CIMObjectPath &handlerPath)
{
    Boolean exceptionCaught = false;
    //
    //  Set Host and Namespace in filter CIMObjectPath
    //
    filterPath.setHost(filterHost);
    filterPath.setNameSpace(filterNameSpace);

    //
    //  Set Host and Namespace in handler CIMObjectPath
    //
    handlerPath.setHost (handlerHost);
    handlerPath.setNameSpace (handlerNameSpace);

    try
    {
        CreateSbscriptionInstance(client, handlerPath,
            filterPath, PEGASUS_NAMESPACENAME_INTEROP);
    }
    catch (CIMException &e)
    {
        if (e.getCode() != CIM_ERR_ALREADY_EXISTS)
        {
            PEGASUS_TEST_ASSERT(0);
        }
        exceptionCaught =  true;
    }
    PEGASUS_TEST_ASSERT(exceptionCaught);
}
Esempio n. 4
0
int _test(CIMClient& client, String& qlang, String& query1, String& query2)
{
    CIMObjectPath Handler1Ref, Handler2Ref;
    CIMObjectPath Filter1Ref, Filter2Ref;
    CIMObjectPath Subscription1Ref, Subscription2Ref;

    try
    {
        Handler1Ref =
            CreateHandler1Instance(client, PEGASUS_NAMESPACENAME_INTEROP);
        Handler2Ref = CreateHandler1Instance(client, NAMESPACE2);
    }
    catch (Exception& e)
    {
        PEGASUS_STD (cerr) << "Exception: " << e.getMessage()
                           << PEGASUS_STD (endl);
        PEGASUS_STD (cerr) << "create handler instance failed"
                           << PEGASUS_STD (endl);
        return -1;
    }

    PEGASUS_STD (cout) << "+++++ handler instances created"
                       << PEGASUS_STD (endl);
    try
    {
      String name1 = "TestFilter01";
      String name2 = "TestFilter02";
      Filter1Ref = CreateFilterInstance (client, query1, qlang, name1,
          PEGASUS_NAMESPACENAME_INTEROP);
      Filter2Ref = CreateFilterInstance (client, query2, qlang, name2,
          NAMESPACE1);
    }
    catch (Exception& e)
    {
        PEGASUS_STD (cerr) << "Exception: " << e.getMessage()
                           << PEGASUS_STD (endl);
        PEGASUS_STD (cerr) << "create filter instances failed"
                           << PEGASUS_STD (endl);
        return -1;
    }

    PEGASUS_STD (cout) << "+++++ filter instances created for "
                       << qlang
                       << PEGASUS_STD (endl);
    try
    {
        Subscription1Ref =
          CreateSbscriptionInstance (client, Handler1Ref, Filter1Ref,
              PEGASUS_NAMESPACENAME_INTEROP);
        Subscription2Ref =
          CreateSbscriptionInstance (client, Handler1Ref, Filter2Ref,
              NAMESPACE3);
    }
    catch (Exception& e)
    {
        PEGASUS_STD (cerr) << "Exception: " << e.getMessage()
                           << PEGASUS_STD (endl);
        PEGASUS_STD (cerr) << "create subscription instance failed"
                           << PEGASUS_STD (endl);
        return -1;
    }

    PEGASUS_STD (cout) << "+++++ subscription instances created"
                       << PEGASUS_STD (endl);

    // get display consumer
    String indicationFile2, oldIndicationFile;

    indicationFile2 = INDICATION_DIR;
    indicationFile2.append("/indicationLog");

    if (FileSystem::exists(indicationFile2))
    {
        oldIndicationFile = INDICATION_DIR;
        oldIndicationFile.append("/oldIndicationFile");
        if (FileSystem::exists(oldIndicationFile))
        {
          FileSystem::removeFile(oldIndicationFile);
        }
        if (!FileSystem::renameFile(indicationFile2, oldIndicationFile))
        {
          FileSystem::removeFile(indicationFile2);
        }
    }

    try
    {
      //
      // generate three indications
      //
      for(Uint8 i = 0; i < 3; i++)
      {
        generateIndication(client);
      }
    }
    catch (Exception& e)
    {
      PEGASUS_STD (cerr) << "Exception: " << e.getMessage()
                         << PEGASUS_STD (endl);
      PEGASUS_STD (cerr) << "generate indication failed"
                         << PEGASUS_STD (endl);
      return -1;
    }

    PEGASUS_STD (cout) << "+++++ indications generated"
                       << PEGASUS_STD (endl);

    System::sleep(5);

    try
    {
      DeleteInstance (client, Subscription1Ref,
                      PEGASUS_NAMESPACENAME_INTEROP);
      DeleteInstance (client, Subscription2Ref, NAMESPACE3);
      DeleteInstance (client, Filter1Ref,
                      PEGASUS_NAMESPACENAME_INTEROP);
      DeleteInstance (client, Filter2Ref, NAMESPACE1);
      DeleteInstance (client, Handler1Ref,
                      PEGASUS_NAMESPACENAME_INTEROP);
      DeleteInstance (client, Handler2Ref, NAMESPACE2);
    }
    catch (Exception& e)
    {
      PEGASUS_STD (cerr) << "Exception: " << e.getMessage()
                         << PEGASUS_STD (endl);
      PEGASUS_STD (cerr) << "delete instance failed"
                         << PEGASUS_STD (endl);
      return -1;
    }

    PEGASUS_STD (cout) << "+++++ instances deleted"
                       << PEGASUS_STD (endl);

    //
    // compare indications with the master output
    //
    String indicationFile, masterFile, indication_failed;

    indicationFile = INDICATION_DIR;
    indicationFile.append("/indicationLog");

    // Get environment variable:
    masterFile = getenv("PEGASUS_ROOT");
    masterFile.append(
        "/src/Pegasus/IndicationService/tests/IndicationProcess/masterOutput");

    if (FileSystem::exists(indicationFile) && FileSystem::exists(masterFile))
    {
      if (FileSystem::compareFiles(indicationFile, masterFile))
      {
        PEGASUS_STD (cout) << "+++++ passed all tests." << PEGASUS_STD (endl);
        // remove indicationFile
        FileSystem::removeFile(indicationFile);
        return 0;
      }
      else
      {
        PEGASUS_STD (cerr) << "----- tests failed" << PEGASUS_STD (endl);
        // rename indicationFile to be indicationLog_FAILED
        // and remove indicationFile
        indication_failed = INDICATION_DIR;
        indication_failed.append("/indicationLog_FAILED");
        FileSystem::renameFile(indicationFile, indication_failed);
        FileSystem::removeFile(indicationFile);
        return 1;
      }
    }
    else
    {
      PEGASUS_STD (cerr) << "----- tests failed" << PEGASUS_STD (endl);
      // rename indicationFile to be indicationFile_FAILED
      // and remove indicationFile
      if (FileSystem::exists(indicationFile))
      {
        indication_failed = INDICATION_DIR;
        indication_failed.append("/indicationLog_FAILED");
        FileSystem::renameFile(indicationFile, indication_failed);
        FileSystem::removeFile(indicationFile);
      }
      return 1;
    }
}