Add ReplTest project
This commit is contained in:
Родитель
12de1a7129
Коммит
038c561d60
|
@ -38,6 +38,14 @@ namespace Microsoft.Spark.CSharp.Core
|
|||
private AccumulatorServer accumulatorServer;
|
||||
private int nextAccumulatorId;
|
||||
|
||||
/// <summary>
|
||||
/// Return a copy of this JavaSparkContext's configuration. The configuration ''cannot'' be changed at runtime.
|
||||
/// </summary>
|
||||
public SparkConf GetConf()
|
||||
{
|
||||
return new SparkConf(SparkContextProxy.GetConf());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The version of Spark on which this application is running.
|
||||
/// </summary>
|
||||
|
|
|
@ -11,6 +11,7 @@ using Microsoft.Spark.CSharp.Proxy.Ipc;
|
|||
[assembly: InternalsVisibleTo("Tests.Common")]
|
||||
[assembly: InternalsVisibleTo("AdapterTest")]
|
||||
[assembly: InternalsVisibleTo("WorkerTest")]
|
||||
[assembly: InternalsVisibleTo("ReplTest")]
|
||||
// DynamicProxyGenAssembly2 is a temporary assembly built by mocking systems that use CastleProxy like Moq
|
||||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
|
||||
namespace Microsoft.Spark.CSharp.Interop
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Microsoft.Spark.CSharp.Proxy
|
|||
{
|
||||
internal interface ISparkContextProxy
|
||||
{
|
||||
ISparkConfProxy GetConf();
|
||||
ISqlContextProxy CreateSqlContext();
|
||||
ISqlContextProxy CreateHiveContext();
|
||||
IColumnProxy CreateColumnFromName(string name);
|
||||
|
|
|
@ -23,6 +23,11 @@ namespace Microsoft.Spark.CSharp.Proxy.Ipc
|
|||
private JvmObjectReference jvmAccumulatorReference;
|
||||
internal List<JvmObjectReference> jvmBroadcastReferences = new List<JvmObjectReference>();
|
||||
|
||||
public ISparkConfProxy GetConf()
|
||||
{
|
||||
return new SparkConfIpcProxy(new JvmObjectReference((string)SparkCLRIpcProxy.JvmBridge.CallNonStaticJavaMethod(jvmJavaContextReference, "getConf")));
|
||||
}
|
||||
|
||||
internal JvmObjectReference JvmSparkContextReference
|
||||
{
|
||||
get { return jvmSparkContextReference; }
|
||||
|
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization.Formatters.Binary;
|
||||
using System.Text;
|
||||
|
@ -13,6 +14,7 @@ using Microsoft.Spark.CSharp.Core;
|
|||
using Microsoft.Spark.CSharp.Proxy;
|
||||
using Microsoft.Spark.CSharp.Sql;
|
||||
|
||||
[assembly: InternalsVisibleTo("ReplTest")]
|
||||
namespace AdapterTest.Mocks
|
||||
{
|
||||
internal class MockSparkCLRProxy : ISparkCLRProxy
|
||||
|
|
|
@ -65,6 +65,13 @@ namespace AdapterTest.Mocks
|
|||
|
||||
string deserializerMode = SerDe.ReadString(s);
|
||||
string serializerMode = SerDe.ReadString(s);
|
||||
|
||||
string runMode = SerDe.ReadString(s);
|
||||
if ("R".Equals(runMode, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
string compilationDumpDir = SerDe.ReadString(s);
|
||||
}
|
||||
|
||||
CSharpWorkerFunc workerFunc = (CSharpWorkerFunc)formatter.Deserialize(new MemoryStream(SerDe.ReadBytes(s)));
|
||||
var func = workerFunc.Func;
|
||||
IEnumerable<dynamic> output = func(default(int), input);
|
||||
|
@ -272,6 +279,11 @@ namespace AdapterTest.Mocks
|
|||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public ISparkConfProxy GetConf()
|
||||
{
|
||||
return new MockSparkConfProxy();
|
||||
}
|
||||
|
||||
public ISqlContextProxy CreateSqlContext()
|
||||
{
|
||||
return new MockSqlContextProxy(this);
|
||||
|
|
|
@ -111,6 +111,13 @@ namespace AdapterTest
|
|||
|
||||
SerDe.ReadString(s);
|
||||
SerDe.ReadString(s);
|
||||
|
||||
string runMode = SerDe.ReadString(s);
|
||||
if ("R".Equals(runMode, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
string compilationDumpDir = SerDe.ReadString(s);
|
||||
}
|
||||
|
||||
CSharpWorkerFunc workerFunc = (CSharpWorkerFunc)formatter.Deserialize(new MemoryStream(SerDe.ReadBytes(s)));
|
||||
var func = workerFunc.Func;
|
||||
result = func(default(int), input);
|
||||
|
|
|
@ -4,38 +4,38 @@
|
|||
<!-- Log4Net configuration sections below are needed only if Log4NetLoggerService is used -->
|
||||
<!--**************************************************************************************-->
|
||||
<configSections>
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
|
||||
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
|
||||
</configSections>
|
||||
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
|
||||
</startup>
|
||||
|
||||
<log4net>
|
||||
<root>
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="ConsoleAppender" />
|
||||
<level value="INFO"/>
|
||||
<appender-ref ref="ConsoleAppender"/>
|
||||
<!--
|
||||
<appender-ref ref="LogFileAppender" />
|
||||
-->
|
||||
</root>
|
||||
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="[%date] [%-5property{pid}] [%thread] [%-5level] [%logger] - %message%newline" />
|
||||
<conversionPattern value="[%date] [%-5property{pid}] [%thread] [%-5level] [%logger] - %message%newline"/>
|
||||
</layout>
|
||||
</appender>
|
||||
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
|
||||
<file type="log4net.Util.PatternString">
|
||||
<conversionPattern value="%env{TEMP}\\SparkCLRLogs\\SparkCLRWorker_%env{COMPUTERNAME}[%processid].log" />
|
||||
<conversionPattern value="%env{TEMP}\\SparkCLRLogs\\SparkCLRWorker_%env{COMPUTERNAME}[%processid].log"/>
|
||||
</file>
|
||||
<param name="AppendToFile" value="true" />
|
||||
<param name="MaxSizeRollBackups" value="2000" />
|
||||
<param name="MaxFileSize" value="51200000" />
|
||||
<param name="StaticLogFileName" value="false" />
|
||||
<param name="DatePattern" value=".yyyy_MM_dd_hh" />
|
||||
<param name="RollingStyle" value="Composite" />
|
||||
<param name="AppendToFile" value="true"/>
|
||||
<param name="MaxSizeRollBackups" value="2000"/>
|
||||
<param name="MaxFileSize" value="51200000"/>
|
||||
<param name="StaticLogFileName" value="false"/>
|
||||
<param name="DatePattern" value=".yyyy_MM_dd_hh"/>
|
||||
<param name="RollingStyle" value="Composite"/>
|
||||
<layout type="log4net.Layout.PatternLayout">
|
||||
<conversionPattern value="[%date] [%thread] [%-5level] [%logger] - %message%newline" />
|
||||
<conversionPattern value="[%date] [%thread] [%-5level] [%logger] - %message%newline"/>
|
||||
</layout>
|
||||
</appender>
|
||||
</log4net>
|
||||
|
|
|
@ -6,5 +6,7 @@ namespace Microsoft.Spark.CSharp
|
|||
public interface IScriptEngine
|
||||
{
|
||||
ScriptResult Execute(string code);
|
||||
|
||||
void Cleanup();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,84 +2,49 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Microsoft.Spark.CSharp.Core;
|
||||
|
||||
namespace Microsoft.Spark.CSharp
|
||||
{
|
||||
class Repl
|
||||
public interface IoHandler
|
||||
{
|
||||
static void Main(string[] args)
|
||||
void Write(Object obj);
|
||||
|
||||
/// <summary>
|
||||
/// Write result to underlying output stream.
|
||||
/// </summary>
|
||||
void WriteLine(Object obj);
|
||||
|
||||
/// <summary>
|
||||
/// Write exception to underlying output stream
|
||||
/// </summary>
|
||||
/// <param name="e"></param>
|
||||
void WriteException(Exception e);
|
||||
|
||||
/// <summary>
|
||||
/// Read codes that will be executed. Current thread will be blocked if no input available.
|
||||
/// </summary>
|
||||
string ReadLine();
|
||||
}
|
||||
|
||||
public class ConsoleIoHandler : IoHandler
|
||||
{
|
||||
public void Write(object obj)
|
||||
{
|
||||
var sparkConf = new SparkConf();
|
||||
var sc = new SparkContext(sparkConf);
|
||||
var scriptEngine = new RoslynScriptEngine(sparkConf, sc);
|
||||
Console.Write(obj.ToString());
|
||||
}
|
||||
|
||||
scriptEngine.Execute(@"
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Spark.CSharp.Core;
|
||||
using Microsoft.Spark.CSharp.Interop;
|
||||
");
|
||||
Console.WriteLine("Spark context available as sc.");
|
||||
Console.WriteLine("SQL context available as sqlContext.");
|
||||
Console.WriteLine("Use :quit to exit.");
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.Write("> ");
|
||||
var inputLines = new StringBuilder();
|
||||
bool cancelSubmission = false;
|
||||
ScriptResult scriptResult = null;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var line = Console.ReadLine();
|
||||
if (string.IsNullOrEmpty(line))
|
||||
{
|
||||
cancelSubmission = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (line.Trim().Equals(":quit", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
scriptEngine.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
inputLines.AppendLine(line);
|
||||
scriptResult = scriptEngine.Execute(inputLines.ToString());
|
||||
if (scriptResult.IsCompleteSubmission)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Console.Write(". ");
|
||||
}
|
||||
|
||||
if (cancelSubmission)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (scriptResult.CompileExceptionInfo != null)
|
||||
{
|
||||
DisplayException(scriptResult.CompileExceptionInfo.SourceException);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (scriptResult.ReturnValue != null)
|
||||
{
|
||||
Console.WriteLine(scriptResult.ReturnValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void WriteLine(Object obj)
|
||||
{
|
||||
Console.WriteLine(obj);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Diplay exception on Console
|
||||
/// </summary>
|
||||
internal static void DisplayException(Exception e)
|
||||
public void WriteException(Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -91,5 +56,102 @@ namespace Microsoft.Spark.CSharp
|
|||
Console.ResetColor();
|
||||
}
|
||||
}
|
||||
|
||||
public string ReadLine()
|
||||
{
|
||||
return Console.ReadLine();
|
||||
}
|
||||
}
|
||||
|
||||
public class Repl
|
||||
{
|
||||
private readonly IScriptEngine scriptEngine;
|
||||
private readonly IoHandler ioHandler;
|
||||
|
||||
public Repl(IScriptEngine scriptEngine, IoHandler ioHandler)
|
||||
{
|
||||
this.scriptEngine = scriptEngine;
|
||||
this.ioHandler = ioHandler;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
scriptEngine.Execute(@"
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.Spark.CSharp.Core;
|
||||
using Microsoft.Spark.CSharp.Interop;
|
||||
");
|
||||
|
||||
ioHandler.WriteLine("Spark context available as sc.");
|
||||
ioHandler.WriteLine("SQL context available as sqlContext.");
|
||||
ioHandler.WriteLine("Use :quit to exit.");
|
||||
}
|
||||
|
||||
public void Run()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
ioHandler.Write("> ");
|
||||
var inputLines = new StringBuilder();
|
||||
bool cancelSubmission = false;
|
||||
ScriptResult scriptResult = null;
|
||||
|
||||
while (true)
|
||||
{
|
||||
var line = ioHandler.ReadLine();
|
||||
if (string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
cancelSubmission = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (line.Trim().Equals(":quit", StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
inputLines.AppendLine(line);
|
||||
scriptResult = scriptEngine.Execute(inputLines.ToString());
|
||||
if (scriptResult.IsCompleteSubmission)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
ioHandler.Write(". ");
|
||||
}
|
||||
|
||||
if (cancelSubmission)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (scriptResult.CompileExceptionInfo != null)
|
||||
{
|
||||
ioHandler.WriteException(scriptResult.CompileExceptionInfo.SourceException);
|
||||
}
|
||||
else if (scriptResult.ExecuteExceptionInfo != null)
|
||||
{
|
||||
ioHandler.WriteException(scriptResult.ExecuteExceptionInfo.SourceException);
|
||||
}
|
||||
else if (scriptResult.ReturnValue != null)
|
||||
{
|
||||
ioHandler.WriteLine(scriptResult.ReturnValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
SparkConf sparkConf = new SparkConf();
|
||||
SparkContext sc = new SparkContext(sparkConf);
|
||||
var scriptEngine = new RoslynScriptEngine(sc);
|
||||
var repl = new Repl(scriptEngine, new ConsoleIoHandler());
|
||||
repl.Init();
|
||||
repl.Run();
|
||||
scriptEngine.Cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Microsoft.Spark.CSharp</RootNamespace>
|
||||
<AssemblyName>Repl</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
|
|
|
@ -40,11 +40,12 @@ namespace Microsoft.Spark.CSharp
|
|||
private readonly SparkConf sparkConf;
|
||||
private readonly SparkContext sc;
|
||||
private readonly SparkCLRHost host;
|
||||
private readonly ParseOptions options;
|
||||
|
||||
public RoslynScriptEngine(SparkConf sparkConf, SparkContext sc)
|
||||
public RoslynScriptEngine(SparkContext sc)
|
||||
{
|
||||
this.sparkConf = sparkConf;
|
||||
this.sc = sc;
|
||||
sparkConf = sc.GetConf();
|
||||
host = new SparkCLRHost
|
||||
{
|
||||
sc = sc,
|
||||
|
@ -54,6 +55,8 @@ namespace Microsoft.Spark.CSharp
|
|||
var sparkLocalDir = sparkConf.Get("spark.local.dir", Path.GetTempPath());
|
||||
compilationDumpDirectory = Path.Combine(sparkLocalDir, Path.GetRandomFileName());
|
||||
Directory.CreateDirectory(compilationDumpDirectory);
|
||||
|
||||
options = new CSharpParseOptions(LanguageVersion.CSharp6, DocumentationMode.Parse, SourceCodeKind.Script);
|
||||
}
|
||||
|
||||
internal Script<object> CreateScript(string code)
|
||||
|
@ -103,7 +106,7 @@ namespace Microsoft.Spark.CSharp
|
|||
{
|
||||
message.Append("[").Append(diagnostic.Severity).Append("] ").Append(": ").Append(diagnostic).Append("\r\n");
|
||||
}
|
||||
return new ScriptResult(null, null, new Exception(message.ToString()));
|
||||
return new ScriptResult(compilationException: new Exception(message.ToString()));
|
||||
}
|
||||
|
||||
var compilationDump = DumpCompilation(script.GetCompilation());
|
||||
|
@ -135,11 +138,11 @@ namespace Microsoft.Spark.CSharp
|
|||
}
|
||||
}
|
||||
previousState = endState;
|
||||
return new ScriptResult(endState.ReturnValue, null, null);
|
||||
return new ScriptResult(returnValue: endState.ReturnValue);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ScriptResult(null, e, null);
|
||||
return new ScriptResult(executionException: e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,7 +168,6 @@ namespace Microsoft.Spark.CSharp
|
|||
/// </summary>
|
||||
internal bool IsCompleteSubmission(string code)
|
||||
{
|
||||
var options = new CSharpParseOptions(LanguageVersion.CSharp6, DocumentationMode.Diagnose, SourceCodeKind.Script);
|
||||
SyntaxTree syntaxTree = SyntaxFactory.ParseSyntaxTree(code, options);
|
||||
return SyntaxFactory.IsCompleteSubmission(syntaxTree);
|
||||
}
|
||||
|
@ -188,7 +190,7 @@ namespace Microsoft.Spark.CSharp
|
|||
/// <summary>
|
||||
/// Clean up compilation dump directory.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
public void Cleanup()
|
||||
{
|
||||
// delete DLLs dump directory on exit
|
||||
if (Directory.Exists(compilationDumpDirectory))
|
||||
|
|
|
@ -9,6 +9,8 @@ namespace Microsoft.Spark.CSharp
|
|||
public class ScriptResult
|
||||
{
|
||||
public static readonly ScriptResult Incomplete = new ScriptResult { IsCompleteSubmission = false };
|
||||
|
||||
public static readonly ScriptResult Empty = new ScriptResult();
|
||||
|
||||
public ScriptResult(
|
||||
object returnValue = null,
|
||||
|
@ -33,10 +35,10 @@ namespace Microsoft.Spark.CSharp
|
|||
IsCompleteSubmission = true;
|
||||
}
|
||||
|
||||
public object ReturnValue { get; private set; }
|
||||
|
||||
public bool IsCompleteSubmission { get; private set; }
|
||||
|
||||
public object ReturnValue { get; private set; }
|
||||
|
||||
public ExceptionDispatchInfo ExecuteExceptionInfo { get; private set; }
|
||||
|
||||
public ExceptionDispatchInfo CompileExceptionInfo { get; private set; }
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="log4net" version="2.0.5" targetFramework="net45" />
|
||||
<package id="Microsoft.Net.Compilers" version="1.1.1" targetFramework="net45" />
|
||||
<package id="Razorvine.Pyrolite" version="4.10.0.0" targetFramework="net45" />
|
||||
<package id="Razorvine.Serpent" version="1.12.0.0" targetFramework="net45" />
|
||||
<package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" />
|
||||
<package id="Razorvine.Pyrolite" version="4.10.0" targetFramework="net45" />
|
||||
<package id="Razorvine.Serpent" version="1.12.0" targetFramework="net45" />
|
||||
</packages>
|
|
@ -0,0 +1,36 @@
|
|||
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("ReplTest")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("ReplTest")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2016")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[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("8942619e-e566-4ada-b850-6d85f9f21a88")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
|
@ -0,0 +1,100 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Spark.CSharp;
|
||||
using Microsoft.Spark.CSharp.Core;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ReplTest
|
||||
{
|
||||
[TestFixture]
|
||||
public class ReplTest
|
||||
{
|
||||
internal class TestIoHandler : IoHandler
|
||||
{
|
||||
internal BlockingCollection<string> input = new BlockingCollection<string>();
|
||||
internal List<string> output = new List<string>();
|
||||
|
||||
public void Write(object obj)
|
||||
{
|
||||
WriteLine(obj);
|
||||
}
|
||||
|
||||
public void WriteLine(object obj)
|
||||
{
|
||||
output.Add(obj.ToString());
|
||||
}
|
||||
|
||||
public void WriteException(Exception e)
|
||||
{
|
||||
output.Add(e.ToString());
|
||||
}
|
||||
|
||||
public string ReadLine()
|
||||
{
|
||||
return input.Take();
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test()
|
||||
{
|
||||
var sc = new SparkContext("", "");
|
||||
|
||||
var scriptEngine = new RoslynScriptEngine(sc);
|
||||
var ioHandler = new TestIoHandler();
|
||||
|
||||
var repl = new Repl(scriptEngine, ioHandler);
|
||||
|
||||
repl.Init();
|
||||
var thread = new Thread(() => { repl.Run();}) { IsBackground = false };
|
||||
thread.Start();
|
||||
|
||||
Assert.IsTrue(ioHandler.output.Any());
|
||||
Assert.AreEqual("> ", ioHandler.output.Last());
|
||||
|
||||
ioHandler.output.Clear();
|
||||
|
||||
// empty input
|
||||
ioHandler.input.Add(" ");
|
||||
|
||||
// incomplete code block
|
||||
ioHandler.input.Add("if (true) {");
|
||||
ioHandler.input.Add("return 1024; }");
|
||||
// execution exception
|
||||
ioHandler.input.Add("new Exception(\"Test\")");
|
||||
// compile exception
|
||||
ioHandler.input.Add("var a=;");
|
||||
|
||||
// quit REPL
|
||||
ioHandler.input.Add(":quit");
|
||||
thread.Join();
|
||||
scriptEngine.Cleanup();
|
||||
|
||||
Console.WriteLine(string.Join("\r\n", ioHandler.output));
|
||||
// Assert.AreEqual(1, ioHandler.output.Count);
|
||||
Assert.AreEqual("> ", ioHandler.output[0]);
|
||||
Assert.AreEqual(". ", ioHandler.output[1]);
|
||||
Assert.AreEqual("1024", ioHandler.output[2]);
|
||||
Assert.AreEqual("> ", ioHandler.output[3]);
|
||||
|
||||
// execution exception
|
||||
Assert.IsTrue(ioHandler.output[4].Contains("System.Exception: Test"));
|
||||
Assert.AreEqual("> ", ioHandler.output[5]);
|
||||
// compile exception
|
||||
Assert.IsTrue(ioHandler.output[6].Contains("Exception"));
|
||||
Assert.AreEqual("> ", ioHandler.output[7]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{C3EF77C2-514D-48EB-9B4B-DD70C7DF4CE9}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>ReplTest</RootNamespace>
|
||||
<AssemblyName>ReplTest</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="nunit.framework, Version=3.0.5813.39031, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NUnit.3.0.1\lib\net45\nunit.framework.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net40\Moq.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ReplTest.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SparkCLRTestEnvironment.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AdapterTest\AdapterTest.csproj">
|
||||
<Project>{d5c2c46e-3fec-473b-8aba-3b0fc5a7319c}</Project>
|
||||
<Name>AdapterTest</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Adapter\Microsoft.Spark.CSharp\Adapter.csproj">
|
||||
<Project>{ce999a96-f42b-4e80-b208-709d7f49a77c}</Project>
|
||||
<Name>Adapter</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Repl\Repl.csproj">
|
||||
<Project>{61ff0035-3910-4356-b2dc-af6b857317ab}</Project>
|
||||
<Name>Repl</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Tests.Common\Tests.Common.csproj">
|
||||
<Project>{e4479c4c-e106-4b90-bf0c-319561cea9c4}</Project>
|
||||
<Name>Tests.Common</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
|
@ -0,0 +1,28 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using AdapterTest;
|
||||
using AdapterTest.Mocks;
|
||||
using Microsoft.Spark.CSharp.Interop;
|
||||
using Microsoft.Spark.CSharp.Interop.Ipc;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace ReplTest
|
||||
{
|
||||
[SetUpFixture]
|
||||
public class SparkCLRTestEnvironment
|
||||
{
|
||||
[OneTimeSetUp]
|
||||
public static void Initialize()
|
||||
{
|
||||
Console.WriteLine("Running SparkCLRTestEnvironment Initialize()");
|
||||
SparkCLREnvironment.SparkCLRProxy = new MockSparkCLRProxy();
|
||||
SparkCLREnvironment.ConfigurationService = new MockConfigurationService();
|
||||
SparkCLREnvironment.WeakObjectManager = new WeakObjectManagerImpl
|
||||
{
|
||||
ObjectReleaser = new MockObjectReleaser(),
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Moq" version="4.2.1510.2205" targetFramework="net45" />
|
||||
<package id="NUnit" version="3.0.1" targetFramework="net45" />
|
||||
</packages>
|
|
@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Microsoft.Sp
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests.Common", "Tests.Common\Tests.Common.csproj", "{E4479C4C-E106-4B90-BF0C-319561CEA9C4}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReplTest", "ReplTest\ReplTest.csproj", "{C3EF77C2-514D-48EB-9B4B-DD70C7DF4CE9}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -67,6 +69,10 @@ Global
|
|||
{E4479C4C-E106-4B90-BF0C-319561CEA9C4}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E4479C4C-E106-4B90-BF0C-319561CEA9C4}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E4479C4C-E106-4B90-BF0C-319561CEA9C4}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C3EF77C2-514D-48EB-9B4B-DD70C7DF4CE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C3EF77C2-514D-48EB-9B4B-DD70C7DF4CE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C3EF77C2-514D-48EB-9B4B-DD70C7DF4CE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C3EF77C2-514D-48EB-9B4B-DD70C7DF4CE9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -305,7 +305,15 @@ namespace Microsoft.Spark.CSharp
|
|||
if ("R".Equals(runMode, StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
var compilationDumpDir = SerDe.ReadString(networkStream);
|
||||
assemblyHandler.LoadAssemblies(Directory.GetFiles(compilationDumpDir, "ReplCompilation.*", SearchOption.TopDirectoryOnly));
|
||||
if (Directory.Exists(compilationDumpDir))
|
||||
{
|
||||
assemblyHandler.LoadAssemblies(Directory.GetFiles(compilationDumpDir, "ReplCompilation.*",
|
||||
SearchOption.TopDirectoryOnly));
|
||||
}
|
||||
else
|
||||
{
|
||||
logger.LogError("Directory " + compilationDumpDir + " dose not exist.");
|
||||
}
|
||||
}
|
||||
|
||||
byte[] command = SerDe.ReadBytes(networkStream);
|
||||
|
|
Загрузка…
Ссылка в новой задаче