public void TestInitialLookup()
 {
     var objectLocationManager = new ObjectLocationManager();
     objectLocationManager.SetObjectOffset(1, 500, 1, 1);
     var offset = objectLocationManager.GetObjectOffset(1);
     Assert.AreEqual(500u, offset);
 }
        public void TestSetExistingValueLookup()
        {
            var objectLocationManager = new ObjectLocationManager();
            objectLocationManager.SetObjectOffset(1, 500, 1, 1);
            var offset = objectLocationManager.GetObjectOffset(1);
            Assert.AreEqual(500u, offset);

            objectLocationManager.SetObjectOffset(1, 1001, 1, 1);
            offset = objectLocationManager.GetObjectOffset(1);
            Assert.AreEqual(1001u, offset);
        }
        public void Test1001Inserts()
        {
            var objectLocationManager = new ObjectLocationManager();
            for (ulong i=0;i < 1001; i++)
            {
                objectLocationManager.SetObjectOffset(i, 1000 + i, 1, 1);
            }            

            // check all OK
            for (ulong i = 0; i < 1001; i++)
            {
                var offset = objectLocationManager.GetObjectOffset(i);
                Assert.AreEqual(1000 + i, offset);
            }     
       
            Assert.AreEqual(2, objectLocationManager.NumberOfContainers);
        }
        public void StoreObjects(IEnumerable <IPersistable> objects, ObjectLocationManager objectLocationManager, string storeLocation)
        {
            Stream fs = null;

            try
            {
                var fileName = Path.Combine(storeLocation, DataFileName);
                if (!_persistenceManager.FileExists(fileName))
                {
                    throw new StoreManagerException(storeLocation, "Data file not found");
                }

                fs = _persistenceManager.GetOutputStream(fileName, FileMode.Append);
                var offset = (ulong)fs.Length;
                using (var writer = new BinaryWriter(fs))
                {
                    fs = null;
                    foreach (var obj in objects)
                    {
                        try
                        {
                            // mark each as no longer pending to commit
                            obj.ScheduledForCommit = false;

                            // store object
                            var bytes = obj.Save(writer, offset);

                            // manage offsets
                            objectLocationManager.SetObjectOffset(obj.ObjectId, offset,
                                                                  PersistantTypeIdentifiers[obj.GetType()], 1);
                            offset += (ulong)bytes;
                        }
                        catch (Exception ex)
                        {
#if WINDOWS_PHONE || PORTABLE
                            Logging.LogError(BrightstarEventId.ObjectWriteError,
                                             "Error writing object {0} with Id {1} and type {2}. Cause: {3}.",
                                             obj, obj.ObjectId, obj.GetType().FullName, ex);
#else
                            Logging.LogError(BrightstarEventId.ObjectWriteError,
                                             "Error writing object {0} with Id {1} and type {2}. Cause: {3}. Call stack: {4}",
                                             obj, obj.ObjectId, obj.GetType().FullName, ex,
                                             Environment.StackTrace);
#endif
                            throw;
                        }
                    }
                    writer.Flush();
                }
            }
            catch (Exception ex)
            {
                Logging.LogError(BrightstarEventId.ObjectWriteError, "Error storing objects {0} {1}", ex.Message, ex.StackTrace);
                throw;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Dispose();
                }
            }
        }
 public void TestInitialInsert()
 {
     var objectLocationManager = new ObjectLocationManager();
     objectLocationManager.SetObjectOffset(1, 500, 1, 1);
 }