多克米斯 / 露天 / 删除 => 创建 => 搜索延迟



我尝试将dotcmis和alfresco集成到我的应用程序中。创建单元测试时,我面临此问题:- 我通过删除"我的文件夹"(如果有)来设置我的测试环境- 我创建返回我的文件夹并将文档放入其中

然后我尝试找到文档:- 第一次(当myfolder之前不存在时),搜索返回0结果- 下次,当myfolder之前存在并被我的测试设置删除时,我会收到异常:

Apache Chemistry OpenCMIS - runtime error
HTTP Status 500 - <!--exception-->runtime<!--/exception--><p><!--message-->Node does     not exist: missing://missing/missing(null)<!--/message--></p><hr noshade='noshade'/><!--    stacktrace--><pre>
org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException: Node does not exist: missing://missing/missing(null)
at org.alfresco.opencmis.AlfrescoCmisExceptionInterceptor.invoke(AlfrescoCmisExceptionInterceptor.java:80)
at ...

当我去Alfresco时,文档存在。似乎文件夹和文档尚不能查询,但为什么?如果我在注释中输入测试环境init,则找到该文档

也许我做错了什么,但是什么?

这是我的代码:

[TestMethod()]
[DeploymentItem(@"FilesSearchTest_1", @"FilesSearchTest_1")]
public void SearchTest_2()
{
    string myfoldername = "myfolder";
    // Session creation
    var p = new Dictionary<String, String>();
    p[SessionParameter.User] = _userName;
    p[SessionParameter.Password] = _userPassword;
    p[SessionParameter.BindingType] = BindingType.AtomPub;
    p[SessionParameter.AtomPubUrl] = _serverUrl;
    var session = DotCMIS.Client.Impl.SessionFactory.NewInstance().GetRepositories(p)[0].CreateSession();
    session.DefaultContext.CacheEnabled = false;
    var operationContext = session.CreateOperationContext();
    operationContext.IncludeAcls = true;
    // Delete and create back folder and document
    // /*
    DotCMIS.Client.IFolder rootFolder = this._testSession.GetRootFolder(operationContext);
    DotCMIS.Client.IFolder myFolder = null;
    Dictionary<String, Object> properties = null;
    // Le dossier de destination des tests existe-t-il ?
    var myFolderExists = rootFolder.GetChildren(operationContext).Any(child => child.Name.Equals(myfoldername));
    if (myFolderExists)
    {
        myFolder = (DotCMIS.Client.IFolder)session.GetObjectByPath(String.Format(@"/{0}", myfoldername), operationContext);
        myFolder.DeleteTree(true, DotCMIS.Enums.UnfileObject.Delete, true);
    }
    properties = new Dictionary<String, Object>();
    properties[PropertyIds.Name] = myfoldername;
    properties[PropertyIds.ObjectTypeId] = "cmis:folder";
    myFolder = rootFolder.CreateFolder(properties);
    rootFolder.Refresh();
    myFolder = (DotCMIS.Client.IFolder)session.GetObjectByPath(String.Format(@"/{0}", myfoldername), operationContext);
    FileInfo sourceFile = new FileInfo(@"FilesSearchTest_1SearchTest_1.pdf");
    properties = new Dictionary<String, Object>();
    properties[PropertyIds.ObjectTypeId] = "cmis:document";
    properties[PropertyIds.Name] = sourceFile.Name;
    using (var fileStream = sourceFile.OpenRead())
    {
        var contentStream = new DotCMIS.Data.Impl.ContentStream();
        contentStream.MimeType = "application/pdf";
        contentStream.Stream = fileStream;
        contentStream.Length = fileStream.Length;
        //this._testSession.CreateDocument(properties, this._testSession.CreateObjectId(myFolder.Id), contentStream, null);
        DotCMIS.Client.IDocument createdDocument = myFolder.CreateDocument(properties, contentStream, null);
    }
    // */
    // Recherche
    string query = @"SELECT * FROM cmis:document WHERE cmis:name = 'SearchTest_1.pdf'";
    var results = this._testSession.Query(query, false, operationContext).ToArray();
    Assert.AreEqual(1, results.Length);
}

您是否使用带有Solr的Alfresco 4.0进行索引?Solr 索引最终是一致的,这意味着更新可能需要一段时间(默认配置中最多 15 秒)才能显示在搜索结果中。

如果您需要立即显示更新,则可以切换到Lucene作为索引子系统。

我不认为solr的"最终一致性"方面是生产中的问题。可能是在测试时,但我更喜欢在生产中拥有更好的系统并且在调试中遇到一些问题,而不是相反。

为了解决我在调试中的问题,我首先放了一个 Thread.Sleep(20)...它奏效了,但是..调试时很长。

我的第二个似乎有效的解决方案是使用 url 地址检查 solr 的索引状态:8080/solr/admin/cores?action=REPORT(在我的代码中_solrStateUrl)。问题是默认情况下只能通过 SSL 访问它。因此,您需要从 afresco 服务器获取文件"browser.p12"并将其放入您的项目中。

所以我做了2个方法:- 检查索引状态,正在分析 xml 响应以查找正在进行的事务- WaitForIndexingDone,在CheckIndexingState上循环

这段代码可能不是很安全,但它只是为了测试......

在这里。希望这会帮助某人...

private bool CheckIndexingState()
{
    ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(delegate(object sender2, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; });
    System.Net.HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(_solrStateUrl);
    request.ClientCertificates.Add(new X509Certificate2(@"ssl/browser.p12", "alfresco"));
    var sb = new System.Text.StringBuilder();
    byte[] buffer = new byte[256];
    int nbRead = -1;
    using (var stream = request.GetResponse().GetResponseStream())
    {
        while (nbRead != 0)
        {
            nbRead = stream.Read(buffer, 0, 256);
            sb.Append(System.Text.Encoding.UTF8.GetString(buffer, 0, nbRead));
        }
    }
    String state = sb.ToString();
    try
    {
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(sb.ToString());
        var node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of transactions in the index but not the DB']");
        int count = Int32.Parse(node.InnerText);
        if (count > 0)
            return false;
        node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of acl transactions in the index but not the DB']");
        count = Int32.Parse(node.InnerText);
        if (count > 0)
            return false;
        node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of missing transactions from the Index']");
        count = Int32.Parse(node.InnerText);
        if (count > 0)
            return false;
        node = doc.SelectSingleNode(@"/response/lst[@name='report']/lst[@name='alfresco']/long[@name='Count of missing acl transactions from the Index']");
        count = Int32.Parse(node.InnerText);
        if (count > 0)
            return false;
    }
    catch (Exception)
    {
        throw;
    }
    return true;
}

相关内容

  • 没有找到相关文章

最新更新