public void TestTimeout() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info1 = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info1); APIConfiguration config = info1.CreateDefaultAPIConfiguration(); config.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(CreateApiOp)), 5000); config.SetTimeout(SafeType <APIOperation> .ForRawType(typeof(SearchApiOp)), 5000); ConfigurationProperties props = config.ConfigurationProperties; ConfigurationProperty property = props.GetProperty("numResults"); // 1000 is several times the remote size between pauses property.Value = 2; OperationOptionsBuilder opBuilder = new OperationOptionsBuilder(); opBuilder.SetOption("delay", 10000); ConnectorFacade facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config); ICollection <ConnectorAttribute> attrs = CollectionUtil.NewReadOnlySet <ConnectorAttribute>(); try { facade1.Create(ObjectClass.ACCOUNT, attrs, opBuilder.Build()).GetUidValue(); Assert.Fail("expected timeout"); } catch (OperationTimeoutException) { // expected } //catch (RemoteWrappedException e) //{ // Assert.IsTrue(e.Is(typeof(OperationTimeoutException))); //} try { facade1.Search(ObjectClass.ACCOUNT, null, new ResultsHandler() { Handle = obj => { return(true); } }, opBuilder.Build()); Assert.Fail("expected timeout"); } catch (OperationTimeoutException) { // expected } //catch (RemoteWrappedException e) //{ // Assert.IsTrue(e.Is(typeof(OperationTimeoutException))); //} }
public virtual void TestSearch2() { ConnectorFacade search = GetFacade(); for (int i = 0; i < 100; i++) { ICollection <ConnectorAttribute> co = GetTestCreateConnectorObject(string.Format("TEST{0:D5}", i)); co.Add(ConnectorAttributeBuilder.Build("sortKey", i)); search.Create(ObjectClass.ACCOUNT, co, null); } OperationOptionsBuilder builder = new OperationOptionsBuilder { PageSize = 10, SortKeys = new[] { new SortKey("sortKey", false) } }; SearchResult result = null; ICollection <ConnectorObject> resultSet = new HashSet <ConnectorObject>(); int pageIndex = 0; int index = 101; while ((result = search.Search(ObjectClass.ACCOUNT, FilterBuilder.StartsWith(ConnectorAttributeBuilder.Build(Name.NAME, "TEST")), new ResultsHandler() { Handle = connectorObject => { int?idx = ConnectorAttributeUtil.GetIntegerValue(connectorObject.GetAttributeByName("sortKey")); Assert.IsTrue(idx < index); if (idx != null) { index = (int)idx; } resultSet.Add(connectorObject); return(true); } }, builder.Build())).PagedResultsCookie != null) { builder = new OperationOptionsBuilder(builder.Build()) { PagedResultsCookie = result.PagedResultsCookie }; Assert.AreEqual(10 * ++pageIndex, resultSet.Count); } Assert.AreEqual(9, pageIndex); Assert.AreEqual(100, resultSet.Count); }
public void TestPagedSearch() { ConnectorPoolManager.Dispose(); ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info1 = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstStatefulPoolableConnector"); Assert.IsNotNull(info1); APIConfiguration config = info1.CreateDefaultAPIConfiguration(); config.ProducerBufferSize = 0; config.ConnectorPoolConfiguration.MinIdle = 1; config.ConnectorPoolConfiguration.MaxIdle = 2; config.ResultsHandlerConfiguration.FilteredResultsHandlerInValidationMode = true; // for paged searches, the filtered results handler should be either disabled or put into validation mode ConnectorFacade facade1 = ConnectorFacadeFactory.GetInstance().NewInstance(config); OperationOptionsBuilder builder = new OperationOptionsBuilder(); builder.PageSize = 10; builder.SetSortKeys(new ICF.SortKey(Name.NAME, true)); SearchResult searchResult = null; ISet <Uid> UIDs = new HashSet <Uid>(); int iteration = 0; do { if (null != searchResult) { builder.PagedResultsCookie = searchResult.PagedResultsCookie; } int size = 0; searchResult = facade1.Search(ObjectClass.ACCOUNT, null, new ResultsHandler() { Handle = obj => { if (size >= 10) { Assert.Fail("More then 10 objects was handled!"); } size++; if (UIDs.Contains(obj.Uid)) { Assert.Fail("Duplicate Entry in results"); } return(UIDs.Add(obj.Uid)); } }, builder.Build()); iteration++; Assert.IsNotNull(searchResult); Assert.AreEqual(searchResult.RemainingPagedResults, 100 - (iteration * 10)); } while (searchResult.PagedResultsCookie != null); // Search with paged results offset builder = new OperationOptionsBuilder(); builder.PageSize = 10; builder.PagedResultsOffset = 5; builder.SetSortKeys(new ICF.SortKey(Name.NAME, true)); searchResult = null; UIDs.Clear(); Filter filter = FilterBuilder.EqualTo(ConnectorAttributeBuilder.BuildEnabled(true)); iteration = 0; do { if (null != searchResult) { builder.PagedResultsCookie = searchResult.PagedResultsCookie; } int size = 0; searchResult = facade1.Search(ObjectClass.ACCOUNT, filter, new ResultsHandler() { Handle = obj => { if (size >= 10) { Assert.Fail("More then 10 objects was handled!"); } size++; if (UIDs.Contains(obj.Uid)) { Assert.Fail("Duplicate Entry in results"); } return(UIDs.Add(obj.Uid)); } }, builder.Build()); iteration++; Assert.IsNotNull(searchResult); Assert.AreEqual(searchResult.RemainingPagedResults, Math.Max(50 - (iteration * 15), 0)); } while (searchResult.PagedResultsCookie != null); }
public void TestSearchWithManyResults() { ConnectorInfoManager manager = GetConnectorInfoManager(); ConnectorInfo info = FindConnectorInfo(manager, "1.0.0.0", "org.identityconnectors.testconnector.TstConnector"); Assert.IsNotNull(info); APIConfiguration api = info.CreateDefaultAPIConfiguration(); api.ProducerBufferSize = 0; ConfigurationProperties props = api.ConfigurationProperties; ConfigurationProperty property = props.GetProperty("numResults"); //1000 is several times the remote size between pauses property.Value = 1000; ConnectorFacadeFactory facf = ConnectorFacadeFactory.GetInstance(); ConnectorFacade facade = facf.NewInstance(api); IList <ConnectorObject> results = new List <ConnectorObject>(); SearchResult searchResult = facade.Search(ObjectClass.ACCOUNT, null, new ResultsHandler() { Handle = obj => { results.Add(obj); return(true); } }, null); Assert.AreEqual(1000, results.Count); Assert.AreEqual(0, searchResult.RemainingPagedResults); for (int i = 0; i < results.Count; i++) { ConnectorObject obj = results[i]; Assert.AreEqual(i.ToString(), obj.Uid.GetUidValue()); } results.Clear(); searchResult = facade.Search(ObjectClass.ACCOUNT, null, new ResultsHandler() { Handle = obj => { if (results.Count < 500) { results.Add(obj); return(true); } else { return(false); } } }, null); Assert.AreEqual(500, results.Count); Assert.IsTrue(500 == searchResult.RemainingPagedResults || 401 == searchResult.RemainingPagedResults); for (int i = 0; i < results.Count; i++) { ConnectorObject obj = results[i]; Assert.AreEqual(i.ToString(), obj.Uid.GetUidValue()); } }