Esempio n. 1
0
        public ObjectStorage(Configuration configuration, Collection collection)
        {
            var dirPath = Path.Combine(configuration.DataPath, collection.Name);

            Directory.CreateDirectory(dirPath);

            var settings = Utils.StorageSettings(configuration, 32);

            _storage = Factory.CreateBPlusTreeStorage(DocumentIdSerializer.Singleton, new NativeSerializer <T>(), settings);
            _storage.OpenOrCreate(dirPath);

            _topId = _storage.Max() ?? new DocumentId();
        }
        public void ConcurrentAccess(int count, int threadCount)
        {
            var r     = new Random();
            var pairs = new Dictionary <int, int>();

            for (int i = 0; i < count; i++)
            {
                pairs[i] = r.Next(1000000);
            }

            _sharedPairs = pairs;

            using (var storage = GetStorage())
            {
                _sharedStorage = storage;
                storage.CreateNew(StoragePath);

                // create threads
                var threads = new List <Thread>();
                for (int i = 0; i < threadCount; i++)
                {
                    threads.Add(new Thread(WorkerRoutine));
                }

                int startNumber = 0;
                // and start them
                foreach (Thread thread in threads)
                {
                    thread.Start(new Tuple <int, int>(startNumber, count / threadCount));
                    startNumber += count / threadCount;
                }

                // wait for the end of work
                foreach (Thread thread in threads)
                {
                    thread.Join();
                }

                foreach (var pair in pairs)
                {
                    string value = storage.Get(pair.Key.ToString(CultureInfo.InvariantCulture));
                    Assert.AreEqual(pair.Value.ToString(CultureInfo.InvariantCulture), value);
                }
            }
        }