public virtual void Parse(EventReader reader, HistoryEventHandler handler) { lock (this) { int eventCtr = 0; HistoryEvent @event; try { while ((@event = reader.GetNextEvent()) != null) { handler.HandleEvent(@event); ++eventCtr; } } catch (IOException ioe) { Log.Info("Caught exception parsing history file after " + eventCtr + " events", ioe ); parseException = ioe; } finally { @in.Close(); } } }
/* * test EventReader EventReader should read the list of events and return * instance of HistoryEvent Different HistoryEvent should have a different * datum. */ /// <exception cref="System.Exception"/> public virtual void TestEvents() { EventReader reader = new EventReader(new DataInputStream(new ByteArrayInputStream (GetEvents()))); HistoryEvent e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.JobPriorityChanged )); NUnit.Framework.Assert.AreEqual("ID", ((JobPriorityChange)e.GetDatum()).jobid.ToString ()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.JobStatusChanged) ); NUnit.Framework.Assert.AreEqual("ID", ((JobStatusChanged)e.GetDatum()).jobid.ToString ()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.TaskUpdated)); NUnit.Framework.Assert.AreEqual("ID", ((TaskUpdated)e.GetDatum()).taskid.ToString ()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.ReduceAttemptKilled )); NUnit.Framework.Assert.AreEqual("task_1_2_r03_4", ((TaskAttemptUnsuccessfulCompletion )e.GetDatum()).taskid.ToString()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.JobKilled)); NUnit.Framework.Assert.AreEqual("ID", ((JobUnsuccessfulCompletion)e.GetDatum()).jobid .ToString()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.ReduceAttemptStarted )); NUnit.Framework.Assert.AreEqual("task_1_2_r03_4", ((TaskAttemptStarted)e.GetDatum ()).taskid.ToString()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.ReduceAttemptFinished )); NUnit.Framework.Assert.AreEqual("task_1_2_r03_4", ((TaskAttemptFinished)e.GetDatum ()).taskid.ToString()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.ReduceAttemptKilled )); NUnit.Framework.Assert.AreEqual("task_1_2_r03_4", ((TaskAttemptUnsuccessfulCompletion )e.GetDatum()).taskid.ToString()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.ReduceAttemptKilled )); NUnit.Framework.Assert.AreEqual("task_1_2_r03_4", ((TaskAttemptUnsuccessfulCompletion )e.GetDatum()).taskid.ToString()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.ReduceAttemptStarted )); NUnit.Framework.Assert.AreEqual("task_1_2_r03_4", ((TaskAttemptStarted)e.GetDatum ()).taskid.ToString()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.ReduceAttemptFinished )); NUnit.Framework.Assert.AreEqual("task_1_2_r03_4", ((TaskAttemptFinished)e.GetDatum ()).taskid.ToString()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.ReduceAttemptKilled )); NUnit.Framework.Assert.AreEqual("task_1_2_r03_4", ((TaskAttemptUnsuccessfulCompletion )e.GetDatum()).taskid.ToString()); e = reader.GetNextEvent(); NUnit.Framework.Assert.IsTrue(e.GetEventType().Equals(EventType.ReduceAttemptKilled )); NUnit.Framework.Assert.AreEqual("task_1_2_r03_4", ((TaskAttemptUnsuccessfulCompletion )e.GetDatum()).taskid.ToString()); reader.Close(); }