lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [01/20] lucenenet git commit: LUCENENET-565: Porting of Lucene Replicator - Commit is for Review with comments about original Java Source for assistance.
Date Fri, 18 Aug 2017 08:04:48 GMT
Repository: lucenenet
Updated Branches:
  refs/heads/replicator [created] 140551230


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6da4dd20/src/Lucene.Net.Tests.Replicator/Properties/AssemblyInfo.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Replicator/Properties/AssemblyInfo.cs b/src/Lucene.Net.Tests.Replicator/Properties/AssemblyInfo.cs
new file mode 100644
index 0000000..457c56c
--- /dev/null
+++ b/src/Lucene.Net.Tests.Replicator/Properties/AssemblyInfo.cs
@@ -0,0 +1,19 @@
+´╗┐using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Lucene.Net.Tests.Replicator")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCulture("")]
+
+// Setting ComVisible to false makes the types in this assembly not visible
+// to COM components.  If you need to access a type in this assembly from
+// COM, set the ComVisible attribute to true on that type.
+[assembly: ComVisible(false)]
+
+// The following GUID is for the ID of the typelib if this project is exposed to COM
+[assembly: Guid("418e9d8e-2369-4b52-8d2f-5a987213999b")]

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6da4dd20/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs b/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs
new file mode 100644
index 0000000..1b8ec1e
--- /dev/null
+++ b/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs
@@ -0,0 +1,192 @@
+//STATUS: PENDING - 4.8.0
+
+using System;
+using Lucene.Net.Replicator.Http;
+using Lucene.Net.Util;
+using Microsoft.AspNetCore.Hosting;
+using Microsoft.AspNetCore.TestHost;
+using Microsoft.Extensions.DependencyInjection;
+
+namespace Lucene.Net.Tests.Replicator
+{
+    /*
+	 * Licensed to the Apache Software Foundation (ASF) under one or more
+	 * contributor license agreements.  See the NOTICE file distributed with
+	 * this work for additional information regarding copyright ownership.
+	 * The ASF licenses this file to You under the Apache License, Version 2.0
+	 * (the "License"); you may not use this file except in compliance with
+	 * the License.  You may obtain a copy of the License at
+	 *
+	 *     http://www.apache.org/licenses/LICENSE-2.0
+	 *
+	 * Unless required by applicable law or agreed to in writing, software
+	 * distributed under the License is distributed on an "AS IS" BASIS,
+	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	 * See the License for the specific language governing permissions and
+	 * limitations under the License.
+	 */
+
+    public class ReplicatorTestCase : LuceneTestCase
+    {
+        //JAVA:  private static ClientConnectionManager clientConnectionManager;
+        //JAVA:  
+        //JAVA:  @AfterClass
+        //JAVA:  public static void afterClassReplicatorTestCase() throws Exception {
+        //JAVA:    if (clientConnectionManager != null) {
+        //JAVA:      clientConnectionManager.shutdown();
+        //JAVA:      clientConnectionManager = null;
+        //JAVA:    }
+        //JAVA:  }
+        //JAVA:  
+
+
+        public static TestServer NewHttpServer<TStartUp>(ReplicationService service)
where TStartUp : class
+        {
+            #region JAVA
+            //JAVA:  /**
+            //JAVA:   * Returns a new {@link Server HTTP Server} instance. To obtain its
port, use
+            //JAVA:   * {@link #serverPort(Server)}.
+            //JAVA:   */
+            //JAVA:  public static synchronized Server newHttpServer(Handler handler) throws
Exception {
+            //JAVA:    Server server = new Server(0);
+            //JAVA:    
+            //JAVA:    server.setHandler(handler);
+            //JAVA:    
+            //JAVA:    final String connectorName = System.getProperty("tests.jettyConnector",
"SelectChannel");
+            //JAVA:    
+            //JAVA:    // if this property is true, then jetty will be configured to use
SSL
+            //JAVA:    // leveraging the same system properties as java to specify
+            //JAVA:    // the keystore/truststore if they are set
+            //JAVA:    //
+            //JAVA:    // This means we will use the same truststore, keystore (and keys)
for
+            //JAVA:    // the server as well as any client actions taken by this JVM in
+            //JAVA:    // talking to that server, but for the purposes of testing that should

+            //JAVA:    // be good enough
+            //JAVA:    final boolean useSsl = Boolean.getBoolean("tests.jettySsl");
+            //JAVA:    final SslContextFactory sslcontext = new SslContextFactory(false);
+            //JAVA:    
+            //JAVA:    if (useSsl) {
+            //JAVA:      if (null != System.getProperty("javax.net.ssl.keyStore")) {
+            //JAVA:        sslcontext.setKeyStorePath
+            //JAVA:        (System.getProperty("javax.net.ssl.keyStore"));
+            //JAVA:      }
+            //JAVA:      if (null != System.getProperty("javax.net.ssl.keyStorePassword"))
{
+            //JAVA:        sslcontext.setKeyStorePassword
+            //JAVA:        (System.getProperty("javax.net.ssl.keyStorePassword"));
+            //JAVA:      }
+            //JAVA:      if (null != System.getProperty("javax.net.ssl.trustStore")) {
+            //JAVA:        sslcontext.setTrustStore
+            //JAVA:        (System.getProperty("javax.net.ssl.trustStore"));
+            //JAVA:      }
+            //JAVA:      if (null != System.getProperty("javax.net.ssl.trustStorePassword"))
{
+            //JAVA:        sslcontext.setTrustStorePassword
+            //JAVA:        (System.getProperty("javax.net.ssl.trustStorePassword"));
+            //JAVA:      }
+            //JAVA:      sslcontext.setNeedClientAuth(Boolean.getBoolean("tests.jettySsl.clientAuth"));
+            //JAVA:    }
+            //JAVA:    
+            //JAVA:    final Connector connector;
+            //JAVA:    final QueuedThreadPool threadPool;
+            //JAVA:    if ("SelectChannel".equals(connectorName)) {
+            //JAVA:      final SelectChannelConnector c = useSsl ? new SslSelectChannelConnector(sslcontext)
: new SelectChannelConnector();
+            //JAVA:      c.setReuseAddress(true);
+            //JAVA:      c.setLowResourcesMaxIdleTime(1500);
+            //JAVA:      connector = c;
+            //JAVA:      threadPool = (QueuedThreadPool) c.getThreadPool();
+            //JAVA:    } else if ("Socket".equals(connectorName)) {
+            //JAVA:      final SocketConnector c = useSsl ? new SslSocketConnector(sslcontext)
: new SocketConnector();
+            //JAVA:      c.setReuseAddress(true);
+            //JAVA:      connector = c;
+            //JAVA:      threadPool = (QueuedThreadPool) c.getThreadPool();
+            //JAVA:    } else {
+            //JAVA:      throw new IllegalArgumentException("Illegal value for system property
'tests.jettyConnector': " + connectorName);
+            //JAVA:    }
+            //JAVA:    
+            //JAVA:    connector.setPort(0);
+            //JAVA:    connector.setHost("127.0.0.1");
+            //JAVA:    if (threadPool != null) {
+            //JAVA:      threadPool.setDaemon(true);
+            //JAVA:      threadPool.setMaxThreads(10000);
+            //JAVA:      threadPool.setMaxIdleTimeMs(5000);
+            //JAVA:      threadPool.setMaxStopTimeMs(30000);
+            //JAVA:    }
+            //JAVA:    
+            //JAVA:    server.setConnectors(new Connector[] {connector});
+            //JAVA:    server.setSessionIdManager(new HashSessionIdManager(new Random(random().nextLong())));
+            //JAVA:    
+            //JAVA:    server.start();
+            //JAVA:    
+            //JAVA:    return server;
+            //JAVA:  }
+            //JAVA:  
+            #endregion
+
+            var server = new TestServer(new WebHostBuilder()
+                .ConfigureServices(container =>
+                {
+                    container.AddSingleton(service);
+                }).UseStartup<TStartUp>());
+            server.BaseAddress = new Uri("http://localhost" + ReplicationService.REPLICATION_CONTEXT);
+            return server;
+        }
+
+        /// <summary>
+        /// Returns a <see cref="server"/>'s port. 
+        /// </summary>
+        public static int ServerPort(TestServer server)
+        {
+            //JAVA:  /** Returns a {@link Server}'s port. */
+            //JAVA:  public static int serverPort(Server server) {
+            //JAVA:    return server.getConnectors()[0].getLocalPort();
+            //JAVA:  }
+            return server.BaseAddress.Port;
+        }
+
+        /// <summary>
+        /// Returns a <see cref="server"/>'s host. 
+        /// </summary>
+        public static string ServerHost(TestServer server)
+        {
+            //JAVA:  /** Returns a {@link Server}'s host. */
+            //JAVA:  public static String serverHost(Server server) {
+            //JAVA:    return server.getConnectors()[0].getHost();
+            //JAVA:  }
+            return server.BaseAddress.Host;
+        }
+
+        /// <summary>
+        /// Stops the given HTTP Server instance.
+        /// </summary>
+        public static void StopHttpServer(TestServer server)
+        {
+            //JAVA:  /**
+            //JAVA:   * Stops the given HTTP Server instance. This method does its best to
guarantee
+            //JAVA:   * that no threads will be left running following this method.
+            //JAVA:   */
+            //JAVA:  public static void stopHttpServer(Server httpServer) throws Exception
{
+            //JAVA:    httpServer.stop();
+            //JAVA:    httpServer.join();
+            //JAVA:  }
+            server.Dispose();
+        }
+
+        //JAVA:  
+        //JAVA:  /**
+        //JAVA:   * Returns a {@link ClientConnectionManager}.
+        //JAVA:   * <p>
+        //JAVA:   * <b>NOTE:</b> do not {@link ClientConnectionManager#shutdown()}
this
+        //JAVA:   * connection manager, it will be shutdown automatically after all tests
have
+        //JAVA:   * finished.
+        //JAVA:   */
+        //JAVA:  public static synchronized ClientConnectionManager getClientConnectionManager()
{
+        //JAVA:    if (clientConnectionManager == null) {
+        //JAVA:      PoolingClientConnectionManager ccm = new PoolingClientConnectionManager();
+        //JAVA:      ccm.setDefaultMaxPerRoute(128);
+        //JAVA:      ccm.setMaxTotal(128);
+        //JAVA:      clientConnectionManager = ccm;
+        //JAVA:    }
+        //JAVA:    
+        //JAVA:    return clientConnectionManager;
+        //JAVA:  }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6da4dd20/src/Lucene.Net.Tests.Replicator/SessionTokenTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Replicator/SessionTokenTest.cs b/src/Lucene.Net.Tests.Replicator/SessionTokenTest.cs
new file mode 100644
index 0000000..7c98f88
--- /dev/null
+++ b/src/Lucene.Net.Tests.Replicator/SessionTokenTest.cs
@@ -0,0 +1,67 @@
+//STATUS: DRAFT - 4.8.0
+
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Lucene.Net.Documents;
+using Lucene.Net.Index;
+using Lucene.Net.Replicator;
+using Lucene.Net.Store;
+using Lucene.Net.Support.IO;
+using Lucene.Net.Util;
+using NUnit.Framework;
+using Directory = Lucene.Net.Store.Directory;
+
+namespace Lucene.Net.Tests.Replicator
+{
+    /*
+	 * Licensed to the Apache Software Foundation (ASF) under one or more
+	 * contributor license agreements.  See the NOTICE file distributed with
+	 * this work for additional information regarding copyright ownership.
+	 * The ASF licenses this file to You under the Apache License, Version 2.0
+	 * (the "License"); you may not use this file except in compliance with
+	 * the License.  You may obtain a copy of the License at
+	 *
+	 *     http://www.apache.org/licenses/LICENSE-2.0
+	 *
+	 * Unless required by applicable law or agreed to in writing, software
+	 * distributed under the License is distributed on an "AS IS" BASIS,
+	 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+	 * See the License for the specific language governing permissions and
+	 * limitations under the License.
+	 */
+
+    public class SessionTokenTest : ReplicatorTestCase
+    {
+        [Test]
+        public void TestSerialization()
+        {
+            Directory directory = NewDirectory();
+            IndexWriterConfig config = new IndexWriterConfig(TEST_VERSION_CURRENT, null);
+            config.IndexDeletionPolicy = new SnapshotDeletionPolicy(config.IndexDeletionPolicy);
+
+            IndexWriter writer = new IndexWriter(directory, config);
+            writer.AddDocument(new Document());
+            writer.Commit();
+            IRevision revision = new IndexRevision(writer);
+
+            SessionToken session1 = new SessionToken("17", revision);
+            MemoryStream baos = new MemoryStream();
+            session1.Serialize(new DataOutputStream(baos));
+            byte[] b = baos.ToArray();
+
+            SessionToken session2 = new SessionToken(new DataInputStream(new MemoryStream(b)));
+            assertEquals(session1.Id, session2.Id);
+            assertEquals(session1.Version, session2.Version);
+            assertEquals(1, session2.SourceFiles.Count);
+            assertEquals(session1.SourceFiles.Count, session2.SourceFiles.Count);
+            assertEquals(session1.SourceFiles.Keys, session2.SourceFiles.Keys);
+            IList<RevisionFile> files1 = session1.SourceFiles.Values.First();
+            IList<RevisionFile> files2 = session2.SourceFiles.Values.First();
+            assertEquals(files1, files2);
+
+            IOUtils.Dispose(writer, directory);
+        }
+        
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/6da4dd20/src/Lucene.Net.Tests.Replicator/packages.config
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Tests.Replicator/packages.config b/src/Lucene.Net.Tests.Replicator/packages.config
new file mode 100644
index 0000000..1f96d54
--- /dev/null
+++ b/src/Lucene.Net.Tests.Replicator/packages.config
@@ -0,0 +1,52 @@
+´╗┐<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Microsoft.AspNetCore.Hosting" version="1.0.3" targetFramework="net451"
/>
+  <package id="Microsoft.AspNetCore.Hosting.Abstractions" version="1.0.3" targetFramework="net451"
/>
+  <package id="Microsoft.AspNetCore.Hosting.Server.Abstractions" version="1.0.3" targetFramework="net451"
/>
+  <package id="Microsoft.AspNetCore.Http" version="1.0.3" targetFramework="net451" />
+  <package id="Microsoft.AspNetCore.Http.Abstractions" version="1.0.3" targetFramework="net451"
/>
+  <package id="Microsoft.AspNetCore.Http.Extensions" version="1.0.3" targetFramework="net451"
/>
+  <package id="Microsoft.AspNetCore.Http.Features" version="1.0.3" targetFramework="net451"
/>
+  <package id="Microsoft.AspNetCore.TestHost" version="1.0.3" targetFramework="net451"
/>
+  <package id="Microsoft.AspNetCore.WebUtilities" version="1.0.3" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.Configuration" version="1.0.2" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.Configuration.Abstractions" version="1.0.2" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.Configuration.EnvironmentVariables" version="1.0.2"
targetFramework="net451" />
+  <package id="Microsoft.Extensions.DependencyInjection" version="1.0.2" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="1.0.2"
targetFramework="net451" />
+  <package id="Microsoft.Extensions.FileProviders.Abstractions" version="1.0.1" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.FileProviders.Physical" version="1.0.1" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.FileSystemGlobbing" version="1.0.1" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.Logging" version="1.0.2" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.Logging.Abstractions" version="1.0.2" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.ObjectPool" version="1.0.1" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.Options" version="1.0.2" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.PlatformAbstractions" version="1.0.0" targetFramework="net451"
/>
+  <package id="Microsoft.Extensions.Primitives" version="1.0.1" targetFramework="net451"
/>
+  <package id="Microsoft.Net.Http.Headers" version="1.0.3" targetFramework="net451" />
+  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net451" />
+  <package id="NUnit" version="3.5.0" targetFramework="net451" />
+  <package id="System.Buffers" version="4.0.0" targetFramework="net451" />
+  <package id="System.Collections" version="4.0.11" targetFramework="net451" />
+  <package id="System.Collections.Concurrent" version="4.0.12" targetFramework="net451"
/>
+  <package id="System.Collections.Immutable" version="1.2.0" targetFramework="net451"
/>
+  <package id="System.ComponentModel" version="4.0.1" targetFramework="net451" />
+  <package id="System.Diagnostics.Contracts" version="4.0.1" targetFramework="net451"
/>
+  <package id="System.Diagnostics.Debug" version="4.0.11" targetFramework="net451" />
+  <package id="System.Diagnostics.DiagnosticSource" version="4.0.0" targetFramework="net451"
/>
+  <package id="System.Globalization" version="4.0.11" targetFramework="net451" />
+  <package id="System.IO" version="4.1.0" targetFramework="net451" />
+  <package id="System.Linq" version="4.1.0" targetFramework="net451" />
+  <package id="System.Linq.Expressions" version="4.1.1" targetFramework="net451" />
+  <package id="System.Reflection" version="4.1.0" targetFramework="net451" />
+  <package id="System.Reflection.Metadata" version="1.3.0" targetFramework="net451" />
+  <package id="System.Resources.ResourceManager" version="4.0.1" targetFramework="net451"
/>
+  <package id="System.Runtime" version="4.1.0" targetFramework="net451" />
+  <package id="System.Runtime.Extensions" version="4.1.0" targetFramework="net451" />
+  <package id="System.Runtime.InteropServices" version="4.1.0" targetFramework="net451"
/>
+  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.0.0" targetFramework="net451"
/>
+  <package id="System.Text.Encoding" version="4.0.11" targetFramework="net451" />
+  <package id="System.Text.Encodings.Web" version="4.0.1" targetFramework="net451" />
+  <package id="System.Threading" version="4.0.11" targetFramework="net451" />
+  <package id="System.Threading.Tasks" version="4.0.11" targetFramework="net451" />
+</packages>
\ No newline at end of file


Mime
View raw message