Пример #1
0
        public override IEnumerator RunTest()
        {
            LogSystem.InstallDefaultReactors();

            _testClusterConfigName  = "cranfield_solr_config";
            _testClusterConfigPath  = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/cranfield_solr_config.zip";
            _testRankerTrainingPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/ranker_training_data.csv";
            _testAnswerDataPath     = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/ranker_answer_data.csv";
            _indexDataPath          = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/cranfield_data.json";
            _testQuery = "What is the basic mechanisim of the transonic aileron buzz";
            _collectionNameToDelete = "TestCollectionToDelete";
            _createdRankerName      = "RankerToDelete";

            try
            {
                VcapCredentials vcapCredentials = new VcapCredentials();
                fsData          data            = null;

                //  Get credentials from a credential file defined in environmental variables in the VCAP_SERVICES format.
                //  See https://www.ibm.com/watson/developercloud/doc/common/getting-started-variables.html.
                var environmentalVariable = Environment.GetEnvironmentVariable("VCAP_SERVICES");
                var fileContent           = File.ReadAllText(environmentalVariable);

                //  Add in a parent object because Unity does not like to deserialize root level collection types.
                fileContent = Utility.AddTopLevelObjectToJson(fileContent, "VCAP_SERVICES");

                //  Convert json to fsResult
                fsResult r = fsJsonParser.Parse(fileContent, out data);
                if (!r.Succeeded)
                {
                    throw new WatsonException(r.FormattedMessages);
                }

                //  Convert fsResult to VcapCredentials
                object obj = vcapCredentials;
                r = _serializer.TryDeserialize(data, obj.GetType(), ref obj);
                if (!r.Succeeded)
                {
                    throw new WatsonException(r.FormattedMessages);
                }

                //  Set credentials from imported credntials
                Credential credential = vcapCredentials.VCAP_SERVICES["retrieve_and_rank"][TestCredentialIndex].Credentials;
                _username = credential.Username.ToString();
                _password = credential.Password.ToString();
                _url      = credential.Url.ToString();
            }
            catch
            {
                Log.Debug("TestRetrieveAndRank.RunTest()", "Failed to get credentials from VCAP_SERVICES file. Please configure credentials to run this test. For more information, see: https://github.com/watson-developer-cloud/unity-sdk/#authentication");
            }

            //  Create credential and instantiate service
            Credentials credentials = new Credentials(_username, _password, _url);

            //  Or authenticate using token
            //Credentials credentials = new Credentials(_url)
            //{
            //    AuthenticationToken = _token
            //};

            _retrieveAndRank = new RetrieveAndRank(credentials);

            //  Get clusters
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to get clusters.");
            if (!_retrieveAndRank.GetClusters(OnGetClusters, OnFail))
            {
                Log.Debug("TestRetrieveAndRank.GetClusters()", "Failed to get clusters!");
            }
            while (!_getClustersTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Create cluster
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to create cluster.");
            if (!_retrieveAndRank.CreateCluster(OnCreateCluster, OnFail, "unity-test-cluster", "1"))
            {
                Log.Debug("TestRetrieveAndRank.CreateCluster()", "Failed to create cluster!");
            }
            while (!_createClusterTested || !_readyToContinue)
            {
                yield return(null);
            }

            //  Wait for cluster status to be `READY`.
            Runnable.Run(CheckClusterStatus(10f));
            while (!_isClusterReady)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  List cluster configs
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to get cluster configs.");
            if (!_retrieveAndRank.GetClusterConfigs(OnGetClusterConfigs, OnFail, _clusterToDelete))
            {
                Log.Debug("TestRetrieveAndRank.GetClusterConfigs()", "Failed to get cluster configs!");
            }
            while (!_getClusterConfigsTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Upload cluster config
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to upload cluster config.");
            if (!_retrieveAndRank.UploadClusterConfig(OnUploadClusterConfig, OnFail, _clusterToDelete, _testClusterConfigName, _testClusterConfigPath))
            {
                Log.Debug("TestRetrieveAndRank.UploadClusterConfig()", "Failed to upload cluster config {0}!", _testClusterConfigPath);
            }
            while (!_uploadClusterConfigTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Get cluster
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to get cluster.");
            if (!_retrieveAndRank.GetCluster(OnGetCluster, OnFail, _clusterToDelete))
            {
                Log.Debug("TestRetrieveAndRank.GetCluster()", "Failed to get cluster!");
            }
            while (!_getClusterTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Get cluster config
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to get cluster config.");
            if (!_retrieveAndRank.GetClusterConfig(OnGetClusterConfig, OnFail, _clusterToDelete, _testClusterConfigName))
            {
                Log.Debug("TestRetrieveAndRank.GetClusterConfig()", "Failed to get cluster config {0}!", _testClusterConfigName);
            }
            while (!_getClusterConfigTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  List Collection request
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to get collections.");
            if (!_retrieveAndRank.ForwardCollectionRequest(OnGetCollections, OnFail, _clusterToDelete, CollectionsAction.List))
            {
                Log.Debug("TestRetrieveAndRank.ForwardCollectionRequest()", "Failed to get collections!");
            }
            while (!_getCollectionsTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Create Collection request
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to create collection.");
            if (!_retrieveAndRank.ForwardCollectionRequest(OnCreateCollection, OnFail, _clusterToDelete, CollectionsAction.Create, _collectionNameToDelete, _testClusterConfigName))
            {
                Log.Debug("TestRetrieveAndRank.ForwardCollectionRequest()", "Failed to create collections!");
            }
            while (!_createCollectionTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Index documents
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to index documents.");
            if (!_retrieveAndRank.IndexDocuments(OnIndexDocuments, OnFail, _indexDataPath, _clusterToDelete, _collectionNameToDelete))
            {
                Log.Debug("TestRetrieveAndRank.IndexDocuments()", "Failed to index documents!");
            }
            while (!_indexDocumentsTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Get rankers
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to get rankers.");
            if (!_retrieveAndRank.GetRankers(OnGetRankers, OnFail))
            {
                Log.Debug("TestRetrieveAndRank.GetRankers()", "Failed to get rankers!");
            }
            while (!_getRankersTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Create ranker
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to create ranker.");
            if (!_retrieveAndRank.CreateRanker(OnCreateRanker, OnFail, _testRankerTrainingPath, _createdRankerName))
            {
                Log.Debug("TestRetrieveAndRank.CreateRanker()", "Failed to create ranker!");
            }
            while (!_createRankerTested || !_readyToContinue)
            {
                yield return(null);
            }

            //  Wait for ranker status to be `Available`.
            Log.Debug("TestRetrieveAndRank.RunTest()", "Checking ranker status in 10 seconds");
            Runnable.Run(CheckRankerStatus(10f));
            while (!_isRankerReady || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Standard Search
            string[] fl = { "title", "id", "body", "author", "bibliography" };
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to search standard.");
            if (!_retrieveAndRank.Search(OnSearchStandard, OnFail, _clusterToDelete, _collectionNameToDelete, _testQuery, fl))
            {
                Log.Debug("TestRetrieveAndRank.Search()", "Failed to search!");
            }
            while (!_searchStandardTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Rank
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to rank.");
            if (!_retrieveAndRank.Rank(OnRank, OnFail, _rankerIdToDelete, _testAnswerDataPath))
            {
                Log.Debug("TestRetrieveAndRank.Rank()", "Failed to rank!");
            }
            while (!_rankTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Get ranker info
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to get rankers.");
            if (!_retrieveAndRank.GetRanker(OnGetRanker, OnFail, _rankerIdToDelete))
            {
                Log.Debug("TestRetrieveAndRank.GetRanker()", "Failed to get ranker!");
            }
            while (!_getRankerTested)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete rankers
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to delete ranker {0}.", _rankerIdToDelete);
            if (!_retrieveAndRank.DeleteRanker(OnDeleteRanker, OnFail, _rankerIdToDelete))
            {
                Log.Debug("TestRetrieveAndRank.DeleteRanker()", "Failed to delete ranker {0}!", _rankerIdToDelete);
            }
            while (!_deleteRankerTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete Collection request
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to delete collection {0}.", "TestCollectionToDelete");
            if (!_retrieveAndRank.ForwardCollectionRequest(OnDeleteCollection, OnFail, _clusterToDelete, CollectionsAction.Delete, "TestCollectionToDelete"))
            {
                Log.Debug("TestRetrieveAndRank.ForwardCollectionRequest()", "Failed to delete collections!");
            }
            while (!_deleteCollectionTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete cluster config
            string clusterConfigToDelete = "test-config";

            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to delete cluster config.");
            if (!_retrieveAndRank.DeleteClusterConfig(OnDeleteClusterConfig, OnFail, _clusterToDelete, clusterConfigToDelete))
            {
                Log.Debug("TestRetrieveAndRank.DeleteClusterConfig()", "Failed to delete cluster config {0}", clusterConfigToDelete);
            }
            while (!_deleteClusterConfigTested || !_readyToContinue)
            {
                yield return(null);
            }

            _readyToContinue = false;
            //  Delete cluster
            Log.Debug("TestRetrieveAndRank.RunTest()", "Attempting to delete cluster {0}.", _clusterToDelete);
            if (!_retrieveAndRank.DeleteCluster(OnDeleteCluster, OnFail, _clusterToDelete))
            {
                Log.Debug("TestRetrieveAndRank.DeleteCluster()", "Failed to delete cluster!");
            }
            while (!_deleteClusterTested || !_readyToContinue)
            {
                yield return(null);
            }

            Log.Debug("TestRetrieveAndRank.RunTest()", "Retrieve and rank examples complete!");
            yield break;
        }
Пример #2
0
        public override IEnumerator RunTest()
        {
            LogSystem.InstallDefaultReactors();

            m_IntegrationTestClusterConfigPath    = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/cranfield_solr_config.zip";
            m_IntegrationTestRankerTrainingPath   = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/ranker_training_data.csv";
            m_IntegrationTestRankerAnswerDataPath = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/ranker_answer_data.csv";
            m_IntegrationTestIndexDataPath        = Application.dataPath + "/Watson/Examples/ServiceExamples/TestData/RetrieveAndRank/cranfield_data.json";

            m_ExampleClusterID      = Config.Instance.GetVariableValue("RetrieveAndRank_IntegrationTestClusterID");
            m_ExampleConfigName     = Config.Instance.GetVariableValue("RetrieveAndRank_IntegrationTestConfigName");
            m_ExampleRankerID       = Config.Instance.GetVariableValue("RetrieveAndRank_IntegrationTestRankerID");
            m_ExampleCollectionName = Config.Instance.GetVariableValue("RetrieveAndRank_IntegrationTestCollectionName");

            #region delete existing
            ////  Get existing cluster data.
            //Log.Debug("TestRetrieveAndRank", "Getting existing clusters.");
            //m_RetrieveAndRank.GetClusters(OnGetExistingClusters);
            //while (!m_ExistingClusterDataRetrieved)
            //    yield return null;

            ////  get existing config data.
            //Log.Debug("TestRetrieveAndRank", "Getting existing configs.");
            //foreach (ClusterInfo cluster in m_ExistingClusterInfo)
            //    m_RetrieveAndRank.GetClusterConfigs(OnGetExistingConfigs, cluster.Cluster.solr_cluster_id, cluster.Cluster.solr_cluster_id);
            //while (m_NumExistingConfigsProcessed < m_ExistingClusterInfo.Count)
            //    yield return null;

            ////  get existing collection data.
            //Log.Debug("TestRetrieveAndRank", "Getting existing collections.");
            //foreach (ClusterInfo cluster in m_ExistingClusterInfo)
            //    m_RetrieveAndRank.ForwardCollectionRequest(OnGetExistingCollections, cluster.Cluster.solr_cluster_id, CollectionsAction.LIST, null, null, cluster.Cluster.solr_cluster_id);
            //while (m_NumExistingCollectionsProcessed < m_ExistingClusterInfo.Count)
            //    yield return null;

            ////  get existing ranker data.
            //Log.Debug("TestRetrieveAndRank", "Getting existing rankers.");
            //m_RetrieveAndRank.GetRankers(OnGetExistingRankers);
            //while (!m_ExistingRankerDataRetrieved)
            //    yield return null;

            ////  Cleanup old data
            //Log.Debug("TestRetrieveAndRank", "Cleaning existing data.");
            //foreach (ClusterInfo cluster in m_ExistingClusterInfo)
            //{
            //    //  Delete collections
            //    Log.Debug("TestRetriveAndRank", "Attempting to delete extra collections!");
            //    if (cluster.Collections != null && cluster.Collections.Length > 0)
            //        foreach (string collection in cluster.Collections)
            //        {
            //            if (collection == m_CollectionToCreateName)
            //            {
            //                Log.Debug("TestRetrieveAndRank", "Deleting collection {0}.", collection);
            //                m_RetrieveAndRank.ForwardCollectionRequest(OnDeleteExistingCollection, cluster.Cluster.solr_cluster_id, CollectionsAction.DELETE, collection);
            //            }
            //    }

            //    //	Wait before deleting config
            //    m_IsDoneWaiting = false;
            //    Runnable.Run(WaitUp(5f));
            //    while (!m_IsDoneWaiting)
            //        yield return null;

            //    //  Delete config
            //    Log.Debug("TestRetriveAndRank", "Attempting to delete extra configs!");
            //    if (cluster.Configs != null && cluster.Configs.Length > 0)
            //        foreach (string config in cluster.Configs)
            //        {
            //            if (config == m_ConfigToCreateName)
            //            {
            //                Log.Debug("TestRetrieveAndRank", "Deleting config {0}.", config);
            //                m_RetrieveAndRank.DeleteClusterConfig(OnDeleteExistingConfig, cluster.Cluster.solr_cluster_id, config);
            //            }
            //        }

            //    //while (m_NumExistingConfigsProcessed > 0)
            //    //    yield return null;

            //    //	Wait before deleting cluster
            //    m_IsDoneWaiting = false;
            //    Runnable.Run(WaitUp(5f));
            //    while (!m_IsDoneWaiting)
            //        yield return null;

            //    //  Delete cluster
            //    Log.Debug("TestRetriveAndRank", "Attempting to delete extra clusters!");
            //    if (cluster.Cluster.cluster_name == m_ClusterToCreateName)
            //    {
            //        Log.Debug("TestRetrieveAndRank", "Deleting cluster {0}.", cluster.Cluster.solr_cluster_id);
            //        m_RetrieveAndRank.DeleteCluster(OnDeleteExistingCluster, cluster.Cluster.solr_cluster_id);
            //    }
            //}

            //while (m_NumExistingClusters > 0)
            //    yield return null;

            ////	Wait before deleting ranker
            //m_IsDoneWaiting = false;
            //Runnable.Run(WaitUp(5f));
            //while (!m_IsDoneWaiting)
            //    yield return null;

            ////  Delete rankers
            //foreach (RankerInfoPayload ranker in m_ExistingRankers)
            //{
            //    if (ranker.name == m_RankerToCreateName)
            //    {
            //        Log.Debug("TestRetrieveAndRank", "Deleting ranker {0}.", ranker.ranker_id);
            //        m_RetrieveAndRank.DeleteRanker(OnDeleteExistingRanker, ranker.ranker_id);
            //    }
            //}
            #endregion

            //  Get clusters
            Log.Debug("TestRetrieveAndRank", "*** Attempting to get clusters!");
            m_RetrieveAndRank.GetClusters(OnGetClusters);
            while (!m_GetClustersTested)
            {
                yield return(null);
            }

#if TEST_CREATE_DELETE
            //  Create cluster
            Log.Debug("TestRetrieveAndRank", "*** Attempting to create cluster!");
            m_RetrieveAndRank.CreateCluster(OnCreateCluster, m_ClusterToCreateName, "1");
            while (!m_CreateClusterTested)
            {
                yield return(null);
            }
#endif
            //  Get created cluster
            Log.Debug("TestRetrieveAndRank", "*** Attempting to get created cluster {0}!", IsFullTest ? m_CreatedClusterID : m_ExampleClusterID);
            m_RetrieveAndRank.GetCluster(OnGetCluster, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID);
            while (!m_GetClusterTested || !m_IsClusterReady)
            {
                yield return(null);
            }

            //  List cluster configs
            if (!m_ListClusterConfigsTested)
            {
                Log.Debug("TestRetrieveAndRank", "*** Attempting to get cluster configs for {0}!", IsFullTest ? m_CreatedClusterID : m_ExampleClusterID);
                m_RetrieveAndRank.GetClusterConfigs(OnGetClusterConfigs, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID);
                while (!m_ListClusterConfigsTested)
                {
                    yield return(null);
                }
            }

#if TEST_CREATE_DELETE
            //  Upload cluster config
            Log.Debug("TestRetrieveAndRank", "*** Attempting to upload cluster {0} config {1}!", IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, m_ConfigToCreateName);
            m_RetrieveAndRank.UploadClusterConfig(OnUploadClusterConfig, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, m_ConfigToCreateName, m_IntegrationTestClusterConfigPath);
            while (!m_UploadClusterConfigTested)
            {
                yield return(null);
            }
#endif
            //  Get cluster config
            Log.Debug("TestRetrieveAndRank", "*** Attempting to get cluster {0} config {1}!", IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, IsFullTest ? m_ConfigToCreateName : m_ExampleConfigName);
            m_RetrieveAndRank.GetClusterConfig(OnGetClusterConfig, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, IsFullTest ? m_ConfigToCreateName : m_ExampleConfigName);
            while (!m_GetClusterConfigTested)
            {
                yield return(null);
            }
#if TEST_CREATE_DELETE
            //  Create Collection
            Log.Debug("TestRetrieveAndRank", "*** Attempting to create collection!");
            m_RetrieveAndRank.ForwardCollectionRequest(OnCreateCollections, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, CollectionsAction.CREATE, m_CollectionToCreateName, IsFullTest ? m_ConfigToCreateName : m_ExampleConfigName);
            while (!m_CreateCollectionRequestTested)
            {
                yield return(null);
            }
#endif
            //  List Collections
            Log.Debug("TestRetrieveAndRank", "*** Attempting to list collections!");
            if (!m_ListCollectionRequestTested)
            {
                m_RetrieveAndRank.ForwardCollectionRequest(OnListCollections, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, CollectionsAction.LIST);
                while (!m_ListCollectionRequestTested)
                {
                    yield return(null);
                }
            }

#if TEST_CREATE_DELETE
            //  Index documents
            Log.Debug("TestRetrieveAndRank", "*** Attempting to index documents!");
            m_RetrieveAndRank.IndexDocuments(OnIndexDocuments, m_IntegrationTestIndexDataPath, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, m_CollectionToCreateName);
            while (!m_IndexDocumentsTested)
            {
                yield return(null);
            }
#endif

            //  Get rankers
            if (!m_GetRankersTested)
            {
                Log.Debug("TestRetrieveAndRank", "*** Attempting to get rankers!");
                m_RetrieveAndRank.GetRankers(OnGetRankers);
                while (!m_GetRankersTested)
                {
                    yield return(null);
                }
            }

#if TEST_CREATE_DELETE
            //  Create ranker
            Log.Debug("TestRetrieveAndRank", "*** Attempting to create rankers!");
            m_RetrieveAndRank.CreateRanker(OnCreateRanker, m_IntegrationTestRankerTrainingPath, m_RankerToCreateName);
            while (!m_CreateRankerTested)
            {
                yield return(null);
            }
#endif
            //  Get ranker info
            Log.Debug("TestRetrieveAndRank", "*** Attempting to get Ranker Info!");
            m_RetrieveAndRank.GetRanker(OnGetRanker, IsFullTest ? m_CreatedRankerID : m_ExampleRankerID);
            while (!m_GetRankerInfoTested || !m_IsRankerReady)
            {
                yield return(null);
            }

            //  Rank
            Log.Debug("TestRetrieveAndRank", "*** Attempting to rank!");
            m_RetrieveAndRank.Rank(OnRank, IsFullTest ? m_CreatedRankerID : m_ExampleRankerID, m_IntegrationTestRankerAnswerDataPath);
            while (!m_RankTested)
            {
                yield return(null);
            }

            //  Standard Search
            Log.Debug("TestRetrieveAndRank", "*** Attempting to search!");
            m_RetrieveAndRank.Search(OnStandardSearch, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, IsFullTest ? m_CollectionToCreateName : m_ExampleCollectionName, m_IntegrationTestQuery, m_Fl);
            while (!m_StandardSearchTested)
            {
                yield return(null);
            }

            //  Ranked Search
            //Log.Debug("TestRetrieveAndRank", "*** Attempting to search!");
            //m_RetrieveAndRank.Search(OnRankedSearch, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, IsFullTest ? m_CollectionToCreateName : m_ExampleCollectionName, m_IntegrationTestQuery, m_Fl, true, m_ExampleRankerID);
            //while (!m_RankedSearchTested)
            //    yield return null;

#if TEST_CREATE_DELETE
            //	Wait before deleting ranker
            Runnable.Run(WaitUp(5f));
            while (!m_IsDoneWaiting)
            {
                yield return(null);
            }

            //  Delete ranker
            if (!m_DeleteRankersTested)
            {
                Log.Debug("ExampleRetriveAndRank", "*** Attempting to delete ranker {0}, {1}!", m_RankerToCreateName, m_CreatedRankerID);
                m_RetrieveAndRank.DeleteRanker(OnDeleteRanker, m_CreatedRankerID);
                while (!m_DeleteRankersTested)
                {
                    yield return(null);
                }
            }

            //	Wait before deleting collection
            m_IsDoneWaiting = false;
            Runnable.Run(WaitUp(5f));
            while (!m_IsDoneWaiting)
            {
                yield return(null);
            }

            //  Delete Collection request
            if (!m_DeleteCollectionRequestTested)
            {
                Log.Debug("TestRetrieveAndRank", "*** Attempting to delete collection!");
                m_RetrieveAndRank.ForwardCollectionRequest(OnDeleteCollections, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, CollectionsAction.DELETE, m_CollectionToCreateName);
                while (!m_DeleteCollectionRequestTested)
                {
                    yield return(null);
                }
            }

            //	Wait before deleting config
            m_IsDoneWaiting = false;
            Runnable.Run(WaitUp(5f));
            while (!m_IsDoneWaiting)
            {
                yield return(null);
            }

            //  Delete cluster config
            if (!m_DeleteClusterConfigTested)
            {
                Log.Debug("TestRetrieveAndRank", "** Attempting to delete config {1} from cluster {0}!", IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, m_ConfigToCreateName);
                m_RetrieveAndRank.DeleteClusterConfig(OnDeleteClusterConfig, IsFullTest ? m_CreatedClusterID : m_ExampleClusterID, m_ConfigToCreateName);
                while (!m_DeleteClusterConfigTested)
                {
                    yield return(null);
                }
            }

            //	Wait before deleting cluster
            m_IsDoneWaiting = false;
            Runnable.Run(WaitUp(5f));
            while (!m_IsDoneWaiting)
            {
                yield return(null);
            }

            //  Delete cluster
            if (!m_DeleteClusterTested)
            {
                Log.Debug("TestRetrieveAndRank", "*** Attempting to delete cluster {0}!", m_CreatedClusterID);
                m_RetrieveAndRank.DeleteCluster(OnDeleteCluster, m_CreatedClusterID);
                while (!m_DeleteClusterTested)
                {
                    yield return(null);
                }
            }
#endif
            yield break;
        }
Пример #3
0
    private IEnumerator Examples()
    {
        //  Get clusters
        Log.Debug("ExampleRetrieveAndRank", "Attempting to get clusters.");
        if (!_retrieveAndRank.GetClusters(OnGetClusters))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to get clusters!");
        }
        while (!_getClustersTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Create cluster
        Log.Debug("ExampleRetrieveAndRank", "Attempting to create cluster.");
        if (!_retrieveAndRank.CreateCluster(OnCreateCluster, "unity-test-cluster", "1"))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to create cluster!");
        }
        while (!_createClusterTested || !_readyToContinue)
        {
            yield return(null);
        }

        //  Wait for cluster status to be `READY`.
        CheckClusterStatus();
        while (!_isClusterReady)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  List cluster configs
        Log.Debug("ExampleRetrieveAndRank", "Attempting to get cluster configs.");
        if (!_retrieveAndRank.GetClusterConfigs(OnGetClusterConfigs, _clusterToDelete))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to get cluster configs!");
        }
        while (!_getClusterConfigsTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Upload cluster config
        Log.Debug("ExampleRetrieveAndRank", "Attempting to upload cluster config.");
        if (!_retrieveAndRank.UploadClusterConfig(OnUploadClusterConfig, _clusterToDelete, _testClusterConfigName, _testClusterConfigPath))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to upload cluster config {0}!", _testClusterConfigPath);
        }
        while (!_uploadClusterConfigTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Get cluster
        Log.Debug("ExampleRetrieveAndRank", "Attempting to get cluster.");
        if (!_retrieveAndRank.GetCluster(OnGetCluster, _clusterToDelete))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to get cluster!");
        }
        while (!_getClusterTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Get cluster config
        Log.Debug("ExampleRetrieveAndRank", "Attempting to get cluster config.");
        if (!_retrieveAndRank.GetClusterConfig(OnGetClusterConfig, _clusterToDelete, _testClusterConfigName))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to get cluster config {0}!", _testClusterConfigName);
        }
        while (!_getClusterConfigTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  List Collection request
        Log.Debug("ExampleRetrieveAndRank", "Attempting to get collections.");
        if (!_retrieveAndRank.ForwardCollectionRequest(OnGetCollections, _clusterToDelete, CollectionsAction.List))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to get collections!");
        }
        while (!_getCollectionsTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Create Collection request
        Log.Debug("ExampleRetrieveAndRank", "Attempting to create collection.");
        if (!_retrieveAndRank.ForwardCollectionRequest(OnCreateCollection, _clusterToDelete, CollectionsAction.Create, _collectionNameToDelete, _testClusterConfigName))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to create collections!");
        }
        while (!_createCollectionTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Index documents
        Log.Debug("ExampleRetrieveAndRank", "Attempting to index documents.");
        if (!_retrieveAndRank.IndexDocuments(OnIndexDocuments, _indexDataPath, _clusterToDelete, _collectionNameToDelete))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to index documents!");
        }
        while (!_indexDocumentsTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Get rankers
        Log.Debug("ExampleRetrieveAndRank", "Attempting to get rankers.");
        if (!_retrieveAndRank.GetRankers(OnGetRankers))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to get rankers!");
        }
        while (!_getRankersTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Create ranker
        Log.Debug("ExampleRetrieveAndRank", "Attempting to create ranker.");
        if (!_retrieveAndRank.CreateRanker(OnCreateRanker, _testRankerTrainingPath, _createdRankerName))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to create ranker!");
        }
        while (!_createRankerTested || !_readyToContinue)
        {
            yield return(null);
        }

        //  Wait for ranker status to be `Available`.
        Log.Debug("ExampleRetrieveAndRank", "Checking ranker status in 10 seconds");
        CheckRankerStatus();
        while (!_isRankerReady || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Standard Search
        string[] fl = { "title", "id", "body", "author", "bibliography" };
        Log.Debug("ExampleRetrieveAndRank", "Attempting to search standard.");
        if (!_retrieveAndRank.Search(OnSearchStandard, _clusterToDelete, _collectionNameToDelete, _testQuery, fl))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to search!");
        }
        while (!_searchStandardTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Rank
        Log.Debug("ExampleRetrieveAndRank", "Attempting to rank.");
        if (!_retrieveAndRank.Rank(OnRank, _rankerIdToDelete, _testAnswerDataPath))
        {
            Log.Debug("ExampleRetriveAndRank", "Failed to rank!");
        }
        while (!_rankTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Get ranker info
        Log.Debug("ExampleRetrieveAndRank", "Attempting to get rankers.");
        if (!_retrieveAndRank.GetRanker(OnGetRanker, _rankerIdToDelete))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to get ranker!");
        }
        while (!_getRankerTested)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Delete rankers
        Log.Debug("ExampleRetrieveAndRank", "Attempting to delete ranker {0}.", _rankerIdToDelete);
        if (!_retrieveAndRank.DeleteRanker(OnDeleteRanker, _rankerIdToDelete))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to delete ranker {0}!", _rankerIdToDelete);
        }
        while (!_deleteRankerTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Delete Collection request
        Log.Debug("ExampleRetrieveAndRank", "Attempting to delete collection {0}.", "TestCollectionToDelete");
        if (!_retrieveAndRank.ForwardCollectionRequest(OnDeleteCollection, _clusterToDelete, CollectionsAction.Delete, "TestCollectionToDelete"))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to delete collections!");
        }
        while (!_deleteCollectionTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Delete cluster config
        string clusterConfigToDelete = "test-config";

        Log.Debug("ExampleRetrieveAndRank", "Attempting to delete cluster config.");
        if (!_retrieveAndRank.DeleteClusterConfig(OnDeleteClusterConfig, _clusterToDelete, clusterConfigToDelete))
        {
            Log.Debug("ExampleRetriveAndRank", "Failed to delete cluster config {0}", clusterConfigToDelete);
        }
        while (!_deleteClusterConfigTested || !_readyToContinue)
        {
            yield return(null);
        }

        _readyToContinue = false;
        //  Delete cluster
        Log.Debug("ExampleRetrieveAndRank", "Attempting to delete cluster {0}.", _clusterToDelete);
        if (!_retrieveAndRank.DeleteCluster(OnDeleteCluster, _clusterToDelete))
        {
            Log.Debug("ExampleRetrieveAndRank", "Failed to delete cluster!");
        }
        while (!_deleteClusterTested || !_readyToContinue)
        {
            yield return(null);
        }

        Log.Debug("ExampleRetrieveAndRank", "Retrieve and rank examples complete!");
    }