public void TestStructure()
        {
            for (int i = 1; i <= RepeatCnt; i++)
            {
                Console.WriteLine(">>> Iteration started: " + i);

                // 1. Generate and shuffle objects.
                IList <BranchedType> objs = new List <BranchedType>();

                for (int j = 0; j < 6 * ObjectsPerMode; j++)
                {
                    objs.Add(new BranchedType((j % 6) + 1));
                }

                objs = IgniteUtils.Shuffle(objs);

                // 2. Create new marshaller.
                BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(typeof(BranchedType));

                BinaryConfiguration cfg = new BinaryConfiguration
                {
                    TypeConfigurations = new List <BinaryTypeConfiguration> {
                        typeCfg
                    }
                };

                Marshaller marsh = new Marshaller(cfg);

                // 3. Marshal all data and ensure deserialized object is fine.
                foreach (BranchedType obj in objs)
                {
                    Console.WriteLine(">>> Write object [mode=" + obj.mode + ']');

                    byte[] data = marsh.Marshal(obj);

                    BranchedType other = marsh.Unmarshal <BranchedType>(data);

                    Assert.IsTrue(obj.Equals(other));
                }

                Console.WriteLine();

                // 4. Ensure that all fields are recorded.
                var desc = marsh.GetDescriptor(typeof(BranchedType));

                CollectionAssert.AreEquivalent(new[] { "mode", "f2", "f3", "f4", "f5", "f6", "f7", "f8" },
                                               desc.WriterTypeStructure.FieldTypes.Keys);
            }
        }
        public void TestStructure()
        {
            for (int i = 1; i <= RepeatCnt; i++)
            {
                Console.WriteLine(">>> Iteration started: " + i);

                // 1. Generate and shuffle objects.
                IList <BranchedType> objs = new List <BranchedType>();

                for (int j = 0; j < 6 * ObjectsPerMode; j++)
                {
                    objs.Add(new BranchedType((j % 6) + 1));
                }

                objs = IgniteUtils.Shuffle(objs);

                // 2. Create new marshaller.
                BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(typeof(BranchedType));

                BinaryConfiguration cfg = new BinaryConfiguration
                {
                    TypeConfigurations = new List <BinaryTypeConfiguration> {
                        typeCfg
                    }
                };

                Marshaller marsh = new Marshaller(cfg);

                // 3. Marshal all data and ensure deserialized object is fine.
                // Use single stream to test object offsets
                using (var stream = new BinaryHeapStream(128))
                {
                    var writer = marsh.StartMarshal(stream);

                    foreach (var obj in objs)
                    {
                        Console.WriteLine(">>> Write object [mode=" + obj.mode + ']');

                        writer.WriteObject(obj);
                    }

                    stream.Seek(0, SeekOrigin.Begin);

                    var reader = marsh.StartUnmarshal(stream);

                    foreach (var obj in objs)
                    {
                        var other = reader.ReadObject <BranchedType>();

                        Assert.IsTrue(obj.Equals(other));
                    }
                }

                Console.WriteLine();

                // 4. Ensure that all fields are recorded.
                var desc = marsh.GetDescriptor(typeof(BranchedType));

                CollectionAssert.AreEquivalent(new[] { "mode", "f2", "f3", "f4", "f5", "f6", "f7", "f8" },
                                               desc.WriterTypeStructure.FieldTypes.Keys);
            }
        }
Beispiel #3
0
        public void Map(PlatformMemoryStream stream)
        {
            IList <IClusterNode> subgrid;

            ClusterGroupImpl prj = (ClusterGroupImpl)_compute.ClusterGroup;

            var ignite = (Ignite)prj.Ignite;

            // 1. Unmarshal topology info if topology changed.
            var reader = prj.Marshaller.StartUnmarshal(stream);

            if (reader.ReadBoolean())
            {
                long topVer = reader.ReadLong();

                List <IClusterNode> nodes = new List <IClusterNode>(reader.ReadInt());

                int nodesCnt = reader.ReadInt();

                subgrid = new List <IClusterNode>(nodesCnt);

                for (int i = 0; i < nodesCnt; i++)
                {
                    IClusterNode node = ignite.GetNode(reader.ReadGuid());

                    nodes.Add(node);

                    if (reader.ReadBoolean())
                    {
                        subgrid.Add(node);
                    }
                }

                // Update parent projection to help other task callers avoid this overhead.
                // Note that there is a chance that topology changed even further and this update fails.
                // It means that some of subgrid nodes could have left the Grid. This is not critical
                // for us, because Java will handle it gracefully.
                prj.UpdateTopology(topVer, nodes);
            }
            else
            {
                IList <IClusterNode> nodes = prj.NodesNoRefresh();

                Debug.Assert(nodes != null, "At least one topology update should have occurred.");

                subgrid = IgniteUtils.Shuffle(nodes);
            }

            // 2. Perform map.
            IDictionary <IComputeJob <T>, IClusterNode> map;
            Exception err;

            try
            {
                map = _task.Map(subgrid, _arg);

                err = null;
            }
            catch (Exception e)
            {
                map = null;

                err = e;

                // Java can receive another exception in case of marshalling failure but it is not important.
                Finish(default(TR), e);
            }

            // 3. Write map result to the output stream.
            stream.Reset();
            BinaryWriter writer = prj.Marshaller.StartMarshal(stream);

            try
            {
                if (err == null)
                {
                    writer.WriteBoolean(true); // Success flag.

                    if (map == null)
                    {
                        writer.WriteBoolean(false); // Map produced no result.
                    }
                    else
                    {
                        writer.WriteBoolean(true); // Map produced result.

                        _jobHandles = WriteJobs(writer, map);
                    }
                }
                else
                {
                    writer.WriteBoolean(false); // Map failed.

                    // Write error as string because it is not important for Java, we need only to print
                    // a message in the log.
                    writer.WriteString("Map step failed [errType=" + err.GetType().Name +
                                       ", errMsg=" + err.Message + ']');
                }
            }
            catch (Exception e)
            {
                // Something went wrong during marshaling.
                Finish(default(TR), e);

                stream.Reset();

                writer.WriteBoolean(false);    // Map failed.
                writer.WriteString(e.Message); // Write error message.
            }
            finally
            {
                prj.Marshaller.FinishMarshal(writer);
            }
        }