private static double GetValue(ValueRequirement req)
        {
            if (req.TargetSpecification.Type != ComputationTargetType.Primitive)
                throw new NotImplementedException();

            using (var remoteClient = Context.CreateFinancialClient())
            {
                var viewDefinition = new ViewDefinition(TestUtils.GetUniqueName());

                var viewCalculationConfiguration = new ViewCalculationConfiguration("Default", new List<ValueRequirement> { req }, new Dictionary<string, HashSet<Tuple<string, ValueProperties>>>());
                viewDefinition.CalculationConfigurationsByName.Add("Default", viewCalculationConfiguration);
                var uid = remoteClient.ViewDefinitionRepository.AddViewDefinition(new AddViewDefinitionRequest(viewDefinition));
                viewDefinition.UniqueID = uid;
                try
                {
                    using (var viewClient = Context.ViewProcessor.CreateClient())
                    {
                        var viewComputationResultModel = viewClient.GetResults(viewDefinition.UniqueID, ExecutionOptions.SingleCycle).First();
                        return (double)viewComputationResultModel["Default", req].Value;
                    }
                }
                finally
                {
                    remoteClient.ViewDefinitionRepository.RemoveViewDefinition(viewDefinition.Name);
                }
            }
        }
        public void CanGetAllKindsOfValues(ViewDefinition defn)
        {
            WithViewCycle(
            delegate(ViewDefinitionCompiledArgs compiled, IViewCycle cycle, RemoteViewClient client)
            {
                var compiledViewDefinition = cycle.GetCompiledViewDefinition();
                foreach (var kvp in compiledViewDefinition.ViewDefinition.CalculationConfigurationsByName)
                {
                    var viewCalculationConfiguration = kvp.Key;

                    var dependencyGraphExplorer =
                        compiledViewDefinition.GetDependencyGraphExplorer(viewCalculationConfiguration);
                    Assert.NotNull(dependencyGraphExplorer);
                    var wholeGraph = dependencyGraphExplorer.GetWholeGraph();

                    var distinctKindsOfSpec = wholeGraph.DependencyNodes.SelectMany(n => n.OutputValues)
                        .ToLookup(s => s.ValueName).Select(g => g.First());
                    var specs = new HashSet<ValueSpecification>(distinctKindsOfSpec);

                    if (! specs.Any())
                    {
                        continue;
                    }
                    var computationCacheResponse = cycle.QueryComputationCaches(new ComputationCacheQuery(viewCalculationConfiguration, specs));
                    Assert.InRange(computationCacheResponse.Results.Count, 0, specs.Count());
                    foreach (var result in computationCacheResponse.Results)
                    {
                        Assert.Contains(result.First, specs);
                        Assert.NotNull(result.Second);
                        ValueAssertions.AssertSensibleValue(result.Second);
                    }
                }
            }, defn.Name);
        }
 public ViewDefinition CreateViewDefinition(RemoteEngineContext context, ValueRequirement valueRequirement)
 {
     var viewDefinition = new ViewDefinition(TestUtils.GetUniqueName());
     viewDefinition.CalculationConfigurationsByName.Add("Default", new ViewCalculationConfiguration("Default", new List<ValueRequirement> { valueRequirement }, new Dictionary<string, HashSet<Tuple<string, ValueProperties>>>()));
     using (var remoteClient = context.CreateFinancialClient())
     {
         var uid = remoteClient.ViewDefinitionRepository.AddViewDefinition(new AddViewDefinitionRequest(viewDefinition));
         viewDefinition.UniqueID = uid;
     }
     _createdViews.Enqueue(Tuple.Create(context, viewDefinition.Name));
     return viewDefinition;
 }
 public void CanAttach(ViewDefinition vd)
 {
     using (var remoteViewClient = Context.ViewProcessor.CreateClient())
     {
         Assert.False(remoteViewClient.IsAttached);
         remoteViewClient.AttachToViewProcess(vd.UniqueID, ExecutionOptions.RealTime);
         Assert.True(remoteViewClient.IsAttached);
         remoteViewClient.DetachFromViewProcess();
         Assert.False(remoteViewClient.IsAttached);
     }
     Thread.Sleep(TimeSpan.FromSeconds(10)); //[PLAT-1904] Try and wait for the compile to finish
 }
        public void CanGetOutputs(ViewDefinition defn)
        {
            UniqueId portfolio = defn.PortfolioIdentifier;
            if (portfolio == null)
            {
                return;
            }
            var remoteAvailableOutputs = Context.RemoteAvailableOutputs;
            remoteAvailableOutputs.MaxNodes = 2;
            remoteAvailableOutputs.MaxPositions = 2;
            var availableOutputs = remoteAvailableOutputs.GetPortfolioOutputs(portfolio);
            Assert.NotNull(availableOutputs);
            foreach (var securityType in availableOutputs.SecurityTypes)
            {
                ICollection<AvailableOutput> positionOutputs = availableOutputs.GetPositionOutputs(securityType);
                Assert.NotEmpty(positionOutputs);
                foreach (var availableOutput in positionOutputs)
                {
                    Assert.Null(availableOutput.PortfolioNodeProperties);
                    Assert.True(new[] {securityType}.SequenceEqual(availableOutput.PositionProperties.Keys));
                    ValueProperties positionProperty = availableOutput.PositionProperties[securityType];
                    Assert.NotNull(positionProperty);
                    Assert.NotNull(positionProperty.GetValues("Function"));
                }
            }

            ICollection<AvailableOutput> portfolioNodeOutputs = availableOutputs.GetPortfolioNodeOutputs();
            Assert.NotNull(portfolioNodeOutputs);
            foreach (var availableOutput in portfolioNodeOutputs)
            {
                Assert.Empty(availableOutput.PositionProperties);
                ValueProperties properties = availableOutput.PortfolioNodeProperties;
                Assert.NotNull(properties);
                Assert.NotNull(properties.GetValues("Function"));
            }
        }
 public void CanGetIsLiveComputationRunning(ViewDefinition definition)
 {
     using (var remoteViewClient = Context.ViewProcessor.CreateClient())
     {
         Assert.Equal(ViewClientState.Started, remoteViewClient.GetState());
         remoteViewClient.Pause();
         Assert.Equal(ViewClientState.Paused, remoteViewClient.GetState());
         remoteViewClient.Resume();
         Assert.Equal(ViewClientState.Started, remoteViewClient.GetState());
     }
 }
        public void CanGetCompilationResults(ViewDefinition definition)
        {
            using (var remoteViewClient = Context.ViewProcessor.CreateClient())
            {
                var compilationResult = new BlockingCollection<object>();

                var eventViewResultListener = new EventViewResultListener();
                eventViewResultListener.ViewDefinitionCompiled +=
                    (sender, e) => compilationResult.Add(e.CompiledViewDefinition);
                eventViewResultListener.ViewDefinitionCompilationFailed +=
                    (sender, e) => compilationResult.Add(e.Exception);

                remoteViewClient.SetResultListener(eventViewResultListener);
                remoteViewClient.AttachToViewProcess(definition.UniqueID, ExecutionOptions.GetCompileOnly());

                var result = compilationResult.Take();
                Assert.IsNotType(typeof(Exception), result);
                Debug.WriteLine(definition.UniqueID);
                Assert.IsAssignableFrom(typeof(ICompiledViewDefinition), result);

                var viewDefin = (ICompiledViewDefinition)result;
                ValueAssertions.AssertSensibleValue(viewDefin);
            }
        }
 public MarketDataSnapshotProcessor CreateFromViewDefinition(ViewDefinition definition, CancellationToken ct = default(CancellationToken))
 {
     return MarketDataSnapshotProcessor.Create(_remoteEngineContext, definition, ct);
 }
        public void CanGetUSDVolatilityCube(string currencyName)
        {
            const string cubeName = "BLOOMBERG";
            var valueProperties = ValueProperties.Create(new Dictionary<string, ISet<string>> { { "Cube", new HashSet<string> { cubeName } } }, new HashSet<string>());

            var viewCalculationConfiguration = new ViewCalculationConfiguration("Default",
                new[]
                    {
                        new ValueRequirement("VolatilityCubeMarketData", new ComputationTargetSpecification(ComputationTargetType.Primitive, Currency.Create(currencyName).UniqueId), valueProperties)
                    }, new Dictionary<string, HashSet<Tuple<string, ValueProperties>>>());

            var vdName = string.Join("-", TestUtils.GetUniqueName(), cubeName, currencyName);

            var defn = new ViewDefinition(vdName, new ResultModelDefinition(ResultOutputMode.TerminalOutputs),
                               calculationConfigurationsByName:
                                   new Dictionary<string, ViewCalculationConfiguration> {{"Default", viewCalculationConfiguration}}, maxFullCalcPeriod:TimeSpan.FromSeconds(1));
            using (var remoteClient = Context.CreateFinancialClient())
            {
                var uid = remoteClient.ViewDefinitionRepository.AddViewDefinition(new AddViewDefinitionRequest(defn));
                defn.UniqueID = uid;
                try
                {
                    using (var remoteViewClient = Context.ViewProcessor.CreateClient())
                    {
                        var viewComputationResultModels = remoteViewClient.GetResults(defn.UniqueID, new ExecutionOptions(new InfiniteViewCycleExecutionSequence(), ViewExecutionFlags.AwaitMarketData | ViewExecutionFlags.TriggersEnabled, null, new ViewCycleExecutionOptions(default(DateTimeOffset), new LiveMarketDataSpecification())));
                        int i = 0;

                        foreach (var viewComputationResultModel in viewComputationResultModels)
                        {
                            if (viewComputationResultModel.AllLiveData.Any())
                            {
                                var liveDataCount = viewComputationResultModel.AllLiveData.Count();
                                if (liveDataCount > 10 && liveDataCount == i)
                                {
                                    var volatilityCubeData = (VolatilityCubeData) viewComputationResultModel.AllResults.Single().ComputedValue.Value;
                                    Assert.InRange(volatilityCubeData.DataPoints.Count, 1, int.MaxValue);
                                    Assert.InRange(volatilityCubeData.Strikes.Count, 1, int.MaxValue);
                                    Assert.Empty(volatilityCubeData.OtherData.DataPoints);

                                    var actual = volatilityCubeData.DataPoints.Count + volatilityCubeData.OtherData.DataPoints.Count + volatilityCubeData.Strikes.Count;
                                    Assert.InRange(actual, liveDataCount * 0.5, liveDataCount); //Allow 50% for PLAT-1383

                                    var pays = volatilityCubeData.DataPoints.Where(k => k.Key.RelativeStrike < 0);
                                    var recvs = volatilityCubeData.DataPoints.Where(k => k.Key.RelativeStrike > 0);
                                    Assert.NotEmpty(pays);
                                    Assert.NotEmpty(volatilityCubeData.DataPoints.Where(k => k.Key.RelativeStrike == 0));
                                    Assert.NotEmpty(recvs);

                                    foreach (var dataPoint in volatilityCubeData.DataPoints.Keys)
                                    {
                                        var strike = volatilityCubeData.Strikes[GetStrikeKey(dataPoint)];
                                        Assert.True(strike > 0.0);
                                    }
                                    break;
                                }
                                i = liveDataCount;
                            }
                        }
                    }
                }
                finally
                {
                    remoteClient.ViewDefinitionRepository.RemoveViewDefinition(defn.Name);
                }
            }
        }
 private static void SetTemporaryName(ViewDefinition viewDefinition)
 {
     viewDefinition.Name = string.Format("{0}-RoundTripped-{1}", viewDefinition.Name, TestUtils.GetUniqueName());
     viewDefinition.UniqueID = null;
 }
        public void CanCreateFromView(ViewDefinition viewDefinition)
        {
            var snapshotManager = Context.MarketDataSnapshotManager;
            using (var proc = snapshotManager.CreateFromViewDefinition(viewDefinition))
            {
                var manageableMarketDataSnapshot = proc.Snapshot;
                Assert.Null(manageableMarketDataSnapshot.Name);
                Assert.Null(manageableMarketDataSnapshot.UniqueId);

                Assert.True(manageableMarketDataSnapshot.Values.Any() || manageableMarketDataSnapshot.YieldCurves.Any(c => c.Value.Values.Values.Any()) || manageableMarketDataSnapshot.VolatilityCubes.Any(v => v.Value.Values.Any()));
                foreach (var valueSnapshot in manageableMarketDataSnapshot.Values)
                {
                    foreach (var snapshot in valueSnapshot.Value)
                    {
                        ValueAssertions.AssertSensibleValue(snapshot.Value.MarketValue);
                        Assert.Null(snapshot.Value.OverrideValue);
                    }
                }

                if (viewDefinition.Name != "GlobeOp Bond View Implied" /* LAP-38 */ && viewDefinition.Name != "Simple Cash Test View 2" /* LAP-82 */)
                {
                    Assert.InRange(manageableMarketDataSnapshot.YieldCurves.Count, ExpectedYieldCurves(viewDefinition), int.MaxValue);
                }
                if (viewDefinition.Name == "Equity Option Test View 1")
                {
                    Assert.Equal(2, manageableMarketDataSnapshot.YieldCurves.Count);
                    var yieldCurveSnapshot = manageableMarketDataSnapshot.YieldCurves.First();
                    Assert.NotNull(yieldCurveSnapshot);
                    Assert.NotEmpty(yieldCurveSnapshot.Value.Values.Values);
                }
                foreach (var curve in manageableMarketDataSnapshot.YieldCurves.Values)
                {
                    AssertSaneValue(curve);
                    Assert.True(curve.Values.Values.Keys.Any(s => ! manageableMarketDataSnapshot.GlobalValues.Values.ContainsKey(s))); //LAP-37
                }
                foreach (var cube in manageableMarketDataSnapshot.VolatilityCubes.Values)
                {
                    Assert.True(cube.Values.Any(v => v.Value.MarketValue == null));
                }
            }
        }
Exemple #12
0
 public UpdateViewDefinitionRequest(string name, ViewDefinition viewDefinition)
 {
     _name = name;
     _viewDefinition = viewDefinition;
 }
        public void ViewResultsHaveSaneValues(ViewDefinition definition)
        {
            var viewComputationResultModel = GetOneResultCache.Get(definition.UniqueID);

            foreach (var viewResultEntry in viewComputationResultModel.AllResults)
            {
                ValueAssertions.AssertSensibleValue(viewResultEntry.ComputedValue.Value);
            }
        }
        public void NumberOfResultsIsConsistent(ViewDefinition viewDefinition)
        {
            using (var remoteViewClient = Context.ViewProcessor.CreateClient())
            {
                var options = new ExecutionOptions(new InfiniteViewCycleExecutionSequence(), ViewExecutionFlags.TriggersEnabled | ViewExecutionFlags.AwaitMarketData, defaultExecutionOptions:new ViewCycleExecutionOptions(default(DateTimeOffset), new LiveMarketDataSpecification()));
                var resultsEnum = remoteViewClient.GetResults(viewDefinition.UniqueID, options);

                var results = resultsEnum.Take(3).ToList();
                AssertNumberOfResultsIsConsistentOnRecompile(results);
            }
        }
        public void UberView()
        {
            var defn = Context.ViewProcessor.ViewDefinitionRepository.GetViewDefinition("Mixed Instrument VaR View");
            UniqueId portfolio = defn.PortfolioIdentifier;

            var remoteAvailableOutputs = Context.RemoteAvailableOutputs;
            remoteAvailableOutputs.MaxNodes = 2;
            remoteAvailableOutputs.MaxPositions = 2;

            var availableOutputs = remoteAvailableOutputs.GetPortfolioOutputs(portfolio);

            Assert.NotNull(availableOutputs);

            var valueNames = availableOutputs.SecurityTypes.ToDictionary(s => s, s => availableOutputs.GetPositionOutputs(s).Select(a => a.ValueName));
            foreach (var securityType in availableOutputs.SecurityTypes)
            {
                ICollection<AvailableOutput> positionOutputs = availableOutputs.GetPositionOutputs(securityType);
                foreach (var availableOutput in positionOutputs)
                {
                    Assert.Null(availableOutput.PortfolioNodeProperties);
                    Assert.True(new[] { securityType }.SequenceEqual(availableOutput.PositionProperties.Keys));
                    ValueProperties positionProperty = availableOutput.PositionProperties[securityType];
                    Assert.NotNull(positionProperty);
                    Assert.NotNull(positionProperty.GetValues("Function"));
                }
            }

            var viewCalculationConfiguration = GetDefaultCalculations(valueNames);
            var newDefn = new ViewDefinition(TestUtils.GetUniqueName(), portfolioIdentifier: portfolio, defaultCurrency: defn.DefaultCurrency, calculationConfigurationsByName: new Dictionary<string, ViewCalculationConfiguration> { { "Default", viewCalculationConfiguration } });

            using (var remoteClient = Context.CreateFinancialClient())
            {
                remoteClient.ViewDefinitionRepository.AddViewDefinition(new AddViewDefinitionRequest(newDefn));
                RemoteViewCycleTests.WithViewCycle(delegate(ViewDefinitionCompiledArgs comp, IViewCycle cycle, RemoteViewClient client)
                {
                    var allLiveData = cycle.GetResultModel().AllLiveData;
                    var dependencyGraphExplorer = cycle.GetCompiledViewDefinition().GetDependencyGraphExplorer("Default");
                    var dependencyGraph = dependencyGraphExplorer.GetWholeGraph();
                    var dependencyNodes = dependencyGraph.DependencyNodes;
                    var valueSpecifications = dependencyNodes.SelectMany(n => n.OutputValues).ToLookup(s => s).Select(g => g.Key).ToList();
                    Assert.NotEmpty(valueSpecifications);
                    var first = cycle.QueryComputationCaches(new ComputationCacheQuery("Default", valueSpecifications));
                    Assert.InRange(allLiveData.Count(), 1, valueSpecifications.Count);
                    Assert.InRange(first.Results.Count, allLiveData.Count() + 1, valueSpecifications.Count);
                }, defn.Name);
            }
        }
 private static int ExpectedYieldCurves(ViewDefinition viewDefinition)
 {
     var yieldCurvesPerConfiguration = viewDefinition.CalculationConfigurationsByName.Select(
         c => c.Value.SpecificRequirements.Where(r => r.ValueName.Contains("YieldCurve") && r.ValueName != ValueRequirementNames.YieldCurveJacobian).Count());
     return
         yieldCurvesPerConfiguration.Distinct().Max();
 }
        public void NumberOfResultsIsConsistent(ViewDefinition defn)
        {
            const int cyclesCount = 5;

            using (var remoteViewClient = Context.ViewProcessor.CreateClient())
            using (var mre = new ManualResetEvent(false))
            {
                var cycles = new BlockingCollection<IEngineResourceReference<IViewCycle>>();

                var listener = new EventViewResultListener();
                listener.ProcessCompleted += delegate { mre.Set(); };
                listener.ViewDefinitionCompilationFailed += delegate { mre.Set(); };
                listener.CycleExecutionFailed += delegate { mre.Set(); };

                listener.CycleCompleted += (sender, e) =>
                                               {
                                                   cycles.Add(remoteViewClient.CreateCycleReference(e.FullResult.ViewCycleId));
                                                   remoteViewClient.TriggerCycle();
                                               };

                remoteViewClient.SetResultListener(listener);
                remoteViewClient.SetViewCycleAccessSupported(true);

                var sequence = ArbitraryViewCycleExecutionSequence.Create(Enumerable.Range(0, cyclesCount).Select(i => DateTimeOffset.Now + TimeSpan.FromHours(i)));
                var options = new ExecutionOptions(sequence, ViewExecutionFlags.TriggersEnabled | ViewExecutionFlags.AwaitMarketData, null, new ViewCycleExecutionOptions(default(DateTimeOffset), ExecutionOptions.GetDefaultMarketDataSpec()));

                remoteViewClient.AttachToViewProcess(defn.UniqueID, options);

                TimeSpan timeout = TimeSpan.FromMinutes(5);
                if (! mre.WaitOne(timeout))
                {
                    throw new TimeoutException(string.Format("Failed to get result in {0}", timeout));
                }
                Assert.Equal(cyclesCount, cycles.Count);

                var specs = cycles.Select(GetAllSpecs).ToList();

                var inconsistent = specs.Zip(specs.Skip(1), Tuple.Create).SelectMany(
                    t =>
                        {
                            var diff = new HashSet<Tuple<string, ValueSpecification>>(t.Item1);
                            diff.SymmetricExceptWith(t.Item2);
                            return diff;
                        }).Distinct();
                if (inconsistent.Any())
                {
                    var counts = string.Join(",", specs.Select(c => c.Count.ToString()));
                    var inconsistentStrings = specs.Select(s => string.Join(",", s.Where(x => inconsistent.Contains(x)).Select(x => x.ToString())));
                    string inconsistentString = string.Join(Environment.NewLine, inconsistentStrings);
                    throw new Exception(string.Format("Inconsistent number of results for {0} {1}: {2}", defn.Name, counts, inconsistentString));
                }
            }
        }
        public void CanGetAllTerminalValues(ViewDefinition defn)
        {
            WithViewCycle(
            delegate(ViewDefinitionCompiledArgs compiled, IViewCycle cycle, RemoteViewClient client)
            {
                var compiledViewDefinition = cycle.GetCompiledViewDefinition();
                var viewComputationResultModel = cycle.GetResultModel();
                foreach (var kvp in compiledViewDefinition.ViewDefinition.CalculationConfigurationsByName)
                {
                    var viewCalculationConfiguration = kvp.Key;
                    var results = viewComputationResultModel.AllResults.Where(r => r.CalculationConfiguration == viewCalculationConfiguration).ToDictionary(r => r.ComputedValue.Specification, r => r.ComputedValue.Value);
                    var specs = results.Select(r => r.Key).ToList();

                    var computationCacheResponse = cycle.QueryComputationCaches(new ComputationCacheQuery(viewCalculationConfiguration, specs));
                    Assert.Equal(specs.Count(), computationCacheResponse.Results.Count);
                    foreach (var result in computationCacheResponse.Results)
                    {
                        Assert.Contains(result.First, specs);
                        var expected = results[result.First];
                        Assert.Equal(expected.GetType(), result.Second.GetType());
                        if (expected is double)
                        {
                            Assert.Equal(expected, result.Second);
                        }
                    }
                }
            }, defn.Name);
        }
        public void CanGetManyResults(ViewDefinition viewDefinition)
        {
            using (var remoteViewClient = Context.ViewProcessor.CreateClient())
            {
                var options = ExecutionOptions.RealTime;
                var resultsEnum = remoteViewClient.GetResults(viewDefinition.UniqueID, options);

                var results = resultsEnum.Take(5).ToList();
                Assert.True(results.All(r => r != null));
            }
        }
        private static void AssertDefinitionContains(ViewDefinition viewDefinition, ViewResultEntry viewResultEntry)
        {
            var configuration = viewDefinition.CalculationConfigurationsByName[viewResultEntry.CalculationConfiguration];

            var valueSpecification = viewResultEntry.ComputedValue.Specification;

            foreach (var req in configuration.SpecificRequirements)
            {
                bool matches = (req.TargetSpecification.Uid ==
                                valueSpecification.TargetSpecification.Uid
                                && req.TargetSpecification.Type == valueSpecification.TargetSpecification.Type
                                && req.ValueName == valueSpecification.ValueName)
                               && req.Constraints.IsSatisfiedBy(valueSpecification.Properties);

                if (matches)
                    return;
            }

            var reqsByType = configuration.PortfolioRequirementsBySecurityType;
            if (!reqsByType.Any(r => r.Value.Any(t => t.Item1 == valueSpecification.ValueName)))
            {
                Assert.True(false,
                            string.Format("Unmatched requirement {0},{1},{2} on {3}", valueSpecification.ValueName,
                                          valueSpecification.TargetSpecification.Type,
                                          valueSpecification.TargetSpecification.Uid, viewDefinition.Name));
            }
        }
 public void CanStartAndGetAResultOrCompilationFailure(ViewDefinition definition)
 {
     try
     {
         Assert.NotNull(GetOneResultCache.Get(definition.UniqueID));
     }
     catch (Exception ex)
     {
         //Compilation failure is allowed, we will check that some views run elsewhere
         Assert.Contains("ViewDefinitionCompilationFailedArgs", ex.Message);
     }
 }
 internal static MarketDataSnapshotProcessor Create(RemoteEngineContext context, ViewDefinition definition, CancellationToken ct)
 {
     using (var liveDataStream = new LiveDataStream(definition.Name, context))
     {
         ManageableMarketDataSnapshot snapshot = liveDataStream.GetNewSnapshotForUpdate(ct);
         //NOTE: we could consider reusing the LiveDataStream, but server side will share the processer
         return new MarketDataSnapshotProcessor(context, snapshot);
     }
 }
        public void NumberOfResultsIsConsistentOnRecompile(ViewDefinition viewDefinition)
        {
            var results = new List<IViewComputationResultModel>();
            var viewProcess = new HashSet<UniqueId>();
            for (int i = 0; i < 10; i++)
            {
                using (var remoteViewClient = Context.ViewProcessor.CreateClient())
                {
                    var options = ExecutionOptions.SingleCycle;
                    var resultsEnum = remoteViewClient.GetResults(viewDefinition.UniqueID, options, true);

                    var result = resultsEnum.Take(1).ToList().Single();
                    if (!viewProcess.Add(result.ViewProcessId))
                    {
                        throw new Exception("Shared process");
                    }
                    results.Add(result);
                }
            }
            AssertNumberOfResultsIsConsistentOnRecompile(results);
        }
Exemple #24
0
 public AddViewDefinitionRequest(ViewDefinition viewDefinition)
 {
     _viewDefinition = viewDefinition;
 }
        public void ViewResultsMatchDefinition(ViewDefinition viewDefinition)
        {
            using (var remoteViewClient = Context.ViewProcessor.CreateClient())
            {
                ICompiledViewDefinition compiledViewDefinition = null;
                IViewComputationResultModel viewComputationResultModel = null;
                var resultsReady = new ManualResetEvent(false);

                var listener = new EventViewResultListener();
                listener.ViewDefinitionCompiled += delegate(object sender, ViewDefinitionCompiledArgs e)
                                                       {
                                                           compiledViewDefinition = e.CompiledViewDefinition;
                                                       };
                listener.CycleCompleted += delegate(object sender, CycleCompletedArgs e)
                                               {
                                                   viewComputationResultModel = e.FullResult;
                                                   resultsReady.Set();
                                               };
                remoteViewClient.SetResultListener(listener);

                remoteViewClient.AttachToViewProcess(viewDefinition.UniqueID, ExecutionOptions.RealTime);

                if (!resultsReady.WaitOne(TimeSpan.FromMinutes(2)))
                    throw new TimeoutException("Failed to get results for " + viewDefinition.Name + " client " + remoteViewClient.GetUniqueId());

                Assert.NotNull(compiledViewDefinition);

                foreach (var viewResultEntry in viewComputationResultModel.AllResults)
                {
                    Assert.NotNull(viewResultEntry.ComputedValue.Value);
                    AssertDefinitionContains(viewDefinition, viewResultEntry);
                }

                var countActualValues = viewComputationResultModel.AllResults.Count();

                var countMaxExpectedValues = CountMaxExpectedValues(compiledViewDefinition);

                Console.Out.WriteLine("{0} {1} {2}", viewDefinition.Name, countActualValues, countMaxExpectedValues);
                Assert.InRange(countActualValues, 1, countMaxExpectedValues);
            }
        }
        public void CanGetYieldCurveValues(ViewDefinition viewDefinition)
        {
            var snapshotManager = Context.MarketDataSnapshotManager;

            using (var dataSnapshotProcessor = snapshotManager.CreateFromViewDefinition(viewDefinition))
            {
                GetAndCheckYieldCurves(dataSnapshotProcessor);
            }
        }
        public void CanUpdateFromLiveDataStream(ViewDefinition viewDefinition)
        {
            var snapshotManager = Context.MarketDataSnapshotManager;

            using (var dataSnapshotProcessor = snapshotManager.CreateFromViewDefinition(viewDefinition))
            {
                UpdateAction<ManageableMarketDataSnapshot> prepareUpdate = dataSnapshotProcessor.PrepareUpdate();
                var before = GetCount(dataSnapshotProcessor);
                prepareUpdate.Execute(dataSnapshotProcessor.Snapshot);

                var after = GetCount(dataSnapshotProcessor);
                Assert.Equal(before, after);
            }
        }
        public void CanCreateAndRunFromView(ViewDefinition vd)
        {
            var snapshotManager = Context.MarketDataSnapshotManager;
            using (var proc = snapshotManager.CreateFromViewDefinition(vd.Name))
            {
                proc.Snapshot.Name = TestUtils.GetUniqueName();
                var uid = Context.MarketDataSnapshotMaster.Add(new MarketDataSnapshotDocument(null, proc.Snapshot)).UniqueId;

                try
                {
                    var snapOptions = ExecutionOptions.Snapshot(proc.Snapshot.UniqueId);
                    var withSnapshot = GetFirstResult(snapOptions, vd.Name);

                    var options = ExecutionOptions.SingleCycle;
                    IViewComputationResultModel withoutSnapshot = GetFirstResult(options, vd.Name);

                    var withoutCount = CountResults(withoutSnapshot);
                    var withCount = CountResults(withSnapshot);
                    if (withoutCount != withCount)
                    {
                        var withSpecs = new HashSet<ValueSpecification>(withSnapshot.AllResults.Select(r => r.ComputedValue.Specification));
                        var withoutSpecs = new HashSet<ValueSpecification>(withoutSnapshot.AllResults.Select(r => r.ComputedValue.Specification));
                        withoutSpecs.SymmetricExceptWith(withSpecs);
                        Assert.True(false, string.Format("Running snapshot of {0} only had {1}, live had {2}", vd.Name, withCount, withoutCount));
                    }

                    Assert.Equal(withoutCount, withCount);
                }
                finally
                {
                    Context.MarketDataSnapshotMaster.Remove(uid);
                }
            }
        }