Ejemplo n.º 1
0
        public void Test_CellPass_BinaryReadWrite()
        {
            CellPass     cp1 = ATestCellPass();
            MemoryStream ms  = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION);
            BinaryWriter bw  = new BinaryWriter(ms, Encoding.UTF8, true);

            cp1.Write(bw);

            ms.Position = 0;
            BinaryReader br  = new BinaryReader(ms, Encoding.UTF8, true);
            CellPass     cp2 = new CellPass();

            cp2.Read(br);

            Assert.True(cp1.Equals(cp2), "Equality check on same cell passes failed after write then read (returned true)");

            // Check negative condition by writing and reading a second different cell pass then comparing the results of reading the two cell passes
            // to ensure they are different

            cp2 = ATestCellPass2();
            MemoryStream ms2 = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION);
            BinaryWriter bw2 = new BinaryWriter(ms2, Encoding.UTF8, true);

            cp2.Write(bw2);

            ms2.Position = 0;
            BinaryReader br2 = new BinaryReader(ms2, Encoding.UTF8, true);

            cp2.Read(br2);

            Assert.False(cp1.Equals(cp2), "Equality check on different cell passes failed after write then read (returned true)");
        }
Ejemplo n.º 2
0
        public void Test_CellPass_AssignCellPasses()
        {
            CellPass cp1 = ATestCellPass();
            CellPass cp2 = ATestCellPass2();

            Assert.False(cp1.Equals(cp2), "Equality check on different cell passes failed (returned true)");

            cp1.Assign(cp2);
            Assert.True(cp1.Equals(cp2), "Equality check on assigned cell passes failed (returned false)");
        }
Ejemplo n.º 3
0
        public void Test_ServerSubGridTreeLeaf_ComputeLatestPassInformation()
        {
            var leaf = CreateADefaultEmptyLeaf();

            Assert.True(leaf.Directory.GlobalLatestCells != null &&
                        leaf.Directory.GlobalLatestCells.PassDataExistenceMap != null,
                        "Pass data existence map is not instantiated");

            Assert.False(leaf.CellHasValue(0, 0), "Cell already has a value");

            // Add three passes them compute the latest pass information and ensure it matches with the cell passes
            CellPass pass = CreateTestCellPass();

            leaf.AddPass(0, 0, pass);

            pass.Time = pass.Time.AddMinutes(1);
            leaf.AddPass(0, 0, pass);

            pass.Time = pass.Time.AddMinutes(1);
            leaf.AddPass(0, 0, pass);

            leaf.ComputeLatestPassInformation(true, StorageProxy.Instance(StorageMutability.Mutable));

            Assert.True(leaf.CellHasValue(0, 0), "Cell does not have value");

            CellPass latestPass = leaf.Directory.GlobalLatestCells[0, 0];

            Assert.True(latestPass.Equals(pass), "Latest cell pass does not match pass");
        }
Ejemplo n.º 4
0
        public void Test_ServerSubGridTreeLeaf_AddPass()
        {
            var leaf = CreateADefaultEmptyLeaf();

            Assert.True(leaf.Cells != null &&
                        leaf.Directory.SegmentDirectory.First().Segment != null &&
                        leaf.Directory.SegmentDirectory.First().Segment.PassesData != null,
                        "Segment passes data not created correctly for AddPass()");

            var pass = CreateTestCellPass();

            leaf.AddPass(0, 0, pass);

            // Check the cell passes in the segment records the cell pass
            Assert.Equal(1, leaf.Directory.SegmentDirectory.First().Segment.PassesData.SegmentPassCount);
            Assert.Equal(1, leaf.Directory.SegmentDirectory.First().Segment.PassesData.PassCount(0, 0));
            Assert.Equal(leaf.Directory.SegmentDirectory.First().Segment.PassesData.PassTime(0, 0, 0), DateTime.SpecifyKind(new DateTime(2000, 1, 1, 1, 1, 1), DateTimeKind.Utc));

            // Pull the pass a compare it to what was added
            CellPass pass2 = leaf.Directory.SegmentDirectory.First().Segment.PassesData.Pass(0, 0, 0);

            Assert.True(pass2.Equals(pass), "Pass retrieved is not the same as the pass asses");

            // Check that the start and end time for the leaf was updated when the cell pass was added.
            Assert.True(leaf.LeafStartTime == leaf.LeafEndTime && leaf.LeafStartTime == DateTime.SpecifyKind(new DateTime(2000, 1, 1, 1, 1, 1), DateTimeKind.Utc), "Leaf start and time was not updated");
        }
Ejemplo n.º 5
0
        public void Test_MutabilityConverterTests_ConvertSubgridSegmentTest()
        {
            // Create a segment with some cell passes. Create a stream fron it then use the
            // mutability converter to convert it to the immutable form. Read this back into an immutable representation
            // and compare the mutable and immutable versions for consistency.

            // Create a mutable segment to contain the passes
            var mutableSegment = new SubGridCellPassesDataSegment
                                     (DIContext.Obtain <ISubGridCellLatestPassesDataWrapperFactory>().NewMutableWrapper_Global(),
                                     DIContext.Obtain <ISubGridCellSegmentPassesDataWrapperFactory>().NewMutableWrapper());

            // Load the mutable stream of information
            SubGridUtilities.SubGridDimensionalIterator((x, y) =>
            {
                var cellPass    = (mutableSegment.LatestPasses as SubGridCellLatestPassDataWrapper_NonStatic)[x, y];
                cellPass.Height = 1234.5678F;
                (mutableSegment.LatestPasses as SubGridCellLatestPassDataWrapper_NonStatic)[x, y] = cellPass;

                // Add 5 passes to each cell
                for (int i = 0; i < 5; i++)
                {
                    cellPass = TestCellPass();

                    // Adjust the height/time so there is a range of values
                    cellPass.Time    = cellPass.Time.AddMinutes(i);
                    cellPass.Height += i;

                    mutableSegment.PassesData.AddPass(x, y, cellPass);
                }
            });

            mutableSegment.SegmentInfo = new SubGridCellPassesDataSegmentInfo(Consts.MIN_DATETIME_AS_UTC, Consts.MAX_DATETIME_AS_UTC, null);

            // Take a copy of the mutable cells and cell passes for later reference
            var mutableLatest = mutableSegment.LatestPasses as SubGridCellLatestPassDataWrapper_NonStatic;

            Cell_NonStatic[,] mutablePasses = mutableSegment.PassesData.GetState();

            MemoryStream mutableStream = new MemoryStream(Consts.TREX_DEFAULT_MEMORY_STREAM_CAPACITY_ON_CREATION);

            using (var writer = new BinaryWriter(mutableStream, Encoding.UTF8, true))
            {
                mutableSegment.Write(writer);
            }

            // Convert the mutable data, using the sourceSegment, into the immutable form and reload it into an immutable segment
            /* todo also test using the mutableStream */
            var mutabilityConverter = new MutabilityConverter();

            mutabilityConverter.ConvertToImmutable(FileSystemStreamType.SubGridSegment, null, mutableSegment, out MemoryStream immutableStream);

            var immutableSegment = new SubGridCellPassesDataSegment
                                       (DIContext.Obtain <ISubGridCellLatestPassesDataWrapperFactory>().NewImmutableWrapper_Segment(),
                                       DIContext.Obtain <ISubGridCellSegmentPassesDataWrapperFactory>().NewImmutableWrapper());

            immutableStream.Position = 0;

            using (var reader = new BinaryReader(immutableStream, Encoding.UTF32, true))
            {
                immutableSegment.Read(reader, true, true);
            }

            var immutableLatest = immutableSegment.LatestPasses as SubGridCellLatestPassDataWrapper_StaticCompressed;

            if (immutableLatest != null)
            {
                // Check height of the latest cells match to tolerance given the compressed lossiness.
                SubGridUtilities.SubGridDimensionalIterator((x, y) =>
                {
                    double mutableValue   = mutableLatest[x, y].Height;
                    double immutableValue = immutableLatest.ReadHeight(x, y);

                    double diff = immutableValue - mutableValue;

                    Assert.True(Math.Abs(diff) <= 0.001,
                                $"Cell height at ({x}, {y}) has unexpected value: {immutableValue} vs {mutableValue}, diff = {diff}");
                });
            }

            // Check the heights specially to account for tolerance differences
            SubGridUtilities.SubGridDimensionalIterator((x, y) =>
            {
                for (int i = 0; i < immutableSegment.PassesData.PassCount(x, y); i++)
                {
                    double mutableValue   = mutableSegment.PassesData.PassHeight(x, y, i);
                    double immutableValue = immutableSegment.PassesData.PassHeight(x, y, i);

                    double diff = immutableValue - mutableValue;

                    Assert.True(Math.Abs(diff) <= 0.001, $"Cell height at ({x}, {y}) has unexpected value: {immutableValue} vs {mutableValue}, diff = {diff}");
                }
            });

            // Check the times specially to account for tolerance differences
            SubGridUtilities.SubGridDimensionalIterator((x, y) =>
            {
                for (int i = 0; i < immutableSegment.PassesData.PassCount(x, y); i++)
                {
                    DateTime mutableValue   = mutableSegment.PassesData.PassTime(x, y, i);
                    DateTime immutableValue = immutableSegment.PassesData.PassTime(x, y, i);

                    TimeSpan diff = mutableValue - immutableValue;

                    Assert.True(diff.Duration() <= TimeSpan.FromSeconds(1), $"Cell time at ({x}, {y}) has unexpected value: {immutableValue} vs {mutableValue}, diff = {diff}");
                }
            });

            // Check that the cell passes in the cell pass stacks for the segment match to tolerance given the compressed lossiness
            SubGridUtilities.SubGridDimensionalIterator((x, y) =>
            {
                for (int i = 0; i < immutableSegment.PassesData.PassCount(x, y); i++)
                {
                    CellPass cellPass = immutableSegment.PassesData.ExtractCellPass(x, y, i);

                    // Force the height and time in the immutable record to be the same as the immutable record
                    // as they have been independently checked above. Also set the machine ID to be the same as the mutable
                    // machine ID as the immutable representation does not include it in the Ignite POC

                    var mutablePass = mutablePasses[x, y].Passes.GetElement(i);
                    cellPass.Time   = mutablePass.Time;
                    cellPass.Height = mutablePass.Height;
                    cellPass.InternalSiteModelMachineIndex = mutablePass.InternalSiteModelMachineIndex;

                    CellPass mutableCellPass = mutablePasses[x, y].Passes.GetElement(i);
                    Assert.True(mutableCellPass.Equals(cellPass), $"Cell passes not equal at Cell[{x}, {y}], cell pass index {i}");
                }
            });
        }