/// <exception cref="System.Exception"></exception> private static void RunOnThread(Runnable task) { Sharpen.Thread t = new Sharpen.Thread(task); t.Start(); t.Join(1000); NUnit.Framework.Assert.IsFalse(t.IsAlive(), "thread has stopped"); }
/// <exception cref="System.Exception"/> public virtual void TestTransitionedToStandbyShouldNotHang() { configuration.SetBoolean(YarnConfiguration.AutoFailoverEnabled, false); Configuration conf = new YarnConfiguration(configuration); MemoryRMStateStore memStore = new _MemoryRMStateStore_464(); memStore.Init(conf); rm = new _MockRM_472(conf, memStore); rm.Init(conf); HAServiceProtocol.StateChangeRequestInfo requestInfo = new HAServiceProtocol.StateChangeRequestInfo (HAServiceProtocol.RequestSource.RequestByUser); NUnit.Framework.Assert.AreEqual(StateErr, HAServiceProtocol.HAServiceState.Initializing , rm.adminService.GetServiceStatus().GetState()); NUnit.Framework.Assert.IsFalse("RM is ready to become active before being started" , rm.adminService.GetServiceStatus().IsReadyToBecomeActive()); CheckMonitorHealth(); rm.Start(); CheckMonitorHealth(); CheckStandbyRMFunctionality(); // 2. Transition to Active. rm.adminService.TransitionToActive(requestInfo); // 3. Try Transition to standby Sharpen.Thread t = new Sharpen.Thread(new _Runnable_498(this)); // TODO Auto-generated catch block t.Start(); rm.GetRMContext().GetStateStore().UpdateApplicationState(null); t.Join(); // wait for thread to finish rm.adminService.TransitionToStandby(requestInfo); CheckStandbyRMFunctionality(); rm.Stop(); }
// use a small block size and a large write so that DN is busy creating // new blocks. This makes it almost 100% sure we can reproduce // case of client getting a DN that hasn't yet created the blocks /// <exception cref="System.IO.IOException"/> public virtual void TestImmediateReadOfNewFile() { int blockSize = 64 * 1024; int writeSize = 10 * blockSize; Configuration conf = new Configuration(); conf.SetLong(DFSConfigKeys.DfsBlockSizeKey, blockSize); Init(conf); int requiredSuccessfulOpens = 100; Path file = new Path("/file1"); AtomicBoolean openerDone = new AtomicBoolean(false); AtomicReference <string> errorMessage = new AtomicReference <string>(); FSDataOutputStream @out = fileSystem.Create(file); Sharpen.Thread writer = new Sharpen.Thread(new _Runnable_219(openerDone, @out, writeSize )); Sharpen.Thread opener = new Sharpen.Thread(new _Runnable_239(this, requiredSuccessfulOpens , file, openerDone, errorMessage, writer)); writer.Start(); opener.Start(); try { writer.Join(); opener.Join(); } catch (Exception) { Sharpen.Thread.CurrentThread().Interrupt(); } NUnit.Framework.Assert.IsNull(errorMessage.Get(), errorMessage.Get()); }
/// <exception cref="System.IO.IOException"/> private void RunTestUnfinishedBlockCRCError(bool transferToAllowed, TestFileConcurrentReader.SyncType syncType, int writeSize, Configuration conf) { conf.SetBoolean(DFSConfigKeys.DfsDatanodeTransfertoAllowedKey, transferToAllowed); Init(conf); Path file = new Path("/block-being-written-to"); int numWrites = 2000; AtomicBoolean writerDone = new AtomicBoolean(false); AtomicBoolean writerStarted = new AtomicBoolean(false); AtomicBoolean error = new AtomicBoolean(false); Sharpen.Thread writer = new Sharpen.Thread(new _Runnable_340(this, file, syncType , error, numWrites, writeSize, writerStarted, writerDone)); Sharpen.Thread tailer = new Sharpen.Thread(new _Runnable_373(this, writerDone, error , writerStarted, file, writer)); writer.Start(); tailer.Start(); try { writer.Join(); tailer.Join(); NUnit.Framework.Assert.IsFalse("error occurred, see log above", error.Get()); } catch (Exception) { Log.Info("interrupted waiting for writer or tailer to complete"); Sharpen.Thread.CurrentThread().Interrupt(); } }
/// <exception cref="System.Exception"/> protected override void ServiceStop() { if (stopped.GetAndSet(true)) { // return if already stopped return; } if (allocatorThread != null) { allocatorThread.Interrupt(); try { allocatorThread.Join(); } catch (Exception ie) { Log.Warn("InterruptedException while stopping", ie); } } if (isApplicationMasterRegistered && shouldUnregister) { Unregister(); } base.ServiceStop(); }
/// <exception cref="System.IO.IOException"/> public virtual void Execute() { if (state != WindowsSecureContainerExecutor.WintuilsProcessStubExecutor.State.Init) { throw new IOException("Process is already started"); } processStub = WindowsSecureContainerExecutor.Native.CreateTaskAsUser(cwd, jobName , userName, pidFile, cmdLine); state = WindowsSecureContainerExecutor.WintuilsProcessStubExecutor.State.Running; Sharpen.Thread stdOutReader = StartStreamReader(processStub.GetInputStream()); Sharpen.Thread stdErrReader = StartStreamReader(processStub.GetErrorStream()); try { processStub.Resume(); processStub.WaitFor(); stdOutReader.Join(); stdErrReader.Join(); } catch (Exception ie) { throw new IOException(ie); } exitCode = processStub.ExitValue(); state = WindowsSecureContainerExecutor.WintuilsProcessStubExecutor.State.Complete; }
/// <exception cref="System.Exception"/> internal virtual void Teardown() { if (bkthread != null) { bkthread.Interrupt(); bkthread.Join(); } }
/// <exception cref="System.Exception"></exception> private void RunTestScript() { // will start new thread to get as close as possible to original // environment, however the same behavior is exposed using new // ScriptRunner(script).run(); Sharpen.Thread thread = new Sharpen.Thread(new Bug421071Test.ScriptRunner(this, testScript)); thread.Start(); thread.Join(); }
/// <exception cref="NSch.JSchException"></exception> internal static Socket CreateSocket(string host, int port, int timeout) { Socket socket = null; if (timeout == 0) { try { socket = Sharpen.Extensions.CreateSocket(host, port); return(socket); } catch (Exception e) { string message = e.Message; if (e is Exception) { throw new JSchException(message, (Exception)e); } throw new JSchException(message); } } string _host = host; int _port = port; Socket[] sockp = new Socket[1]; Exception[] ee = new Exception[1]; string message_1 = string.Empty; Sharpen.Thread tmp = new Sharpen.Thread(new _Runnable_350(sockp, _host, _port, ee )); tmp.SetName("Opening Socket " + host); tmp.Start(); try { tmp.Join(timeout); message_1 = "timeout: "; } catch (Exception) { } if (sockp[0] != null && sockp[0].Connected) { socket = sockp[0]; } else { message_1 += "socket is not established"; if (ee[0] != null) { message_1 = ee[0].ToString(); } tmp.Interrupt(); tmp = null; throw new JSchException(message_1); } return(socket); }
/// <summary>Shut down this instance of the datanode.</summary> /// <remarks> /// Shut down this instance of the datanode. /// Returns only after shutdown is complete. /// </remarks> public virtual void Shutdown() { shouldRun = false; if (checkpointThread != null) { checkpointThread.Interrupt(); try { checkpointThread.Join(10000); } catch (Exception) { Log.Info("Interrupted waiting to join on checkpointer thread"); Sharpen.Thread.CurrentThread().Interrupt(); } } // maintain status try { if (infoServer != null) { infoServer.Stop(); infoServer = null; } } catch (Exception e) { Log.Warn("Exception shutting down SecondaryNameNode", e); } if (nameNodeStatusBeanName != null) { MBeans.Unregister(nameNodeStatusBeanName); nameNodeStatusBeanName = null; } try { if (checkpointImage != null) { checkpointImage.Close(); checkpointImage = null; } } catch (IOException e) { Log.Warn("Exception while closing CheckpointStorage", e); } if (namesystem != null) { namesystem.Shutdown(); namesystem = null; } }
public virtual void TestUncaughtExceptionHandlerWithError() { ExitUtil.DisableSystemExit(); YarnUncaughtExceptionHandler spyErrorHandler = Org.Mockito.Mockito.Spy(exHandler); Error error = new Error("test-error"); Sharpen.Thread errorThread = new Sharpen.Thread(new _Runnable_75(error)); errorThread.SetUncaughtExceptionHandler(spyErrorHandler); NUnit.Framework.Assert.AreSame(spyErrorHandler, errorThread.GetUncaughtExceptionHandler ()); errorThread.Start(); errorThread.Join(); Org.Mockito.Mockito.Verify(spyErrorHandler).UncaughtException(errorThread, error); }
public virtual void TestUncaughtExceptionHandlerWithOutOfMemoryError() { ExitUtil.DisableSystemHalt(); YarnUncaughtExceptionHandler spyOomHandler = Org.Mockito.Mockito.Spy(exHandler); OutOfMemoryException oomError = new OutOfMemoryException("out-of-memory-error"); Sharpen.Thread oomThread = new Sharpen.Thread(new _Runnable_104(oomError)); oomThread.SetUncaughtExceptionHandler(spyOomHandler); NUnit.Framework.Assert.AreSame(spyOomHandler, oomThread.GetUncaughtExceptionHandler ()); oomThread.Start(); oomThread.Join(); Org.Mockito.Mockito.Verify(spyOomHandler).UncaughtException(oomThread, oomError); }
public virtual void TestUncaughtExceptionHandlerWithRuntimeException() { YarnUncaughtExceptionHandler spyYarnHandler = Org.Mockito.Mockito.Spy(exHandler); YarnRuntimeException yarnException = new YarnRuntimeException("test-yarn-runtime-exception" ); Sharpen.Thread yarnThread = new Sharpen.Thread(new _Runnable_45(yarnException)); yarnThread.SetUncaughtExceptionHandler(spyYarnHandler); NUnit.Framework.Assert.AreSame(spyYarnHandler, yarnThread.GetUncaughtExceptionHandler ()); yarnThread.Start(); yarnThread.Join(); Org.Mockito.Mockito.Verify(spyYarnHandler).UncaughtException(yarnThread, yarnException ); }
public virtual void TearDown() { IOUtils.Cleanup(Log, Sharpen.Collections.ToArray(clients, new SocketChannel[clients .Count])); IOUtils.Cleanup(Log, fs); if (serverSocket != null) { try { serverSocket.Close(); } catch (IOException e) { Log.Debug("Exception in closing " + serverSocket, e); } } if (serverThread != null) { serverThread.Join(); } }
private void StopTransactionWorkers() { // wait for all transactions to get over foreach (TestEditLogRace.Transactions worker in workers) { worker.Stop(); } foreach (TestEditLogRace.Transactions worker_1 in workers) { Sharpen.Thread thr = worker_1.GetThread(); try { if (thr != null) { thr.Join(); } } catch (Exception) { } } }
/// <summary>Interrupt the writing thread and wait until it dies</summary> /// <exception cref="System.IO.IOException">the waiting is interrupted</exception> public virtual void StopWriter(long xceiverStopTimeout) { if (writer != null && writer != Sharpen.Thread.CurrentThread() && writer.IsAlive( )) { writer.Interrupt(); try { writer.Join(xceiverStopTimeout); if (writer.IsAlive()) { string msg = "Join on writer thread " + writer + " timed out"; DataNode.Log.Warn(msg + "\n" + StringUtils.GetStackTrace(writer)); throw new IOException(msg); } } catch (Exception) { throw new IOException("Waiting for writer thread is interrupted."); } } }
/// <exception cref="System.Exception"/> protected override void ServiceStop() { if (drainEventsOnStop) { blockNewEvents = true; Log.Info("AsyncDispatcher is draining to stop, igonring any new events."); long endTime = Runtime.CurrentTimeMillis() + GetConfig().GetLong(YarnConfiguration .DispatcherDrainEventsTimeout, YarnConfiguration.DefaultDispatcherDrainEventsTimeout ); lock (waitForDrained) { while (!drained && eventHandlingThread != null && eventHandlingThread.IsAlive() && Runtime.CurrentTimeMillis() < endTime) { Sharpen.Runtime.Wait(waitForDrained, 1000); Log.Info("Waiting for AsyncDispatcher to drain. Thread state is :" + eventHandlingThread .GetState()); } } } stopped = true; if (eventHandlingThread != null) { eventHandlingThread.Interrupt(); try { eventHandlingThread.Join(); } catch (Exception ie) { Log.Warn("Interrupted Exception while stopping", ie); } } // stop all the components base.ServiceStop(); }
/// <exception cref="System.Exception"></exception> public static void Run(ShellContextFactory shellContextFactory, FilePath jsFile, ShellTest.Parameters parameters, ShellTest.Status status) { Global global = new Global(); MemoryStream @out = new MemoryStream(); TextWriter p = new TextWriter(@out); global.SetOut(p); global.SetErr(p); global.DefineFunctionProperties(new string[] { "options" }, typeof(ShellTest), ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); // test suite expects keywords to be disallowed as identifiers shellContextFactory.SetAllowReservedKeywords(false); ShellTest.TestState testState = new ShellTest.TestState(); if (jsFile.GetName().EndsWith("-n.js")) { status.SetNegative(); } Exception[] thrown = new Exception[] { null }; Sharpen.Thread t = new Sharpen.Thread(new _Runnable_274(shellContextFactory, thrown, testState, status, jsFile, global), jsFile.GetPath()); t.SetDaemon(true); t.Start(); t.Join(parameters.GetTimeoutMilliseconds()); lock (testState) { if (!testState.finished) { CallStop(t); status.TimedOut(); } } int expectedExitCode = 0; p.Flush(); status.OutputWas(Sharpen.Runtime.GetStringForBytes(@out.ToArray())); BufferedReader r = new BufferedReader(new StreamReader(new MemoryStream(@out.ToArray()))); string failures = string.Empty; for (; ; ) { string s = r.ReadLine(); if (s == null) { break; } if (s.IndexOf("FAILED!") != -1) { failures += s + '\n'; } int expex = s.IndexOf("EXPECT EXIT CODE "); if (expex != -1) { expectedExitCode = s[expex + "EXPECT EXIT CODE ".Length] - '0'; } } if (thrown[0] != null) { status.Threw(thrown[0]); } status.ExitCodesWere(expectedExitCode, testState.exitCode); if (failures != string.Empty) { status.Failed(failures); } }
/// <exception cref="NSch.JSchException"></exception> internal static Socket CreateSocket(string host, int port, int timeout) { Socket socket = null; if (timeout == 0) { try { socket = Sharpen.Extensions.CreateSocket(host, port); return socket; } catch (Exception e) { string message = e.ToString(); if (e is Exception) { throw new JSchException(message, (Exception)e); } throw new JSchException(message); } } string _host = host; int _port = port; Socket[] sockp = new Socket[1]; Exception[] ee = new Exception[1]; string message_1 = string.Empty; Sharpen.Thread tmp = new Sharpen.Thread(new _Runnable_350(sockp, _host, _port, ee )); tmp.SetName("Opening Socket " + host); tmp.Start(); try { tmp.Join(timeout); message_1 = "timeout: "; } catch (Exception) { } if (sockp[0] != null && sockp[0].Connected) { socket = sockp[0]; } else { message_1 += "socket is not established"; if (ee[0] != null) { message_1 = ee[0].ToString(); } tmp.Interrupt(); tmp = null; throw new JSchException(message_1); } return socket; }