/// <summary> /// A helper function to serialize the JobTokenIdentifier to be sent to the /// ShuffleHandler as ServiceData. /// </summary> /// <param name="jobToken"> /// the job token to be used for authentication of /// shuffle data requests. /// </param> /// <returns>the serialized version of the jobToken.</returns> /// <exception cref="System.IO.IOException"/> public static ByteBuffer SerializeServiceData(Org.Apache.Hadoop.Security.Token.Token <JobTokenIdentifier> jobToken) { //TODO these bytes should be versioned DataOutputBuffer jobToken_dob = new DataOutputBuffer(); jobToken.Write(jobToken_dob); return ByteBuffer.Wrap(jobToken_dob.GetData(), 0, jobToken_dob.GetLength()); }
/// <summary>Test token serialization</summary> /// <exception cref="System.IO.IOException"/> public virtual void TestTokenSerialization() { // Get a token Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> sourceToken = new Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier>(); sourceToken.SetService(new Text("service")); // Write it to an output buffer DataOutputBuffer @out = new DataOutputBuffer(); sourceToken.Write(@out); // Read the token back DataInputBuffer @in = new DataInputBuffer(); @in.Reset(@out.GetData(), @out.GetLength()); Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier> destToken = new Org.Apache.Hadoop.Security.Token.Token <TokenIdentifier>(); destToken.ReadFields(@in); Assert.True(CheckEqual(sourceToken, destToken)); }