http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/evaluator/IEvaluatorRequest .cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/evaluator/IEvaluatorRequest .cs b/lang/cs/Org.Apache.REEF.Driver/evaluator/IEvaluatorRequest .cs new file mode 100644 index 0000000..ded8db6 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/evaluator/IEvaluatorRequest .cs @@ -0,0 +1,42 @@ +/** + * 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. + */ + +using Org.Apache.REEF.Common.Capabilities; +using Org.Apache.REEF.Common.Catalog; +using System.Collections.Generic; + +namespace Org.Apache.REEF.Driver.Evaluator +{ + public interface IEvaluatorRequest + { + int MemoryMegaBytes { get; set; } + + int Number { get; set; } + + int VirtualCore { get; set; } + + string Rack { get; set; } + + string EvaluatorBatchId { get; set; } + + List<ICapability> Capabilities { get; set; } + + IResourceCatalog Catalog { get; set; } + } +}
http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/evaluator/IEvaluatorRequestor.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/evaluator/IEvaluatorRequestor.cs b/lang/cs/Org.Apache.REEF.Driver/evaluator/IEvaluatorRequestor.cs new file mode 100644 index 0000000..ac374ce --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/evaluator/IEvaluatorRequestor.cs @@ -0,0 +1,47 @@ +/** + * 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. + */ + +using System.Collections.Generic; + +using Org.Apache.REEF.Common.Catalog; + +namespace Org.Apache.REEF.Driver.Evaluator +{ + /// <summary> + /// Interface through which Evaluators can be requested. + /// </summary> + public interface IEvaluatorRequestor + { + /// <summary> + /// Access to the {@link ResourceCatalog} for the cluster this Factory has access to + /// </summary> + IResourceCatalog ResourceCatalog { get; set; } + + /// <summary> + /// Map between user evaluator id and evaluator information + /// </summary> + //IDictionary<string, IEvaluatorDescriptor> Evaluators { get; } + + /// <summary> + /// Submit the request for new evaluator. The response will surface in the AllocatedEvaluator message handler. + /// </summary> + /// <param name="request"></param> + void Submit(IEvaluatorRequest request); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/evaluator/IFailedEvaluator.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/evaluator/IFailedEvaluator.cs b/lang/cs/Org.Apache.REEF.Driver/evaluator/IFailedEvaluator.cs new file mode 100644 index 0000000..cd2ae2c --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/evaluator/IFailedEvaluator.cs @@ -0,0 +1,41 @@ +/** + * 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. + */ + +using Org.Apache.REEF.Common.Exceptions; +using Org.Apache.REEF.Driver.Bridge; +using Org.Apache.REEF.Driver.Task; +using Org.Apache.REEF.Utilities; +using System.Collections.Generic; + +namespace Org.Apache.REEF.Driver.Evaluator +{ + /// <summary> + /// Represents an Evaluator that became unavailable. + /// </summary> + public interface IFailedEvaluator : IIdentifiable + { + EvaluatorException EvaluatorException { get; set; } + + List<FailedContext> FailedContexts { get; set; } + + Optional<IFailedTask> FailedTask { get; set; } + + IEvaluatorRequestor GetEvaluatorRequetor(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/packages.config ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/packages.config b/lang/cs/Org.Apache.REEF.Driver/packages.config new file mode 100644 index 0000000..933b7e1 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/packages.config @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +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. +--> +<packages> + <package id="Microsoft.Hadoop.Avro" version="1.4.0.0" targetFramework="net45" /> + <package id="Newtonsoft.Json" version="6.0.8" targetFramework="net45" /> + <package id="protobuf-net" version="2.0.0.668" targetFramework="net45" /> +</packages> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/task/ICompletedTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/task/ICompletedTask.cs b/lang/cs/Org.Apache.REEF.Driver/task/ICompletedTask.cs new file mode 100644 index 0000000..bfd15c7 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/task/ICompletedTask.cs @@ -0,0 +1,29 @@ +/** + * 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. + */ + +using Org.Apache.REEF.Driver.Context; +using Org.Apache.REEF.Utilities; + +namespace Org.Apache.REEF.Driver.Task +{ + public interface ICompletedTask : IMessage, IIdentifiable + { + IActiveContext ActiveContext { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/task/IFailedTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/task/IFailedTask.cs b/lang/cs/Org.Apache.REEF.Driver/task/IFailedTask.cs new file mode 100644 index 0000000..6d12993 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/task/IFailedTask.cs @@ -0,0 +1,30 @@ +/** + * 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. + */ + +using Org.Apache.REEF.Common.Api; +using Org.Apache.REEF.Driver.Context; +using Org.Apache.REEF.Utilities; + +namespace Org.Apache.REEF.Driver.Task +{ + public interface IFailedTask : IAbstractFailure + { + Optional<IActiveContext> GetActiveContext(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/task/IRunningTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/task/IRunningTask.cs b/lang/cs/Org.Apache.REEF.Driver/task/IRunningTask.cs new file mode 100644 index 0000000..f1c4ea0 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/task/IRunningTask.cs @@ -0,0 +1,65 @@ +/** + * 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. + */ + +using Org.Apache.REEF.Driver.Context; +using Org.Apache.REEF.Utilities; +using System; + +namespace Org.Apache.REEF.Driver.Task +{ + /// <summary> + /// Represents a running Task + /// </summary> + public interface IRunningTask : IIdentifiable, IDisposable + { + /// <summary> + /// the context the task is running on. + /// </summary> + IActiveContext ActiveContext { get; set; } + + /// <summary> + /// Sends the message to the running task. + /// </summary> + /// <param name="message"></param> + void OnNext(byte[] message); + + /// <summary> + /// Sends the message + /// </summary> + /// <param name="message"></param> + void Send(byte[] message); + + /// <summary> + /// Signal the task to suspend. + /// </summary> + /// <param name="message">a message that is sent to the Task.</param> + void Suspend(byte[] message); + + /// <summary> + /// Sends the message to the running task. + /// </summary> + void Suspend(); + + /// <summary> + /// Signal the task to shut down. + /// </summary> + /// <param name="message">a message that is sent to the Task.</param> + void Dispose(byte[] message); + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/task/ISuspendedTask.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/task/ISuspendedTask.cs b/lang/cs/Org.Apache.REEF.Driver/task/ISuspendedTask.cs new file mode 100644 index 0000000..80f7976 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/task/ISuspendedTask.cs @@ -0,0 +1,29 @@ +/** + * 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. + */ + +using Org.Apache.REEF.Driver.Context; +using Org.Apache.REEF.Utilities; + +namespace Org.Apache.REEF.Driver +{ + public interface ISuspendedTask : IMessage, IIdentifiable + { + IActiveContext ActiveContext { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/task/ITaskMessage.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/task/ITaskMessage.cs b/lang/cs/Org.Apache.REEF.Driver/task/ITaskMessage.cs new file mode 100644 index 0000000..e06c8f3 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/task/ITaskMessage.cs @@ -0,0 +1,28 @@ +/** + * 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. + */ + +namespace Org.Apache.REEF.Driver.Task +{ + public interface ITaskMessage + { + byte[] Message { get; set; } + + string TaskId { get; set; } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Driver/task/RunningTaskImpl.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Driver/task/RunningTaskImpl.cs b/lang/cs/Org.Apache.REEF.Driver/task/RunningTaskImpl.cs new file mode 100644 index 0000000..94a4435 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Driver/task/RunningTaskImpl.cs @@ -0,0 +1,127 @@ +/** + * 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. + */ + +using Org.Apache.REEF.Common; +using Org.Apache.REEF.Common.ProtoBuf.EvaluatorRunTimeProto; +using Org.Apache.REEF.Driver.Context; +using Org.Apache.REEF.Utilities.Logging; +using System.Globalization; + +namespace Org.Apache.REEF.Driver.Task +{ + public class RunningTaskImpl : IRunningTask + { + private static readonly Logger LOGGER = Logger.GetLogger(typeof(RunningTaskImpl)); + + private string _id; + + private EvaluatorManager _evaluatorManager; + + private EvaluatorContext _evaluatorContext; + + public RunningTaskImpl(EvaluatorManager evaluatorManager, string taskId, EvaluatorContext evaluatorContext) + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "INIT: TaskRuntime id [{0}] on evaluator id [{1}]", taskId, evaluatorManager.Id)); + _id = taskId; + _evaluatorManager = evaluatorManager; + _evaluatorContext = evaluatorContext; + } + + public string Id + { + get + { + return _id; + } + + set + { + } + } + + public IActiveContext ActiveContext + { + get + { + return _evaluatorContext; + } + + set + { + } + } + + public void Dispose() + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "DISPOSE: TaskRuntime id [{0}] on evaluator id [{1}]", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.stop_task = new StopTaskProto(); + _evaluatorManager.Handle(contextControlProto); + } + + public void Dispose(byte[] message) + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "DISPOSE: TaskRuntime id [{0}] on evaluator id [{1}] with message", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.stop_task = new StopTaskProto(); + contextControlProto.task_message = message; + _evaluatorManager.Handle(contextControlProto); + } + + public void OnNext(byte[] message) + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "MESSAGE: TaskRuntime id [{0}] on evaluator id [{1}]", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.task_message = message; + _evaluatorManager.Handle(contextControlProto); + } + + public void Suspend(byte[] message) + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "SUSPEND: TaskRuntime id [{0}] on evaluator id [{1}] with message", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.suspend_task = new SuspendTaskProto(); + contextControlProto.task_message = message; + _evaluatorManager.Handle(contextControlProto); + } + + public void Suspend() + { + LOGGER.Log(Level.Info, string.Format(CultureInfo.InvariantCulture, "SUSPEND: TaskRuntime id [{0}] on evaluator id [{1}]", _id, _evaluatorManager.Id)); + ContextControlProto contextControlProto = new ContextControlProto(); + contextControlProto.suspend_task = new SuspendTaskProto(); + _evaluatorManager.Handle(contextControlProto); + } + + public override string ToString() + { + return "TaskRuntime with taskId = " + _id; + } + + public override int GetHashCode() + { + return _id.GetHashCode(); + } + + public void Send(byte[] message) + { + LOGGER.Log(Level.Info, "RunningTaskImpl.Send() is called"); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/AnonymousType.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/AnonymousType.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/AnonymousType.cs new file mode 100644 index 0000000..ad5bd26 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/AnonymousType.cs @@ -0,0 +1,57 @@ +/** + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.Tang.Examples +{ + public class MyEventStreamDefinition + { + public ISet<int> Shards { get; set; } + + public Type Type { get; set; } + } + + public class AnonymousType + { + private Dictionary<string, MyEventStreamDefinition> d = new Dictionary<string, MyEventStreamDefinition>(); + private Dictionary<string, int> d2; + + //Anonymous class in injectable constructor + [Inject] + public AnonymousType() + { + d2 = d + .Select((e, i) => new { e.Key, i }) + .ToDictionary(e => e.Key, e => e.i); + } + + //Anonymous class in other constructor + public AnonymousType(Dictionary<string, MyEventStreamDefinition> d) + { + this.d = d; + d2 = d + .Select((e, i) => new { e.Key, i }) + .ToDictionary(e => e.Key, e => e.i); + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/CheckChild.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/CheckChild.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/CheckChild.cs new file mode 100644 index 0000000..c925c36 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/CheckChild.cs @@ -0,0 +1,37 @@ +/** + * 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. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.Tang.Examples +{ + public interface CheckChildIface + { + } + + public class CheckChildImpl : CheckChildIface + { + [Inject] + public CheckChildImpl() {} + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/DocumentedLocalNamedParameter.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/DocumentedLocalNamedParameter.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/DocumentedLocalNamedParameter.cs new file mode 100644 index 0000000..3a2b88e --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/DocumentedLocalNamedParameter.cs @@ -0,0 +1,43 @@ +/** + * 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. + */ +using System; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.Tang.Examples +{ + public class DocumentedLocalNamedParameter + { + string value; + [NamedParameter(Documentation = "doc stuff", ShortName = "DocFoo", DefaultValue = "some value")] + public sealed class Foo : Name<String> + { + } + + [Inject] + public DocumentedLocalNamedParameter([Parameter(typeof(Foo))] String s) + { + value = s; + } + + public override string ToString() + { + return value; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/FileNames.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/FileNames.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/FileNames.cs new file mode 100644 index 0000000..840fd3a --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/FileNames.cs @@ -0,0 +1,39 @@ +/** + * 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. + */ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Org.Apache.REEF.Tang.Examples +{ + public class FileNames + { + public static string Examples = @"Org.Apache.REEF.Tang.Examples"; + public static string Common = @"Org.Apache.REEF.Common"; + public static string Tasks = @"Org.Apache.REEF.Tasks"; + public static string Seconds = "Org.Apache.REEF.Tang.Examples.Timer+Seconds"; + public static string Timer = "Org.Apache.REEF.Tang.Examples.Timer"; + public static string B = "Org.Apache.REEF.Tang.Examples.B"; + public static string B1 = "Org.Apache.REEF.Tang.Examples.B+B1"; + public static string B2 = "Org.Apache.REEF.Tang.Examples.B+B1+B2"; + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/ForksInjectorInConstructor.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/ForksInjectorInConstructor.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/ForksInjectorInConstructor.cs new file mode 100644 index 0000000..20c2091 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/ForksInjectorInConstructor.cs @@ -0,0 +1,60 @@ +/** + * 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. + */ +using System; +using System.Collections.Generic; +/** + * 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. + */ + +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Tang.Implementations; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Implementations.Tang; + +namespace Org.Apache.REEF.Tang.Examples +{ + public class ForksInjectorInConstructor + { + [Inject] + public ForksInjectorInConstructor(IInjector i) + { + ICsConfigurationBuilder cb = TangFactory.GetTang().NewConfigurationBuilder(new string[] { @"Org.Apache.REEF.Tang.Examples" }); + //cb.BindImplementation(Number.class, typeof(Int32)); + i.ForkInjector(new IConfiguration[] { cb.Build() }); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/GenericArgument.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/GenericArgument.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/GenericArgument.cs new file mode 100644 index 0000000..2be2db3 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/GenericArgument.cs @@ -0,0 +1,48 @@ +/** + * 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. + */ + +using System; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Wake.RX; + +namespace Org.Apache.REEF.Tang.Examples +{ + public class GenericArgument<T> : AbstractObserver<T> + { + [Inject] + public GenericArgument() + { + } + + public override void OnNext(T arg1) + { + throw new NotImplementedException(); + } + } + + public class ClassWithGenericArgument<T> + { + private T _obj; + + public ClassWithGenericArgument(T obj) + { + _obj = obj; + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/GenericAsArgument.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/GenericAsArgument.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/GenericAsArgument.cs new file mode 100644 index 0000000..7665582 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/GenericAsArgument.cs @@ -0,0 +1,44 @@ +/** + * 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. + */ + +namespace Org.Apache.REEF.Tang.Examples +{ + public class Event<TPayload> + { + public Event() + { + } + + public Event(StreamEvent<TPayload> trillEvent) + { + } + + public StreamEvent<TPayload> ToStreamEvent() + { + return null; + } + } + + public class StreamEvent<T> + { + public StreamEvent() + { + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/NamedParameterConstructors.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/NamedParameterConstructors.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/NamedParameterConstructors.cs new file mode 100644 index 0000000..d3e784e --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/NamedParameterConstructors.cs @@ -0,0 +1,40 @@ +/** + * 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. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.Tang.Examples +{ + public class NamedParameterConstructors + { + [NamedParameter()] + public class X : Name<String> + { + }; + + [Inject] + public NamedParameterConstructors(String x, [Parameter(typeof(X))] String y) + { + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/Org.Apache.REEF.Tang.Examples.csproj ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/Org.Apache.REEF.Tang.Examples.csproj b/lang/cs/Org.Apache.REEF.Tang.Examples/Org.Apache.REEF.Tang.Examples.csproj new file mode 100644 index 0000000..33c9b03 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/Org.Apache.REEF.Tang.Examples.csproj @@ -0,0 +1,119 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +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. +--> +<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>{711B7F32-196E-4C21-9DBD-AD59C4A7CF77}</ProjectGuid> + <OutputType>Library</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>Org.Apache.REEF.Tang.Examples</RootNamespace> + <AssemblyName>Org.Apache.REEF.Tang.Examples</AssemblyName> + <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <RestorePackages>true</RestorePackages> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir> + </PropertyGroup> + <Import Project="$(SolutionDir)\Source\build.props" /> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>$(BinDir)\$(Platform)\$(Configuration)\$(RootNamespace)</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <ItemGroup> + <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="AnonymousType.cs" /> + <Compile Include="CheckChild.cs" /> + <Compile Include="DocumentedLocalNamedParameter.cs" /> + <Compile Include="FileNames.cs" /> + <Compile Include="ForksInjectorInConstructor.cs" /> + <Compile Include="GenericArgument.cs" /> + <Compile Include="GenericAsArgument.cs" /> + <Compile Include="NamedParameterConstructors.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + <Compile Include="ShortNameFooAB.cs" /> + <Compile Include="SimpleConstructors.cs" /> + <Compile Include="TestClasses.cs" /> + <Compile Include="Timer.cs" /> + <Compile Include="TweetExample.cs" /> + </ItemGroup> + <ItemGroup> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Tang\Org.Apache.REEF.Tang.csproj"> + <Project>{97dbb573-3994-417a-9f69-ffa25f00d2a6}</Project> + <Name>Org.Apache.REEF.Tang</Name> + </ProjectReference> + <ProjectReference Include="$(SolutionDir)\Org.Apache.REEF.Utilities\Org.Apache.REEF.Utilities.csproj"> + <Project>{79e7f89a-1dfb-45e1-8d43-d71a954aeb98}</Project> + <Name>Org.Apache.REEF.Utilities</Name> + </ProjectReference> + <ProjectReference Include="..\Org.Apache.REEF.Wake\Org.Apache.REEF.Wake.csproj"> + <Project>{cdfb3464-4041-42b1-9271-83af24cd5008}</Project> + <Name>Org.Apache.REEF.Wake</Name> + </ProjectReference> + </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> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/Properties/AssemblyInfo.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/Properties/AssemblyInfo.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..efe60ce --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/Properties/AssemblyInfo.cs @@ -0,0 +1,55 @@ +/** + * 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. + */ + +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("Org.Apache.REEF.Tang.Examples")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Org.Apache.REEF.Tang.Examples")] +[assembly: AssemblyCopyright("Copyright © 2015")] +[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("cb44520c-2fd1-4d3b-9b9a-250f94a11239")] + +// 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")] http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/ShortNameFooAB.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/ShortNameFooAB.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/ShortNameFooAB.cs new file mode 100644 index 0000000..fbbdf6b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/ShortNameFooAB.cs @@ -0,0 +1,38 @@ +/** + * 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. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.Tang.Examples +{ + [NamedParameter(ShortName = "fooA")] + public class ShortNameFooA : Name<String> + { + } + + //when same short name is used, exception would throw when building the class hierarchy + [NamedParameter(ShortName = "fooB")] + public class ShortNameFooB : Name<Int32> + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/SimpleConstructors.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/SimpleConstructors.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/SimpleConstructors.cs new file mode 100644 index 0000000..b1acc7e --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/SimpleConstructors.cs @@ -0,0 +1,42 @@ +/** + * 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. + */ +using System; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.Tang.Examples +{ + public class SimpleConstructors + { + [Inject] + public SimpleConstructors() + { + } + + [Inject] + public SimpleConstructors(int x) + { + } + + [Inject] + public SimpleConstructors(int x, String y) + { + } + + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/TestClasses.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/TestClasses.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/TestClasses.cs new file mode 100644 index 0000000..9cdaa0c --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/TestClasses.cs @@ -0,0 +1,57 @@ +/** + * 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. + */ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.Tang.Examples +{ + public interface A + { + + } + + public class B : A + { + public class B1 + { + public class B2 { } + } + } + + public class C : B + { + string s; + int v; + + [Inject] + public C(string s, int v) + { + this.s = s; + this.v = v; + } + } + + public static class E + { + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/Timer.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/Timer.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/Timer.cs new file mode 100644 index 0000000..85886c3 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/Timer.cs @@ -0,0 +1,46 @@ +/** + * 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. + */ +using System; +using System.Threading; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.Tang.Examples +{ + public class Timer + { + [NamedParameter("Number of seconds to sleep", "sec", "10")] + public class Seconds : Name<Int32> { } + private readonly int seconds; + + [Inject] + public Timer([Parameter(typeof(Seconds))] int seconds) + { + if (seconds < 0) + { + throw new ArgumentException("Cannot sleep for negative time!"); + } + this.seconds = seconds; + } + + public void sleep() + { + Thread.Sleep(seconds * 1000); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Examples/TweetExample.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Examples/TweetExample.cs b/lang/cs/Org.Apache.REEF.Tang.Examples/TweetExample.cs new file mode 100644 index 0000000..5053069 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Examples/TweetExample.cs @@ -0,0 +1,90 @@ +/** + * 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. + */ +using System; +using Org.Apache.REEF.Tang.Annotations; + +namespace Org.Apache.REEF.Tang.Examples +{ + public interface ISMS + { + void SendSMS(String msg, long phoneNumber); + } + + public interface ITweetFactory + { + String GetTweet(); + } + + public class MockTweetFactory : ITweetFactory + { + [Inject] + public MockTweetFactory() { + } + + public String GetTweet() + { + return "@tw #bbq bbqftw!!! gopher://vuwed.wefd/bbqftw!"; + } + } + + public class MockSMS : ISMS + { + [Inject] + public MockSMS() + { + } + + public void SendSMS(String msg, long phoneNumber) + { + if (phoneNumber != 8675309) + { + throw new ArgumentException("Unknown recipient"); + } + // success! + } + } + + public class Tweeter + { + ITweetFactory tw; + ISMS sms; + long phoneNumber; + + [NamedParameter(Documentation="Phone number", ShortName="number", DefaultValue="1800")] + public class PhoneNumber : Name<long> { } + [Inject] + public Tweeter(ITweetFactory tw, ISMS sms, [Parameter(typeof(PhoneNumber))] long phoneNumber) + { + this.tw = tw; + this.sms = sms; + this.phoneNumber = phoneNumber; + } + + [Inject] + public Tweeter([Parameter(typeof(PhoneNumber))] long phoneNumber) + { + this.phoneNumber = phoneNumber; + } + + public void sendMessage() + { + sms.SendSMS(tw.GetTweet(), phoneNumber); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestAnonymousType.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestAnonymousType.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestAnonymousType.cs new file mode 100644 index 0000000..fb12c1b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestAnonymousType.cs @@ -0,0 +1,64 @@ +/** + * 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. + */ + +using System; +using System.Collections.Generic; +using System.IO; +using Org.Apache.REEF.Tang.Examples; +using Org.Apache.REEF.Tang.Implementations; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Protobuf; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.REEF.Tang.Implementations.Tang; + +namespace Org.Apache.REEF.Tang.Tests.ClassHierarchy +{ + [TestClass] + public class TestAnonymousType + { + const string ClassHierarchyBinFileName = "example.bin"; + + [ClassInitialize] + public static void ClassSetup(TestContext context) + { + TangImpl.Reset(); + } + + [TestMethod] + public void TestAnonymousTypeWithDictionary() + { + List<string> appDlls = new List<string>(); + appDlls.Add(typeof(AnonymousType).Assembly.GetName().Name); + var c = TangFactory.GetTang().GetClassHierarchy(appDlls.ToArray()); + c.GetNode(typeof(AnonymousType).AssemblyQualifiedName); + + IConfiguration conf = TangFactory.GetTang().NewConfigurationBuilder(c).Build(); + IInjector injector = TangFactory.GetTang().NewInjector(conf); + var obj = injector.GetInstance<AnonymousType>(); + Assert.IsNotNull(obj); + + var cd = Directory.GetCurrentDirectory(); + Console.WriteLine(cd); + + ProtocolBufferClassHierarchy.Serialize(ClassHierarchyBinFileName, c); + IClassHierarchy ch = ProtocolBufferClassHierarchy.DeSerialize(ClassHierarchyBinFileName); + ch.GetNode(typeof(AnonymousType).AssemblyQualifiedName); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestClassHierarchy.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestClassHierarchy.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestClassHierarchy.cs new file mode 100644 index 0000000..935d739 --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestClassHierarchy.cs @@ -0,0 +1,719 @@ +/** + * 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. + */ + +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.REEF.Tang.Annotations; +using Org.Apache.REEF.Tang.Examples; +using Org.Apache.REEF.Tang.Exceptions; +using Org.Apache.REEF.Tang.Implementations; +using Org.Apache.REEF.Tang.Implementations.Tang; +using Org.Apache.REEF.Tang.Interface; +using Org.Apache.REEF.Tang.Types; +using Org.Apache.REEF.Tang.Util; +using System; +using System.Collections.Generic; + +namespace Org.Apache.REEF.Tang.Tests.ClassHierarchy +{ + [TestClass] + public class TestClassHierarchy + { + public static IClassHierarchy ns; + + [ClassInitialize] + public static void ClassSetup(TestContext context) + { + TangImpl.Reset(); + ns = TangFactory.GetTang().GetClassHierarchy(new string[] { FileNames.Examples, FileNames.Common, FileNames.Tasks }); + } + + [ClassCleanup] + public static void ClassCleanup() + { + } + + [TestInitialize()] + public void TestSetup() + { + } + + [TestCleanup()] + public void TestCleanup() + { + } + + [TestMethod] + public void TestString() + { + INode n = null; + try + { + n = ns.GetNode("System"); + } + catch (ApplicationException) + { + } + catch (NameResolutionException) + { + } + Assert.IsNull(n); + + Assert.IsNotNull(ns.GetNode(typeof(System.String).AssemblyQualifiedName)); + + string msg = null; + try + { + ns.GetNode("org.apache"); + msg = "Didn't get expected exception"; + } + catch (ApplicationException) + { + } + catch (NameResolutionException) + { + + } + Assert.IsNull(msg, msg); + } + + [TestMethod] + public void TestInt() + { + INode n = null; + try + { + n = ns.GetNode("System"); + } + catch (ApplicationException) + { + } + catch (NameResolutionException) + { + } + Assert.IsNull(n); + + Assert.IsNotNull(ns.GetNode(typeof(System.Int32).AssemblyQualifiedName)); + + string msg = null; + try + { + ns.GetNode("org.apache"); + msg = "Didn't get expected exception"; + } + catch (ApplicationException) + { + } + catch (NameResolutionException) + { + + } + Assert.IsNull(msg, msg); + } + + [TestMethod] + public void TestSimpleConstructors() + { + IClassNode cls = (IClassNode)ns.GetNode(typeof(SimpleConstructors).AssemblyQualifiedName); + Assert.IsTrue(cls.GetChildren().Count == 0); + IList<IConstructorDef> def = cls.GetInjectableConstructors(); + Assert.AreEqual(3, def.Count); + } + + [TestMethod] + public void TestTimer() + { + IClassNode timerClassNode = (IClassNode)ns.GetNode(typeof(Timer).AssemblyQualifiedName); + INode secondNode = ns.GetNode(typeof(Timer.Seconds).AssemblyQualifiedName); + Assert.AreEqual(secondNode.GetFullName(), ReflectionUtilities.GetAssemblyQualifiedName(typeof(Timer.Seconds))); + + } + + [TestMethod] + public void TestNamedParameterConstructors() + { + var node = ns.GetNode(typeof(NamedParameterConstructors).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), ReflectionUtilities.GetAssemblyQualifiedName(typeof(NamedParameterConstructors))); + } + + [TestMethod] + public void TestArray() + { + Type t = (new string[0]).GetType(); + INode node = ns.GetNode(t.AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), t.AssemblyQualifiedName); + } + + [TestMethod] + public void TestRepeatConstructorArg() + { + TestNegativeCase(typeof(RepeatConstructorArg), + "Repeated constructor parameter detected. Cannot inject constructor RepeatConstructorArg(int,int)."); + } + + [TestMethod] + public void TestRepeatConstructorArgClasses() + { + TestNegativeCase(typeof(RepeatConstructorArgClasses), + "Repeated constructor parameter detected. Cannot inject constructor RepeatConstructorArgClasses(A, A)."); + } + + [TestMethod] + public void testLeafRepeatedConstructorArgClasses() + { + INode node = ns.GetNode(typeof(LeafRepeatedConstructorArgClasses).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), typeof(LeafRepeatedConstructorArgClasses).AssemblyQualifiedName); + } + + [TestMethod] + public void TestNamedRepeatConstructorArgClasses() + { + INode node = ns.GetNode(typeof(NamedRepeatConstructorArgClasses).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), typeof(NamedRepeatConstructorArgClasses).AssemblyQualifiedName); + } + + [TestMethod] + public void TestResolveDependencies() + { + ns.GetNode(typeof(SimpleConstructors).AssemblyQualifiedName); + Assert.IsNotNull(ns.GetNode(typeof(string).AssemblyQualifiedName)); + } + + [TestMethod] + public void TestDocumentedLocalNamedParameter() + { + var node = ns.GetNode(typeof(DocumentedLocalNamedParameter).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), ReflectionUtilities.GetAssemblyQualifiedName(typeof(DocumentedLocalNamedParameter))); + } + + [TestMethod] + public void TestNamedParameterTypeMismatch() + { + TestNegativeCase(typeof(NamedParameterTypeMismatch), + "Named parameter type mismatch in NamedParameterTypeMismatch. Constructor expects a System.String but Foo is a System.Int32."); + } + + [TestMethod] + public void TestUnannotatedName() + { + TestNegativeCase(typeof(UnannotatedName), + "Named parameter UnannotatedName is missing its [NamedParameter] attribute."); + } + + [TestMethod] + public void TestAnnotatedNotName() + { + TestNegativeCase(typeof(AnnotatedNotName), + "Found illegal [NamedParameter] AnnotatedNotName does not implement Name<T>."); + } + + [TestMethod] + public void TestAnnotatedNameWrongInterface() + { + TestNegativeCase(typeof(AnnotatedNameWrongInterface), + "Found illegal [NamedParameter] AnnotatedNameWrongInterface does not implement Name<T>."); + } + + [TestMethod] + public void TestAnnotatedNameMultipleInterfaces() + { + TestNegativeCase(typeof(AnnotatedNameMultipleInterfaces), + "Named parameter Org.Apache.REEF.Tang.Implementation.AnnotatedNameMultipleInterfaces implements multiple interfaces. It is only allowed to implement Name<T>."); + } + + [TestMethod] + public void TestUnAnnotatedNameMultipleInterfaces() + { + TestNegativeCase(typeof(UnAnnotatedNameMultipleInterfaces), + "Named parameter Org.Apache.REEF.Tang.Implementation.UnAnnotatedNameMultipleInterfaces is missing its @NamedParameter annotation."); + } + + [TestMethod] + public void TestNameWithConstructor() + { + TestNegativeCase(typeof(NameWithConstructor), + "Named parameter Org.Apache.REEF.Tang.Implementation.NameWithConstructor has a constructor. Named parameters must not declare any constructors."); + } + + [TestMethod] + public void TestNameWithZeroArgInject() + { + TestNegativeCase(typeof(NameWithZeroArgInject), + "Named parameter Org.Apache.REEF.Tang.Implementation.NameWithZeroArgInject has an injectable constructor. Named parameters must not declare any constructors."); + } + + [TestMethod] + public void TestInjectNonStaticLocalArgClass() + { + var node = ns.GetNode(typeof(InjectNonStaticLocalArgClass).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), typeof(InjectNonStaticLocalArgClass).AssemblyQualifiedName); + } + + [TestMethod] + public void TestInjectNonStaticLocalType() + { + var node = ns.GetNode(typeof(InjectNonStaticLocalType).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), typeof(InjectNonStaticLocalType).AssemblyQualifiedName); + } + + [TestMethod] + public void TestOKShortNames() + { + var node = ns.GetNode(typeof(ShortNameFooA).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), typeof(ShortNameFooA).AssemblyQualifiedName); + } + + public void TestConflictingShortNames() + { + string msg = null; + try + { + var nodeA = ns.GetNode(typeof(ShortNameFooA).AssemblyQualifiedName); + var nodeB = ns.GetNode(typeof(ShortNameFooB).AssemblyQualifiedName); + msg = + "ShortNameFooA and ShortNameFooB have the same short name" + + nodeA.GetName() + nodeB.GetName(); + } + catch (Exception e) + { + Console.WriteLine(e); + } + Assert.IsNull(msg, msg); + } + + [TestMethod] + public void TestRoundTripInnerClassNames() + { + INode node = ns.GetNode(typeof(Nested.Inner).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), typeof(Nested.Inner).AssemblyQualifiedName); + } + + [TestMethod] + public void TestRoundTripAnonInnerClassNames() + { + INode node1 = ns.GetNode(typeof(AnonNested.X1).AssemblyQualifiedName); + INode node2 = ns.GetNode(typeof(AnonNested.Y1).AssemblyQualifiedName); + Assert.AreNotEqual(node1.GetFullName(), node2.GetFullName()); + + Type t1 = ReflectionUtilities.GetTypeByName(node1.GetFullName()); + Type t2 = ReflectionUtilities.GetTypeByName(node2.GetFullName()); + + Assert.AreNotSame(t1, t2); + } + + [TestMethod] + public void TestNameCantBindWrongSubclassAsDefault() + { + TestNegativeCase(typeof(BadName), + "class org.apache.reef.tang.implementation.BadName defines a default class Int32 with a type that does not extend of its target's type string"); + } + + + [TestMethod] + public void TestNameCantBindWrongSubclassOfArgumentAsDefault() + { + TestNegativeCase(typeof(BadNameForGeneric), + "class BadNameForGeneric defines a default class Int32 with a type that does not extend of its target's string in ISet<string>"); + } + + [TestMethod] + public void TestNameCantBindSubclassOfArgumentAsDefault() + { + ns = TangFactory.GetTang().GetClassHierarchy(new string[] { FileNames.Examples, FileNames.Common, FileNames.Tasks }); + INode node = ns.GetNode(typeof(GoodNameForGeneric).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), typeof(GoodNameForGeneric).AssemblyQualifiedName); + } + + [TestMethod] + public void TestInterfaceCantBindWrongImplAsDefault() + { + TestNegativeCase(typeof(IBadIfaceDefault), + "interface IBadIfaceDefault declares its default implementation to be non-subclass class string"); + } + + private void TestNegativeCase(Type clazz, string message) + { + string msg = null; + try + { + var node = ns.GetNode(typeof(IBadIfaceDefault).AssemblyQualifiedName); + msg = message + node.GetName(); + } + catch (Exception) + { + } + Assert.IsNull(msg, msg); + } + + [TestMethod] + public void TestParseableDefaultClassNotOK() + { + TestNegativeCase(typeof(BadParsableDefaultClass), + "Named parameter BadParsableDefaultClass defines default implementation for parsable type System.string"); + } + + [TestMethod] + public void testGenericTorture1() + { + g(typeof(GenericTorture1)); + } + [TestMethod] + public void testGenericTorture2() + { + g(typeof(GenericTorture2)); + } + [TestMethod] + public void testGenericTorture3() + { + g(typeof(GenericTorture3)); + } + [TestMethod] + public void testGenericTorture4() + { + g(typeof(GenericTorture4)); + } + + public string s(Type t) + { + return ReflectionUtilities.GetAssemblyQualifiedName(t); + } + public INode g(Type t) + { + INode n = ns.GetNode(s(t)); + Assert.IsNotNull(n); + return n; + } + + [TestMethod] + public void TestHelloTaskNode() + { + var node = ns.GetNode(typeof(Org.Apache.REEF.Tasks.HelloTask).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), ReflectionUtilities.GetAssemblyQualifiedName(typeof(Org.Apache.REEF.Tasks.HelloTask))); + } + + [TestMethod] + public void TestITackNode() + { + var node = ns.GetNode(typeof(Org.Apache.REEF.Tasks.ITask).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), ReflectionUtilities.GetAssemblyQualifiedName(typeof(Org.Apache.REEF.Tasks.ITask))); + } + + [TestMethod] + public void TestNamedParameterIdentifier() + { + var node = ns.GetNode(typeof(Org.Apache.REEF.Tasks.TaskConfigurationOptions.Identifier).AssemblyQualifiedName); + Assert.AreEqual(node.GetFullName(), ReflectionUtilities.GetAssemblyQualifiedName(typeof(Org.Apache.REEF.Tasks.TaskConfigurationOptions.Identifier))); + } + [TestMethod] + public void TestInterface() + { + g(typeof(A)); + g(typeof(MyInterface<int>)); + g(typeof(MyInterface<string>)); + g(typeof(B)); + + ITang tang = TangFactory.GetTang(); + ICsConfigurationBuilder cb = tang.NewConfigurationBuilder(); + + cb.BindImplementation(GenericType<MyInterface<string>>.Class, GenericType<MyImplString>.Class); + cb.BindImplementation(GenericType<MyInterface<int>>.Class, GenericType<MyImplInt>.Class); + IConfiguration conf = cb.Build(); + IInjector i = tang.NewInjector(conf); + + var a = (A)i.GetInstance(typeof(A)); + var implString = (MyImplString)i.GetInstance(typeof(MyImplString)); + var implInt = (MyImplString)i.GetInstance(typeof(MyImplString)); + var b = (B)i.GetInstance(typeof(B)); + var c = (C)i.GetInstance(typeof(C)); + + Assert.IsNotNull(a); + Assert.IsNotNull(implString); + Assert.IsNotNull(implInt); + Assert.IsNotNull(b); + Assert.IsNotNull(c); + } + } + + [NamedParameter] + class GenericTorture1 : Name<ISet<string>> { + } + [NamedParameter] + class GenericTorture2 : Name<ISet<ISet<string>>> + { + } + [NamedParameter] + class GenericTorture3 : Name<IDictionary<ISet<string>, ISet<string>>> + { + } + [NamedParameter] + class GenericTorture4 : Name<IDictionary<string, string>> + { + } + + public interface MyInterface<T> + { + + } + + public class RepeatConstructorArg + { + [Inject] + public RepeatConstructorArg(int x, int y) + { + } + } + + public class RepeatConstructorArgClasses + { + [Inject] + public RepeatConstructorArgClasses(A x, A y) + { + } + } + + public class A : MyInterface<int>, MyInterface<string> + { + [Inject] + A() + { + } + } + + public class MyImplString : MyInterface<string> + { + [Inject] + public MyImplString() + { + } + } + + public class B + { + [Inject] + public B(MyInterface<string> b) + { + } + } + + public class MyImplInt : MyInterface<int> + { + [Inject] + public MyImplInt() + { + } + } + public class C + { + [Inject] + public C(MyInterface<int> b) + { + } + } + public class LeafRepeatedConstructorArgClasses + { + + public static class A + { + public class AA + { + } + } + + public static class B + { + public class AA + { + } + } + + public class C + { + [Inject] + public C(A.AA a, B.AA b) + { + } + } + } + + class D + { + } + [NamedParameter] + class D1 : Name<D> + { + } + + [NamedParameter] + class D2 : Name<D> + { + } + + class NamedRepeatConstructorArgClasses + { + [Inject] + public NamedRepeatConstructorArgClasses([Parameter(typeof(D1))] D x, [Parameter(typeof(D2))] D y) + { + } + } + + class NamedParameterTypeMismatch + { + [NamedParameter(Documentation = "doc.stuff", DefaultValue = "1")] + class Foo : Name<Int32> + { + } + + [Inject] + public NamedParameterTypeMismatch([Parameter(Value = typeof(Foo))] string s) + { + } + } + + class UnannotatedName : Name<string> { + } + + interface I1 + { + } + + [NamedParameter(Documentation = "c")] + class AnnotatedNotName + { + } + + [NamedParameter(Documentation = "c")] + class AnnotatedNameWrongInterface : I1 + { + } + + class UnAnnotatedNameMultipleInterfaces : Name<object>, I1 + { + } + + [NamedParameter(Documentation = "c")] + class AnnotatedNameMultipleInterfaces : Name<object>, I1 + { + } + + [NamedParameter(Documentation = "c")] + class NameWithConstructor : Name<object> + { + private NameWithConstructor(int i) + { + } + } + + [NamedParameter] + class NameWithZeroArgInject : Name<object> + { + [Inject] + public NameWithZeroArgInject() + { + } + } + + class InjectNonStaticLocalArgClass + { + class NonStaticLocal + { + } + + [Inject] + InjectNonStaticLocalArgClass(NonStaticLocal x) + { + } + } + + class InjectNonStaticLocalType + { + class NonStaticLocal + { + [Inject] + NonStaticLocal(NonStaticLocal x) + { + } + } + } + + [NamedParameter(ShortName = "foo")] + public class ShortNameFooA : Name<String> + { + } + + //when same short name is used, exception would throw when building the class hierarchy + [NamedParameter(ShortName = "foo")] + public class ShortNameFooB : Name<Int32> + { + } + + class Nested + { + public class Inner + { + } + } + + class AnonNested + { + public interface X + { + } + + public class X1 : X + { + //int i; + } + + public class Y1 : X + { + //int j; + } + + public static X XObj = new X1(); + public static X YObj = new Y1(); + } + + //Negative case: Int32 doesn't match string + [NamedParameter(DefaultClass = typeof(Int32))] + class BadName : Name<string> + { + } + + //Negative case: Int32 doesn't match string in the ISet + [NamedParameter(DefaultClass = typeof(Int32))] + class BadNameForGeneric : Name<ISet<string>> + { + } + + //Positive case: type matched. ISet is not in parsable list + [NamedParameter(DefaultClass = typeof(string))] + class GoodNameForGeneric : Name<ISet<string>> + { + } + + [DefaultImplementation(typeof(string))] + interface IBadIfaceDefault + { + } + + //negative case: type matched. However, string is in the parsable list and DefaultClass is not null. + [NamedParameter(DefaultClass = typeof(string))] + class BadParsableDefaultClass : Name<string> + { + } + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestClassHierarchyRoundTrip.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestClassHierarchyRoundTrip.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestClassHierarchyRoundTrip.cs new file mode 100644 index 0000000..a2dd2fc --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestClassHierarchyRoundTrip.cs @@ -0,0 +1,70 @@ +/** + * 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. + */ + +using System.Globalization; +using System.IO; +using Org.Apache.REEF.Tang.Implementations; +using Org.Apache.REEF.Tang.Protobuf; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.REEF.Tang.Examples; +using Org.Apache.REEF.Tang.Implementations.Tang; + +namespace Org.Apache.REEF.Tang.Tests.ClassHierarchy +{ + [TestClass] + public class TestClassHierarchyRoundTrip : TestClassHierarchy + { + private void setup1() + { + TangImpl.Reset(); + ns = TangFactory.GetTang().GetClassHierarchy(new string[] { FileNames.Examples, FileNames.Common, FileNames.Tasks }); + } + + private void setup2() + { + TangImpl.Reset(); + ns = new ProtocolBufferClassHierarchy(ProtocolBufferClassHierarchy.Serialize(ns)); + } + + private void setup3() + { + TangImpl.Reset(); + try + { + ProtocolBufferClassHierarchy.Serialize("testProto.bin", ns); + ns = ProtocolBufferClassHierarchy.DeSerialize("testProto.bin"); + } + catch (IOException e) + { + Assert.Fail(string.Format(CultureInfo.CurrentCulture, "IOException when serialize/deserialize proto buffer file", e)); + } + } + + //[TestMethod] + //public new void TestString() + //{ + // setup1(); + // base.TestSimpleConstructors(); + // setup2(); + // base.TestSimpleConstructors(); + // setup3(); + // base.TestSimpleConstructors(); + //} + } +} http://git-wip-us.apache.org/repos/asf/incubator-reef/blob/c1b5200f/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestGeneric.cs ---------------------------------------------------------------------- diff --git a/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestGeneric.cs b/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestGeneric.cs new file mode 100644 index 0000000..23cc28b --- /dev/null +++ b/lang/cs/Org.Apache.REEF.Tang.Tests/ClassHierarchy/TestGeneric.cs @@ -0,0 +1,47 @@ +/** + * 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. + */ + +using System.Collections.Generic; +using Org.Apache.REEF.Tang.Examples; +using Org.Apache.REEF.Tang.Implementations; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using Org.Apache.REEF.Wake.RX; +using Org.Apache.REEF.Tang.Implementations.Tang; + +namespace Org.Apache.REEF.Tang.Tests.ClassHierarchy +{ + [TestClass] + public class TestGeneric + { + [ClassInitialize] + public static void ClassSetup(TestContext context) + { + TangImpl.Reset(); + } + + [TestMethod] + public void TestGenericClassWithT() + { + List<string> appDlls = new List<string>(); + appDlls.Add(typeof(GenericArgument<>).Assembly.GetName().Name); + appDlls.Add(typeof(AbstractObserver<>).Assembly.GetName().Name); + TangFactory.GetTang().GetClassHierarchy(appDlls.ToArray()); + } + } +} \ No newline at end of file
