http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/LocalReplicator.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/LocalReplicator.cs b/src/Lucene.Net.Replicator/LocalReplicator.cs index ae3a3a9..c32f8b7 100644 --- a/src/Lucene.Net.Replicator/LocalReplicator.cs +++ b/src/Lucene.Net.Replicator/LocalReplicator.cs @@ -2,10 +2,10 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; -using Lucene.Net.Search; using Lucene.Net.Support; namespace Lucene.Net.Replicator @@ -76,36 +76,6 @@ namespace Lucene.Net.Replicator public void Publish(IRevision revision) { - #region Java - //JAVA: public synchronized void publish(Revision revision) throws IOException { - //JAVA: ensureOpen(); - //JAVA: if (currentRevision != null) { - //JAVA: int compare = revision.compareTo(currentRevision.revision); - //JAVA: if (compare == 0) { - //JAVA: // same revision published again, ignore but release it - //JAVA: revision.release(); - //JAVA: return; - //JAVA: } - //JAVA: - //JAVA: if (compare < 0) { - //JAVA: revision.release(); - //JAVA: throw new IllegalArgumentException("Cannot publish an older revision: rev=" + revision + " current=" - //JAVA: + currentRevision); - //JAVA: } - //JAVA: } - //JAVA: - //JAVA: // swap revisions - //JAVA: final RefCountedRevision oldRevision = currentRevision; - //JAVA: currentRevision = new RefCountedRevision(revision); - //JAVA: if (oldRevision != null) { - //JAVA: oldRevision.decRef(); - //JAVA: } - //JAVA: - //JAVA: // check for expired sessions - //JAVA: checkExpiredSessions(); - //JAVA: } - #endregion - lock (padlock) { EnsureOpen(); @@ -137,34 +107,11 @@ namespace Lucene.Net.Replicator } /// <summary> - /// + /// TODO /// </summary> - /// <param name="currentVersion"></param> /// <returns></returns> public SessionToken CheckForUpdate(string currentVersion) { - #region Java - //JAVA: public synchronized SessionToken checkForUpdate(String currentVersion) { - //JAVA: ensureOpen(); - //JAVA: if (currentRevision == null) { // no published revisions yet - //JAVA: return null; - //JAVA: } - //JAVA: - //JAVA: if (currentVersion != null && currentRevision.revision.compareTo(currentVersion) <= 0) { - //JAVA: // currentVersion is newer or equal to latest published revision - //JAVA: return null; - //JAVA: } - //JAVA: - //JAVA: // currentVersion is either null or older than latest published revision - //JAVA: currentRevision.incRef(); - //JAVA: final String sessionID = Integer.toString(sessionToken.incrementAndGet()); - //JAVA: final SessionToken sessionToken = new SessionToken(sessionID, currentRevision.revision); - //JAVA: final ReplicationSession timedSessionToken = new ReplicationSession(sessionToken, currentRevision); - //JAVA: sessions.put(sessionID, timedSessionToken); - //JAVA: return sessionToken; - //JAVA: } - #endregion - lock (padlock) { EnsureOpen(); @@ -186,9 +133,8 @@ namespace Lucene.Net.Replicator } /// <summary> - /// + /// TODO /// </summary> - /// <param name="sessionId"></param> /// <exception cref="InvalidOperationException"></exception> public void Release(string sessionId) { @@ -199,26 +145,11 @@ namespace Lucene.Net.Replicator } } + /// <summary> + /// TODO + /// </summary> public Stream ObtainFile(string sessionId, string source, string fileName) { - #region Java - //JAVA: public synchronized InputStream obtainFile(String sessionID, String source, String fileName) throws IOException { - //JAVA: ensureOpen(); - //JAVA: ReplicationSession session = sessions.get(sessionID); - //JAVA: if (session != null && session.isExpired(expirationThresholdMilllis)) { - //JAVA: releaseSession(sessionID); - //JAVA: session = null; - //JAVA: } - //JAVA: // session either previously expired, or we just expired it - //JAVA: if (session == null) { - //JAVA: throw new SessionExpiredException("session (" + sessionID + ") expired while obtaining file: source=" + source - //JAVA: + " file=" + fileName); - //JAVA: } - //JAVA: sessions.get(sessionID).markAccessed(); - //JAVA: return session.revision.revision.open(source, fileName); - //JAVA: } - #endregion - lock (padlock) { EnsureOpen(); @@ -240,21 +171,11 @@ namespace Lucene.Net.Replicator } + /// <summary> + /// TODO + /// </summary> public void Dispose() { - #region Java - //JAVA: public synchronized void close() throws IOException { - //JAVA: if (!closed) { - //JAVA: // release all managed revisions - //JAVA: for (ReplicationSession session : sessions.values()) { - //JAVA: session.revision.decRef(); - //JAVA: } - //JAVA: sessions.clear(); - //JAVA: closed = true; - //JAVA: } - //JAVA: } - #endregion - if (disposed) return; @@ -270,21 +191,6 @@ namespace Lucene.Net.Replicator /// <exception cref="InvalidOperationException"></exception> private void CheckExpiredSessions() { - #region Java - //JAVA: private void checkExpiredSessions() throws IOException { - //JAVA: // make a "to-delete" list so we don't risk deleting from the map while iterating it - //JAVA: final ArrayList<ReplicationSession> toExpire = new ArrayList<>(); - //JAVA: for (ReplicationSession token : sessions.values()) { - //JAVA: if (token.isExpired(expirationThresholdMilllis)) { - //JAVA: toExpire.add(token); - //JAVA: } - //JAVA: } - //JAVA: for (ReplicationSession token : toExpire) { - //JAVA: releaseSession(token.session.id); - //JAVA: } - //JAVA: } - #endregion - // .NET NOTE: .ToArray() so we don't modify a collection we are enumerating... // I am wondering if it would be overall more practical to switch to a concurrent dictionary... foreach (ReplicationSession token in sessions.Values.Where(token => token.IsExpired(ExpirationThreshold)).ToArray()) @@ -296,17 +202,6 @@ namespace Lucene.Net.Replicator /// <exception cref="InvalidOperationException"></exception> private void ReleaseSession(string sessionId) { - #region Java - //JAVA: private void releaseSession(String sessionID) throws IOException { - //JAVA: ReplicationSession session = sessions.remove(sessionID); - //JAVA: // if we're called concurrently by close() and release(), could be that one - //JAVA: // thread beats the other to release the session. - //JAVA: if (session != null) { - //JAVA: session.revision.decRef(); - //JAVA: } - //JAVA: } - #endregion - ReplicationSession session; // if we're called concurrently by close() and release(), could be that one // thread beats the other to release the session. @@ -349,7 +244,6 @@ namespace Lucene.Net.Replicator { if (refCount.Get() <= 0) { - //JAVA: throw new IllegalStateException("this revision is already released"); throw new InvalidOperationException("this revision is already released"); } @@ -373,7 +267,6 @@ namespace Lucene.Net.Replicator } else if (rc < 0) { - //JAVA: throw new IllegalStateException("too many decRef calls: refCount is " + rc + " after decrement"); throw new InvalidOperationException(string.Format("too many decRef calls: refCount is {0} after decrement", rc)); } } @@ -395,19 +288,16 @@ namespace Lucene.Net.Replicator { Session = session; Revision = revision; - //JAVA: lastAccessTime = System.currentTimeMillis(); lastAccessTime = Stopwatch.GetTimestamp(); } public bool IsExpired(long expirationThreshold) { - //JAVA: return lastAccessTime < (System.currentTimeMillis() - expirationThreshold); return lastAccessTime < Stopwatch.GetTimestamp() - expirationThreshold * Stopwatch.Frequency / 1000; } public void MarkAccessed() { - //JAVA: lastAccessTime = System.currentTimeMillis(); lastAccessTime = Stopwatch.GetTimestamp(); } }
http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Lucene.Net.Replicator.csproj ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/Lucene.Net.Replicator.csproj b/src/Lucene.Net.Replicator/Lucene.Net.Replicator.csproj index 9481bd4..1b0b90f 100644 --- a/src/Lucene.Net.Replicator/Lucene.Net.Replicator.csproj +++ b/src/Lucene.Net.Replicator/Lucene.Net.Replicator.csproj @@ -64,8 +64,6 @@ <Reference Include="System.Xml" /> </ItemGroup> <ItemGroup> - <Compile Include="ComponentWrapperInfoStream.cs" /> - <Compile Include="Http\EnumerableExtensions.cs" /> <Compile Include="Http\HttpClientBase.cs" /> <Compile Include="Http\HttpReplicator.cs" /> <Compile Include="Http\Abstractions\IReplicationRequest.cs" /> http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs b/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs index e7f1d80..e65c8cb 100644 --- a/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs +++ b/src/Lucene.Net.Replicator/PerSessionDirectoryFactory.cs @@ -1,5 +1,3 @@ -//STATUS: DRAFT - 4.8.0 - using System; using System.IO; using Lucene.Net.Store; @@ -34,9 +32,6 @@ namespace Lucene.Net.Replicator /// </remarks> public class PerSessionDirectoryFactory : ISourceDirectoryFactory { - #region Java - //JAVA: private final File workDir; - #endregion private readonly string workingDirectory; /** Constructor with the given sources mapping. */ @@ -47,20 +42,6 @@ namespace Lucene.Net.Replicator public Directory GetDirectory(string sessionId, string source) { - #region Java - //JAVA: public Directory getDirectory(String sessionID, String source) throws IOException { - //JAVA: File sessionDir = new File(workDir, sessionID); - //JAVA: if (!sessionDir.exists() && !sessionDir.mkdirs()) { - //JAVA: throw new IOException("failed to create session directory " + sessionDir); - //JAVA: } - //JAVA: File sourceDir = new File(sessionDir, source); - //JAVA: if (!sourceDir.mkdirs()) { - //JAVA: throw new IOException("failed to create source directory " + sourceDir); - //JAVA: } - //JAVA: return FSDirectory.open(sourceDir); - //JAVA: } - #endregion - string sourceDirectory = Path.Combine(workingDirectory, sessionId, source); System.IO.Directory.CreateDirectory(sourceDirectory); return FSDirectory.Open(sourceDirectory); @@ -70,27 +51,8 @@ namespace Lucene.Net.Replicator { if (string.IsNullOrEmpty(sessionId)) throw new ArgumentException("sessionID cannot be empty", "sessionId"); - #region Java - //JAVA: rm(new File(workDir, sessionID)); - #endregion - string sessionDirectory = Path.Combine(workingDirectory, sessionId); System.IO.Directory.Delete(sessionDirectory, true); } - - #region Java - //JAVA: private void rm(File file) throws IOException { - //JAVA: if (file.isDirectory()) { - //JAVA: for (File f : file.listFiles()) { - //JAVA: rm(f); - //JAVA: } - //JAVA: } - //JAVA: - //JAVA: // This should be either an empty directory, or a file - //JAVA: if (!file.delete() && file.exists()) { - //JAVA: throw new IOException("failed to delete " + file); - //JAVA: } - //JAVA: } - #endregion } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/Properties/AssemblyInfo.cs b/src/Lucene.Net.Replicator/Properties/AssemblyInfo.cs index 898ca18..6cc1e58 100644 --- a/src/Lucene.Net.Replicator/Properties/AssemblyInfo.cs +++ b/src/Lucene.Net.Replicator/Properties/AssemblyInfo.cs @@ -1,6 +1,5 @@ using System; using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/ReplicationClient.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/ReplicationClient.cs b/src/Lucene.Net.Replicator/ReplicationClient.cs index 63837c9..14c1c2b 100644 --- a/src/Lucene.Net.Replicator/ReplicationClient.cs +++ b/src/Lucene.Net.Replicator/ReplicationClient.cs @@ -1,14 +1,11 @@ -//STATUS: DRAFT - 4.8.0 using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.IO; using System.Linq; -using System.Text; using System.Threading; using Lucene.Net.Store; -using Lucene.Net.Support; using Lucene.Net.Support.Threading; using Lucene.Net.Util; using Directory = Lucene.Net.Store.Directory; @@ -45,14 +42,16 @@ namespace Lucene.Net.Replicator /// <remarks> /// Lucene.Experimental /// </remarks> - public partial class ReplicationClient : IDisposable + public class ReplicationClient : IDisposable { /// <summary> /// The component name to use with <see cref="Util.InfoStream.IsEnabled"/> /// </summary> public const string INFO_STREAM_COMPONENT = "ReplicationThread"; - /// <summary> Gets or sets the <see cref="Util.InfoStream"/> to use for logging messages. </summary> + /// <summary> + /// Gets or sets the <see cref="Util.InfoStream"/> to use for logging messages. + /// </summary> public InfoStream InfoStream { get { return infoStream; } @@ -86,84 +85,6 @@ namespace Lucene.Net.Replicator /// <exception cref="IOException"></exception> private void DoUpdate() { - #region Java - //JAVA: private void doUpdate() throws IOException { - //JAVA: SessionToken session = null; - //JAVA: final Map<String,Directory> sourceDirectory = new HashMap<>(); - //JAVA: final Map<String,List<String>> copiedFiles = new HashMap<>(); - //JAVA: boolean notify = false; - //JAVA: try { - //JAVA: final String version = handler.currentVersion(); - //JAVA: session = replicator.checkForUpdate(version); - //JAVA: if (infoStream.isEnabled(INFO_STREAM_COMPONENT)) { - //JAVA: infoStream.message(INFO_STREAM_COMPONENT, "doUpdate(): handlerVersion=" + version + " session=" + session); - //JAVA: } - //JAVA: if (session == null) { - //JAVA: // already up to date - //JAVA: return; - //JAVA: } - //JAVA: Map<String,List<RevisionFile>> requiredFiles = requiredFiles(session.sourceFiles); - //JAVA: if (infoStream.isEnabled(INFO_STREAM_COMPONENT)) { - //JAVA: infoStream.message(INFO_STREAM_COMPONENT, "doUpdate(): requiredFiles=" + requiredFiles); - //JAVA: } - //JAVA: for (Entry<String,List<RevisionFile>> e : requiredFiles.entrySet()) { - //JAVA: String source = e.getKey(); - //JAVA: Directory dir = factory.getDirectory(session.id, source); - //JAVA: sourceDirectory.put(source, dir); - //JAVA: List<String> cpFiles = new ArrayList<>(); - //JAVA: copiedFiles.put(source, cpFiles); - //JAVA: for (RevisionFile file : e.getValue()) { - //JAVA: if (closed) { - //JAVA: // if we're closed, abort file copy - //JAVA: if (infoStream.isEnabled(INFO_STREAM_COMPONENT)) { - //JAVA: infoStream.message(INFO_STREAM_COMPONENT, "doUpdate(): detected client was closed); abort file copy"); - //JAVA: } - //JAVA: return; - //JAVA: } - //JAVA: InputStream in = null; - //JAVA: IndexOutput out = null; - //JAVA: try { - //JAVA: in = replicator.obtainFile(session.id, source, file.fileName); - //JAVA: out = dir.createOutput(file.fileName, IOContext.DEFAULT); - //JAVA: copyBytes(out, in); - //JAVA: cpFiles.add(file.fileName); - //JAVA: // TODO add some validation, on size / checksum - //JAVA: } finally { - //JAVA: IOUtils.close(in, out); - //JAVA: } - //JAVA: } - //JAVA: } - //JAVA: // only notify if all required files were successfully obtained. - //JAVA: notify = true; - //JAVA: } finally { - //JAVA: if (session != null) { - //JAVA: try { - //JAVA: replicator.release(session.id); - //JAVA: } finally { - //JAVA: if (!notify) { // cleanup after ourselves - //JAVA: IOUtils.close(sourceDirectory.values()); - //JAVA: factory.cleanupSession(session.id); - //JAVA: } - //JAVA: } - //JAVA: } - //JAVA: } - //JAVA: - //JAVA: // notify outside the try-finally above, so the session is released sooner. - //JAVA: // the handler may take time to finish acting on the copied files, but the - //JAVA: // session itself is no longer needed. - //JAVA: try { - //JAVA: if (notify && !closed ) { // no use to notify if we are closed already - //JAVA: handler.revisionReady(session.version, session.sourceFiles, copiedFiles, sourceDirectory); - //JAVA: } - //JAVA: } finally { - //JAVA: IOUtils.close(sourceDirectory.values()); - //JAVA: if (session != null) { - //JAVA: factory.cleanupSession(session.id); - //JAVA: } - //JAVA: } - //JAVA: } - #endregion - SessionToken session = null; Dictionary<string, Directory> sourceDirectory = new Dictionary<string, Directory>(); Dictionary<string, IList<string>> copiedFiles = new Dictionary<string, IList<string>>(); @@ -285,37 +206,6 @@ namespace Lucene.Net.Replicator /// <returns></returns> private IDictionary<string, IList<RevisionFile>> RequiredFiles(IDictionary<string, IList<RevisionFile>> newRevisionFiles) { - #region Java - //JAVA: protected Map<String,List<RevisionFile>> requiredFiles(Map<String,List<RevisionFile>> newRevisionFiles) { - //JAVA: Map<String,List<RevisionFile>> handlerRevisionFiles = handler.currentRevisionFiles(); - //JAVA: if (handlerRevisionFiles == null) { - //JAVA: return newRevisionFiles; - //JAVA: } - //JAVA: - //JAVA: Map<String,List<RevisionFile>> requiredFiles = new HashMap<>(); - //JAVA: for (Entry<String,List<RevisionFile>> e : handlerRevisionFiles.entrySet()) { - //JAVA: // put the handler files in a Set, for faster contains() checks later - //JAVA: Set<String> handlerFiles = new HashSet<>(); - //JAVA: for (RevisionFile file : e.getValue()) { - //JAVA: handlerFiles.add(file.fileName); - //JAVA: } - //JAVA: - //JAVA: // make sure to preserve revisionFiles order - //JAVA: ArrayList<RevisionFile> res = new ArrayList<>(); - //JAVA: String source = e.getKey(); - //JAVA: assert newRevisionFiles.containsKey(source) : "source not found in newRevisionFiles: " + newRevisionFiles; - //JAVA: for (RevisionFile file : newRevisionFiles.get(source)) { - //JAVA: if (!handlerFiles.contains(file.fileName)) { - //JAVA: res.add(file); - //JAVA: } - //JAVA: } - //JAVA: requiredFiles.put(source, res); - //JAVA: } - //JAVA: - //JAVA: return requiredFiles; - //JAVA: } - #endregion - IDictionary<string, IList<RevisionFile>> handlerRevisionFiles = handler.CurrentRevisionFiles; if (handlerRevisionFiles == null) return newRevisionFiles; @@ -346,22 +236,6 @@ namespace Lucene.Net.Replicator /// <exception cref="InvalidOperationException"> if the thread has already been started </exception> public void StartUpdateThread(long intervalMillis, string threadName) { - #region Java - //JAVA: public synchronized void startUpdateThread(long intervalMillis, String threadName) { - //JAVA: ensureOpen(); - //JAVA: if (updateThread != null && updateThread.isAlive()) { - //JAVA: throw new IllegalStateException( - //JAVA: "cannot start an update thread when one is running, must first call 'stopUpdateThread()'"); - //JAVA: } - //JAVA: threadName = threadName == null ? INFO_STREAM_COMPONENT : "ReplicationThread-" + threadName; - //JAVA: updateThread = new ReplicationThread(intervalMillis); - //JAVA: updateThread.setName(threadName); - //JAVA: updateThread.start(); - //JAVA: // we rely on isAlive to return true in isUpdateThreadAlive, assert to be on the safe side - //JAVA: assert updateThread.isAlive() : "updateThread started but not alive?"; - //JAVA: } - #endregion - EnsureOpen(); if (updateThread != null && updateThread.IsAlive) throw new InvalidOperationException("cannot start an update thread when one is running, must first call 'stopUpdateThread()'"); @@ -379,24 +253,6 @@ namespace Lucene.Net.Replicator /// </summary> public void StopUpdateThread() { - #region Java - //JAVA: public synchronized void stopUpdateThread() { - //JAVA: if (updateThread != null) { - //JAVA: // this will trigger the thread to terminate if it awaits the lock. - //JAVA: // otherwise, if it's in the middle of replication, we wait for it to - //JAVA: // stop. - //JAVA: updateThread.stop.countDown(); - //JAVA: try { - //JAVA: updateThread.join(); - //JAVA: } catch (InterruptedException e) { - //JAVA: Thread.currentThread().interrupt(); - //JAVA: throw new ThreadInterruptedException(e); - //JAVA: } - //JAVA: updateThread = null; - //JAVA: } - //JAVA: } - #endregion - // this will trigger the thread to terminate if it awaits the lock. // otherwise, if it's in the middle of replication, we wait for it to // stop. @@ -496,53 +352,6 @@ namespace Lucene.Net.Replicator //Note: LUCENENET specific, .NET does not work with Threads in the same way as Java does, so we mimic the same behavior using the ThreadPool instead. private class ReplicationThread { - #region Java - //JAVA: private class ReplicationThread extends Thread { - //JAVA: private final long interval; - //JAVA: // client uses this to stop us - //JAVA: final CountDownLatch stop = new CountDownLatch(1); - //JAVA: - //JAVA: public ReplicationThread(long interval) { - //JAVA: this.interval = interval; - //JAVA: } - //JAVA: - //JAVA: @SuppressWarnings("synthetic-access") - //JAVA: @Override - //JAVA: public void run() { - //JAVA: while (true) { - //JAVA: long time = System.currentTimeMillis(); - //JAVA: updateLock.lock(); - //JAVA: try { - //JAVA: doUpdate(); - //JAVA: } catch (Throwable t) { - //JAVA: handleUpdateException(t); - //JAVA: } finally { - //JAVA: updateLock.unlock(); - //JAVA: } - //JAVA: time = System.currentTimeMillis() - time; - //JAVA: - //JAVA: // adjust timeout to compensate the time spent doing the replication. - //JAVA: final long timeout = interval - time; - //JAVA: if (timeout > 0) { - //JAVA: try { - //JAVA: // this will return immediately if we were ordered to stop (count=0) - //JAVA: // or the timeout has elapsed. if it returns true, it means count=0, - //JAVA: // so terminate. - //JAVA: if (stop.await(timeout, TimeUnit.MILLISECONDS)) { - //JAVA: return; - //JAVA: } - //JAVA: } catch (InterruptedException e) { - //JAVA: // if we were interruted, somebody wants to terminate us, so just - //JAVA: // throw the exception further. - //JAVA: Thread.currentThread().interrupt(); - //JAVA: throw new ThreadInterruptedException(e); - //JAVA: } - //JAVA: } - //JAVA: } - //JAVA: } - //JAVA: } - #endregion - private readonly Action doUpdate; private readonly Action<Exception> handleException; private readonly ReentrantLock @lock; http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Replicator.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/Replicator.cs b/src/Lucene.Net.Replicator/Replicator.cs index af7ef51..28de0d3 100644 --- a/src/Lucene.Net.Replicator/Replicator.cs +++ b/src/Lucene.Net.Replicator/Replicator.cs @@ -1,4 +1,3 @@ -//STATUS: DRAFT - 4.8.0 using System; using System.IO; @@ -62,15 +61,12 @@ namespace Lucene.Net.Replicator /// should call <see cref="Release"/> so that the session resources can be /// reclaimed, including the revision files. /// </remarks> - /// <param name="currentVersion"></param> - /// <returns></returns> /// <exception cref="IOException"></exception> - SessionToken CheckForUpdate(string currentVersion);// throws IOException; + SessionToken CheckForUpdate(string currentVersion); /// <summary> /// Notify that the specified <see cref="SessionToken"/> is no longer needed by the caller. /// </summary> - /// <param name="sessionId"></param> /// <exception cref="IOException"></exception> void Release(string sessionId); @@ -81,10 +77,6 @@ namespace Lucene.Net.Replicator /// <remarks> /// It is the caller's responsibility to call <see cref="IDisposable.Dispose"/> on the returned stream. /// </remarks> - /// <param name="sessionId"></param> - /// <param name="source"></param> - /// <param name="fileName"></param> - /// <returns></returns> /// <exception cref="SessionExpiredException">The specified session has already expired</exception> Stream ObtainFile(string sessionId, string source, string fileName); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/Revision.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/Revision.cs b/src/Lucene.Net.Replicator/Revision.cs index 3d6fe19..57d7ffb 100644 --- a/src/Lucene.Net.Replicator/Revision.cs +++ b/src/Lucene.Net.Replicator/Revision.cs @@ -1,5 +1,3 @@ -//STATUS: DRAFT - 4.8.0 - using System; using System.Collections.Generic; using System.IO; @@ -60,15 +58,11 @@ namespace Lucene.Net.Replicator int CompareTo(string version); /// <summary> - /// Returns an {@link IndexInput} for the given fileName and source. It is the - /// caller's respnsibility to close the {@link IndexInput} when it has been + /// Returns a <see cref="Stream"/> for the given fileName and source. It is the + /// caller's respnsibility to close the <see cref="Stream"/> when it has been /// consumed. /// </summary> - /// <param name="source"></param> - /// <param name="fileName"></param> - /// <returns></returns> /// <exception cref="IOException"></exception> - //TODO: Stream or IndexInput? Stream Open(string source, string fileName); /// <summary> http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/RevisionFile.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/RevisionFile.cs b/src/Lucene.Net.Replicator/RevisionFile.cs index abd7aff..3d54719 100644 --- a/src/Lucene.Net.Replicator/RevisionFile.cs +++ b/src/Lucene.Net.Replicator/RevisionFile.cs @@ -1,5 +1,3 @@ -//STATUS: DRAFT - 4.8.0 - using System; namespace Lucene.Net.Replicator @@ -35,7 +33,6 @@ namespace Lucene.Net.Replicator /// </summary> public string FileName { get; private set; } - //TODO: can this be readonly? /// <summary> /// Gets or sets the length of the file denoted by <see cref="FileName"/>. /// </summary> @@ -44,7 +41,7 @@ namespace Lucene.Net.Replicator /// <summary> /// Constructor with the given file name and optionally length. /// </summary> - /// <param name="fileName"></param> + /// <param name="fileName">The name of the file</param> /// <param name="length">Optional, the length of the file.</param> public RevisionFile(string fileName, long length = -1) { http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/SessionExpiredException.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/SessionExpiredException.cs b/src/Lucene.Net.Replicator/SessionExpiredException.cs index 38eed6c..7aeb426 100644 --- a/src/Lucene.Net.Replicator/SessionExpiredException.cs +++ b/src/Lucene.Net.Replicator/SessionExpiredException.cs @@ -1,8 +1,5 @@ -//STATUS: DRAFT - 4.8.0 - using System; using System.IO; -using System.Runtime.Serialization; namespace Lucene.Net.Replicator { http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Replicator/SessionToken.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Replicator/SessionToken.cs b/src/Lucene.Net.Replicator/SessionToken.cs index a9440d7..c998137 100644 --- a/src/Lucene.Net.Replicator/SessionToken.cs +++ b/src/Lucene.Net.Replicator/SessionToken.cs @@ -1,8 +1,4 @@ -//STATUS: DRAFT - 4.8.0 - -using System; using System.Collections.Generic; -using System.Collections.ObjectModel; using System.IO; using Lucene.Net.Store; using Lucene.Net.Support.IO; @@ -67,7 +63,7 @@ namespace Lucene.Net.Replicator Id = reader.ReadUTF(); Version = reader.ReadUTF(); - var sourceFiles = new Dictionary<string, IList<RevisionFile>>(); + Dictionary<string, IList<RevisionFile>> sourceFiles = new Dictionary<string, IList<RevisionFile>>(); int numSources = reader.ReadInt32(); while (numSources > 0) { http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj index 533a4ec..d9f4abd 100644 --- a/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj +++ b/src/Lucene.Net.TestFramework/Lucene.Net.TestFramework.csproj @@ -1,4 +1,4 @@ -<?xml version="1.0" encoding="utf-8"?> +<?xml version="1.0" encoding="utf-8"?> <!-- Licensed to the Apache Software Foundation (ASF) under one @@ -19,7 +19,6 @@ under the License. --> - <Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> <PropertyGroup> @@ -530,4 +529,4 @@ <Target Name="AfterBuild"> </Target> --> -</Project> +</Project> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Tests.Replicator/Http/HttpReplicatorTest.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests.Replicator/Http/HttpReplicatorTest.cs b/src/Lucene.Net.Tests.Replicator/Http/HttpReplicatorTest.cs index 3d116f9..6254be6 100644 --- a/src/Lucene.Net.Tests.Replicator/Http/HttpReplicatorTest.cs +++ b/src/Lucene.Net.Tests.Replicator/Http/HttpReplicatorTest.cs @@ -44,7 +44,6 @@ namespace Lucene.Net.Tests.Replicator.Http public override void SetUp() { base.SetUp(); - //JAVA: System.setProperty("org.eclipse.jetty.LEVEL", "DEBUG"); // sets stderr logging to DEBUG level clientWorkDir = CreateTempDir("httpReplicatorTest"); handlerIndexDir = NewDirectory(); serverIndexDir = NewDirectory(); @@ -61,7 +60,6 @@ namespace Lucene.Net.Tests.Replicator.Http { StopHttpServer(server); IOUtils.Dispose(reader, writer, handlerIndexDir, serverIndexDir); - //JAVA: System.clearProperty("org.eclipse.jetty.LEVEL"); base.TearDown(); } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyReplicationClientTest.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyReplicationClientTest.cs b/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyReplicationClientTest.cs index 645888a..a6cdfbc 100644 --- a/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyReplicationClientTest.cs +++ b/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyReplicationClientTest.cs @@ -116,36 +116,6 @@ namespace Lucene.Net.Tests.Replicator private void AssertHandlerRevision(int expectedId, Directory dir) { - //JAVA: private void assertHandlerRevision(int expectedID, Directory dir) throws IOException { - //JAVA: // loop as long as client is alive. test-framework will terminate us if - //JAVA: // there's a serious bug, e.g. client doesn't really update. otherwise, - //JAVA: // introducing timeouts is not good, can easily lead to false positives. - //JAVA: while (client.isUpdateThreadAlive()) { - //JAVA: // give client a chance to update - //JAVA: try { - //JAVA: Thread.sleep(100); - //JAVA: } catch (InterruptedException e) { - //JAVA: throw new ThreadInterruptedException(e); - //JAVA: } - //JAVA: - //JAVA: try { - //JAVA: DirectoryReader reader = DirectoryReader.open(dir); - //JAVA: try { - //JAVA: int handlerID = Integer.parseInt(reader.getIndexCommit().getUserData().get(VERSION_ID), 16); - //JAVA: if (expectedID == handlerID) { - //JAVA: return; - //JAVA: } - //JAVA: } finally { - //JAVA: reader.close(); - //JAVA: } - //JAVA: } catch (Exception e) { - //JAVA: // we can hit IndexNotFoundException or e.g. EOFException (on - //JAVA: // segments_N) because it is being copied at the same time it is read by - //JAVA: // DirectoryReader.open(). - //JAVA: } - //JAVA: } - //JAVA: } - // loop as long as client is alive. test-framework will terminate us if // there's a serious bug, e.g. client doesn't really update. otherwise, // introducing timeouts is not good, can easily lead to false positives. @@ -180,15 +150,6 @@ namespace Lucene.Net.Tests.Replicator private IRevision CreateRevision(int id) { - //JAVA: private Revision createRevision(final int id) throws IOException { - //JAVA: publishIndexWriter.addDocument(newDocument(publishTaxoWriter, id)); - //JAVA: publishIndexWriter.setCommitData(new HashMap<String, String>() {{ - //JAVA: put(VERSION_ID, Integer.toString(id, 16)); - //JAVA: }}); - //JAVA: publishIndexWriter.commit(); - //JAVA: publishTaxoWriter.commit(); - //JAVA: return new IndexAndTaxonomyRevision(publishIndexWriter, publishTaxoWriter); - //JAVA: } publishIndexWriter.AddDocument(NewDocument(publishTaxoWriter, id)); publishIndexWriter.SetCommitData(new Dictionary<string, string>{ { VERSION_ID, id.ToString("X") } @@ -309,12 +270,10 @@ namespace Lucene.Net.Tests.Replicator newTaxo.Dispose(); } - //JAVA: /* - //JAVA: * This test verifies that the client and handler do not end up in a corrupt - //JAVA: * index if exceptions are thrown at any point during replication. Either when - //JAVA: * a client copies files from the server to the temporary space, or when the - //JAVA: * handler copies them to the index directory. - //JAVA: */ + // This test verifies that the client and handler do not end up in a corrupt + // index if exceptions are thrown at any point during replication. Either when + // a client copies files from the server to the temporary space, or when the + // handler copies them to the index directory. [Test] public void TestConsistencyOnExceptions() { @@ -482,11 +441,6 @@ namespace Lucene.Net.Tests.Replicator // category to all documents, there's nothing much more to validate TestUtil.CheckIndex(test.handlerTaxoDir.Delegate); } - //TODO: Java had this, but considering what it does do we need it? - //JAVA: catch (IOException e) - //JAVA: { - //JAVA: throw new RuntimeException(e); - //JAVA: } finally { // count-down number of failures @@ -507,8 +461,6 @@ namespace Lucene.Net.Tests.Replicator } else { - //JAVA: if (t instanceof RuntimeException) throw (RuntimeException) t; - //JAVA: throw new RuntimeException(t); throw exception; } } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyRevisionTest.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyRevisionTest.cs b/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyRevisionTest.cs index dd20864..9a54148 100644 --- a/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyRevisionTest.cs +++ b/src/Lucene.Net.Tests.Replicator/IndexAndTaxonomyRevisionTest.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using Lucene.Net.Documents; using Lucene.Net.Facet; @@ -11,6 +12,7 @@ using Lucene.Net.Replicator; using Lucene.Net.Store; using Lucene.Net.Util; using NUnit.Framework; +using Directory = Lucene.Net.Store.Directory; namespace Lucene.Net.Tests.Replicator { @@ -166,9 +168,7 @@ namespace Lucene.Net.Tests.Replicator { skip = 0; } - //JAVA: in.skip(skip); - byte[] skips = new byte[skip]; - @in.Read(skips, 0, skip); + @in.Seek(skip, SeekOrigin.Current); src.Seek(skip); offset = skip; } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Tests.Replicator/IndexReplicationClientTest.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests.Replicator/IndexReplicationClientTest.cs b/src/Lucene.Net.Tests.Replicator/IndexReplicationClientTest.cs index 6a56c77..9d28332 100644 --- a/src/Lucene.Net.Tests.Replicator/IndexReplicationClientTest.cs +++ b/src/Lucene.Net.Tests.Replicator/IndexReplicationClientTest.cs @@ -28,14 +28,6 @@ namespace Lucene.Net.Tests.Replicator public IndexReadyCallback(Directory indexDir) { - //JAVA: public IndexReadyCallback(Directory indexDir) throws IOException { - //JAVA: this.indexDir = indexDir; - //JAVA: if (DirectoryReader.indexExists(indexDir)) { - //JAVA: reader = DirectoryReader.open(indexDir); - //JAVA: lastGeneration = reader.getIndexCommit().getGeneration(); - //JAVA: } - //JAVA: } - this.indexDir = indexDir; if (DirectoryReader.IndexExists(indexDir)) { @@ -46,22 +38,6 @@ namespace Lucene.Net.Tests.Replicator public bool? Call() { - //JAVA: public Boolean call() throws Exception { - //JAVA: if (reader == null) { - //JAVA: reader = DirectoryReader.open(indexDir); - //JAVA: lastGeneration = reader.getIndexCommit().getGeneration(); - //JAVA: } else { - //JAVA: DirectoryReader newReader = DirectoryReader.openIfChanged(reader); - //JAVA: assertNotNull("should not have reached here if no changes were made to the index", newReader); - //JAVA: long newGeneration = newReader.getIndexCommit().getGeneration(); - //JAVA: assertTrue("expected newer generation; current=" + lastGeneration + " new=" + newGeneration, newGeneration > lastGeneration); - //JAVA: reader.close(); - //JAVA: reader = newReader; - //JAVA: lastGeneration = newGeneration; - //JAVA: TestUtil.checkIndex(indexDir); - //JAVA: } - //JAVA: return null; - //JAVA: } if (reader == null) { reader = DirectoryReader.Open(indexDir); @@ -94,44 +70,11 @@ namespace Lucene.Net.Tests.Replicator private IReplicationHandler handler; private IndexWriter publishWriter; private IndexReadyCallback callback; - //JAVA: private IndexReadyCallback callback; private const string VERSION_ID = "version"; private void AssertHandlerRevision(int expectedId, Directory dir) { - //JAVA: private void assertHandlerRevision(int expectedID, Directory dir) throws IOException { - //JAVA: // loop as long as client is alive. test-framework will terminate us if - //JAVA: // there's a serious bug, e.g. client doesn't really update. otherwise, - //JAVA: // introducing timeouts is not good, can easily lead to false positives. - //JAVA: while (client.isUpdateThreadAlive()) { - //JAVA: // give client a chance to update - //JAVA: try { - //JAVA: Thread.sleep(100); - //JAVA: } catch (InterruptedException e) { - //JAVA: throw new ThreadInterruptedException(e); - //JAVA: } - //JAVA: - //JAVA: try { - //JAVA: DirectoryReader reader = DirectoryReader.open(dir); - //JAVA: try { - //JAVA: int handlerID = Integer.parseInt(reader.getIndexCommit().getUserData().get(VERSION_ID), 16); - //JAVA: if (expectedID == handlerID) { - //JAVA: return; - //JAVA: } else if (VERBOSE) { - //JAVA: System.out.println("expectedID=" + expectedID + " actual=" + handlerID + " generation=" + reader.getIndexCommit().getGeneration()); - //JAVA: } - //JAVA: } finally { - //JAVA: reader.close(); - //JAVA: } - //JAVA: } catch (Exception e) { - //JAVA: // we can hit IndexNotFoundException or e.g. EOFException (on - //JAVA: // segments_N) because it is being copied at the same time it is read by - //JAVA: // DirectoryReader.open(). - //JAVA: } - //JAVA: } - //JAVA: } - // loop as long as client is alive. test-framework will terminate us if // there's a serious bug, e.g. client doesn't really update. otherwise, // introducing timeouts is not good, can easily lead to false positives. @@ -170,14 +113,6 @@ namespace Lucene.Net.Tests.Replicator private IRevision CreateRevision(int id) { - //JAVA: private Revision createRevision(final int id) throws IOException { - //JAVA: publishWriter.addDocument(new Document()); - //JAVA: publishWriter.setCommitData(new HashMap<String, String>() {{ - //JAVA: put(VERSION_ID, Integer.toString(id, 16)); - //JAVA: }}); - //JAVA: publishWriter.commit(); - //JAVA: return new IndexRevision(publishWriter); - //JAVA: } publishWriter.AddDocument(new Document()); publishWriter.SetCommitData(new Dictionary<string, string>{ { VERSION_ID, id.ToString("X") } @@ -188,20 +123,6 @@ namespace Lucene.Net.Tests.Replicator public override void SetUp() { - //JAVA: public void setUp() throws Exception { - //JAVA: super.setUp(); - //JAVA: publishDir = newMockDirectory(); - //JAVA: handlerDir = newMockDirectory(); - //JAVA: sourceDirFactory = new PerSessionDirectoryFactory(createTempDir("replicationClientTest")); - //JAVA: replicator = new LocalReplicator(); - //JAVA: callback = new IndexReadyCallback(handlerDir); - //JAVA: handler = new IndexReplicationHandler(handlerDir, callback); - //JAVA: client = new ReplicationClient(replicator, handler, sourceDirFactory); - //JAVA: - //JAVA: IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, null); - //JAVA: conf.setIndexDeletionPolicy(new SnapshotDeletionPolicy(conf.getIndexDeletionPolicy())); - //JAVA: publishWriter = new IndexWriter(publishDir, conf); - //JAVA: } base.SetUp(); publishDir = NewMockDirectory(); @@ -219,10 +140,6 @@ namespace Lucene.Net.Tests.Replicator public override void TearDown() { - //JAVA: public void tearDown() throws Exception { - //JAVA: IOUtils.close(client, callback, publishWriter, replicator, publishDir, handlerDir); - //JAVA: super.tearDown(); - //JAVA: } IOUtils.Dispose(client, callback, publishWriter, replicator, publishDir, handlerDir); base.TearDown(); } @@ -230,21 +147,6 @@ namespace Lucene.Net.Tests.Replicator [Test] public void TestNoUpdateThread() { - //JAVA: public void testNoUpdateThread() throws Exception { - //JAVA: assertNull("no version expected at start", handler.currentVersion()); - //JAVA: - //JAVA: // Callback validates the replicated index - //JAVA: replicator.publish(createRevision(1)); - //JAVA: client.updateNow(); - //JAVA: - //JAVA: replicator.publish(createRevision(2)); - //JAVA: client.updateNow(); - //JAVA: - //JAVA: // Publish two revisions without update, handler should be upgraded to latest - //JAVA: replicator.publish(createRevision(3)); - //JAVA: replicator.publish(createRevision(4)); - //JAVA: client.updateNow(); - //JAVA: } assertNull("no version expected at start", handler.CurrentVersion); // Callback validates the replicated ind @@ -264,21 +166,6 @@ namespace Lucene.Net.Tests.Replicator [Test] public void TestUpdateThread() { - //JAVA: public void testUpdateThread() throws Exception { - //JAVA: client.startUpdateThread(10, "index"); - //JAVA: - //JAVA: replicator.publish(createRevision(1)); - //JAVA: assertHandlerRevision(1, handlerDir); - //JAVA: - //JAVA: replicator.publish(createRevision(2)); - //JAVA: assertHandlerRevision(2, handlerDir); - //JAVA: - //JAVA: // Publish two revisions without update, handler should be upgraded to latest - //JAVA: replicator.publish(createRevision(3)); - //JAVA: replicator.publish(createRevision(4)); - //JAVA: assertHandlerRevision(4, handlerDir); - //JAVA: } - client.StartUpdateThread(10, "index"); replicator.Publish(CreateRevision(1)); @@ -296,22 +183,6 @@ namespace Lucene.Net.Tests.Replicator [Test] public void TestRestart() { - //JAVA: public void testRestart() throws Exception { - //JAVA: replicator.publish(createRevision(1)); - //JAVA: client.updateNow(); - //JAVA: - //JAVA: replicator.publish(createRevision(2)); - //JAVA: client.updateNow(); - //JAVA: - //JAVA: client.stopUpdateThread(); - //JAVA: client.close(); - //JAVA: client = new ReplicationClient(replicator, handler, sourceDirFactory); - //JAVA: - //JAVA: // Publish two revisions without update, handler should be upgraded to latest - //JAVA: replicator.publish(createRevision(3)); - //JAVA: replicator.publish(createRevision(4)); - //JAVA: client.updateNow(); - //JAVA: } replicator.Publish(CreateRevision(1)); client.UpdateNow(); @@ -328,12 +199,10 @@ namespace Lucene.Net.Tests.Replicator client.UpdateNow(); } - //JAVA: /* - //JAVA: * This test verifies that the client and handler do not end up in a corrupt - //JAVA: * index if exceptions are thrown at any point during replication. Either when - //JAVA: * a client copies files from the server to the temporary space, or when the - //JAVA: * handler copies them to the index directory. - //JAVA: */ + // This test verifies that the client and handler do not end up in a corrupt + // index if exceptions are thrown at any point during replication. Either when + // a client copies files from the server to the temporary space, or when the + // handler copies them to the index directory. [Test] public void TestConsistencyOnExceptions() { @@ -352,7 +221,6 @@ namespace Lucene.Net.Tests.Replicator // where the handler overwrites an existing index file, but // there's nothing currently we can do about it, unless we don't // use MDW. - //JAVA: handlerDir.setPreventDoubleWrite(false); handlerDir.PreventDoubleWrite = false; // wrap sourceDirFactory to return a MockDirWrapper so we can simulate errors @@ -478,12 +346,6 @@ namespace Lucene.Net.Tests.Replicator // verify index consistency TestUtil.CheckIndex(test.handlerDir.Delegate); } - //TODO: Java had this, but considering what it does do we need it? - //JAVA: catch (IOException e) - //JAVA: { - //JAVA: // exceptions here are bad, don't ignore them - //JAVA: throw new RuntimeException(e); - //JAVA: } finally { // count-down number of failures @@ -502,8 +364,6 @@ namespace Lucene.Net.Tests.Replicator } } } else { - //JAVA: if (t instanceof RuntimeException) throw (RuntimeException) t; - //JAVA: throw new RuntimeException(t); throw exception; } } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Tests.Replicator/IndexRevisionTest.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests.Replicator/IndexRevisionTest.cs b/src/Lucene.Net.Tests.Replicator/IndexRevisionTest.cs index de4dbb4..ee0108b 100644 --- a/src/Lucene.Net.Tests.Replicator/IndexRevisionTest.cs +++ b/src/Lucene.Net.Tests.Replicator/IndexRevisionTest.cs @@ -1,6 +1,7 @@ //STATUS: DRAFT - 4.8.0 using System; +using System.IO; using System.Linq; using Lucene.Net.Documents; using Lucene.Net.Index; @@ -8,6 +9,7 @@ using Lucene.Net.Replicator; using Lucene.Net.Store; using Lucene.Net.Util; using NUnit.Framework; +using Directory = Lucene.Net.Store.Directory; namespace Lucene.Net.Tests.Replicator { @@ -144,7 +146,7 @@ namespace Lucene.Net.Tests.Replicator foreach (RevisionFile file in sourceFiles.Values.First()) { IndexInput src = dir.OpenInput(file.FileName, IOContext.READ_ONCE); - System.IO.Stream @in = rev.Open(source, file.FileName); + Stream @in = rev.Open(source, file.FileName); assertEquals(src.Length, @in.Length); byte[] srcBytes = new byte[(int) src.Length]; byte[] inBytes = new byte[(int) src.Length]; @@ -156,9 +158,7 @@ namespace Lucene.Net.Tests.Replicator { skip = 0; } - //JAVA: in.skip(skip); - byte[] skips = new byte[skip]; - @in.Read(skips, 0, skip); + @in.Seek(skip, SeekOrigin.Current); src.Seek(skip); offset = skip; } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net.Tests.Replicator/LocalReplicatorTest.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net.Tests.Replicator/LocalReplicatorTest.cs b/src/Lucene.Net.Tests.Replicator/LocalReplicatorTest.cs index 9946457..d54e2e1 100644 --- a/src/Lucene.Net.Tests.Replicator/LocalReplicatorTest.cs +++ b/src/Lucene.Net.Tests.Replicator/LocalReplicatorTest.cs @@ -61,9 +61,6 @@ namespace Lucene.Net.Tests.Replicator private IRevision CreateRevision(int id) { sourceWriter.AddDocument(new Document()); - //JAVA: sourceWriter.setCommitData(new HashMap<String, String>() {{ - //JAVA: put(VERSION_ID, Integer.toString(id, 16)); - //JAVA: } sourceWriter.SetCommitData(new Dictionary<string, string> { { VERSION_ID, id.ToString() } }); @@ -175,8 +172,7 @@ namespace Lucene.Net.Tests.Replicator replicator.ObtainFile(res.Id, res.SourceFiles.Keys.First(), "madeUpFile"); fail("should have failed obtaining an unrecognized file"); } - //JAVA: } catch (FileNotFoundException | NoSuchFileException e) { -> Could not find a "NoSuchFileException" ?NoSuchItemException - catch (Exception e) when (e is FileNotFoundException)//|| e is NoSuchItemException) + catch (FileNotFoundException e) { // expected } http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/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 index 1b8ec1e..58e6ea9 100644 --- a/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs +++ b/src/Lucene.Net.Tests.Replicator/ReplicatorTestCase.cs @@ -28,99 +28,8 @@ namespace Lucene.Net.Tests.Replicator 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 => { @@ -135,10 +44,6 @@ namespace Lucene.Net.Tests.Replicator /// </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; } @@ -147,10 +52,6 @@ namespace Lucene.Net.Tests.Replicator /// </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; } @@ -159,34 +60,7 @@ namespace Lucene.Net.Tests.Replicator /// </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/e3305307/src/Lucene.Net/Lucene.Net.csproj ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Lucene.Net.csproj b/src/Lucene.Net/Lucene.Net.csproj index d2b8e6e..50b1b14 100644 --- a/src/Lucene.Net/Lucene.Net.csproj +++ b/src/Lucene.Net/Lucene.Net.csproj @@ -395,6 +395,7 @@ <Compile Include="Index\UpgradeIndexMergePolicy.cs" /> <Compile Include="LucenePackage.cs" /> <Compile Include="Support\Document\DocumentExtensions.cs" /> + <Compile Include="Support\EnumerableExtensions.cs" /> <Compile Include="Support\IO\Compression\LZOCompressor.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Search\AutomatonQuery.cs" /> http://git-wip-us.apache.org/repos/asf/lucenenet/blob/e3305307/src/Lucene.Net/Support/EnumerableExtensions.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Support/EnumerableExtensions.cs b/src/Lucene.Net/Support/EnumerableExtensions.cs new file mode 100644 index 0000000..f621289 --- /dev/null +++ b/src/Lucene.Net/Support/EnumerableExtensions.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; + +namespace Lucene.Net.Support +{ + /* + * 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. + */ + + /// <summary> + /// .NET Specific Helper Extensions for IEnumerable + /// </summary> + //Note: LUCENENET specific + public static class EnumerableExtensions + { + /// <summary> + /// Enumerates a sequence in pairs + /// </summary> + /// <remarks> + /// In the case of an uneven amount of elements, the list call to <paramref name="join" /> pases <code>default(T)</code> as the second parameter. + /// </remarks> + /// <typeparam name="T">The type of the elements of <paramref name="source" />.</typeparam> + /// <typeparam name="TOut">The type of the elements returned from <paramref name="join" />.</typeparam> + /// <param name="source">An <see cref="T:System.Collections.Generic.IEnumerable`1" /> to enumerate in pairs.</param> + /// <param name="join">A function that is invoked for each pair of elements.</param> + /// <exception cref="T:System.ArgumentNullException"><paramref name="source" /> or <paramref name="join" /> is <see langword="null" />.</exception> + /// <returns>A new <see cref="T:System.Collections.Generic.IEnumerable`1" /> containing the results from each pair.</returns> + public static IEnumerable<TOut> InPairs<T, TOut>(this IEnumerable<T> source, Func<T, T, TOut> join) + { + if (source == null) + throw new ArgumentNullException("source"); + if (join == null) + throw new ArgumentNullException("join"); + + using (IEnumerator<T> enumerator = source.GetEnumerator()) + { + while (true) + { + if (!enumerator.MoveNext()) + yield break; + + T x = enumerator.Current; + if (!enumerator.MoveNext()) + yield return join(x, default(T)); + yield return join(x, enumerator.Current); + } + } + } + } +} \ No newline at end of file
