public override void GlobalContext()
 {
     base.GlobalContext();
     _simulationPersister = Api.GetSimulationPersister();
     _concurrencyManager  = Api.Container.Resolve <IConcurrencyManager>();
     sut = new ConcurrentSimulationRunner(_concurrencyManager);
 }
Exemple #2
0
        public void CanGetStatisticsFromTableFilledWithValues()
        {
            manager = new StatisticsManager(tableManager, _transaction, tableCatalogName, fieldCatalogName, 1);

            var data = manager.GetStatisticalInfo(tableName, _transaction);

            var recordFile = new RecordFile(tableInfo, _transaction);

            recordFile.BeforeFirst();

            for (int i = 0; i < 30; ++i)
            {
                recordFile.Insert();
                recordFile.SetInt("Id", i + 10);
            }
            _transaction.Commit();

            //Before update

            Assert.AreEqual(1, data.BlocksAccessed);
            Assert.AreEqual(0, data.RecordsOutput);

            Assert.AreEqual(1, data.DistinctValues("Id"));

            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);
            //After update
            var updatedData = manager.GetStatisticalInfo(tableName, _transaction);

            Assert.AreEqual(30, updatedData.RecordsOutput);
            Assert.AreEqual(1, updatedData.BlocksAccessed);
            Assert.AreEqual(11, updatedData.DistinctValues("Id"));
        }
Exemple #3
0
        public void CanCreateViewDefinitionInDifferentTransaction()
        {
            var viewMetadataStorageFilename = RandomFilename;

            viewManager = new ViewManager(true, tableManager, _transaction, viewMetadataStorageFilename);

            viewManager.CreateView("view1", "viewDefinition1", _transaction);

            _transaction.Commit();

            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            var schema = new Schema();

            schema.AddStringField("viewname", ViewManager.MAX_VIEW_LENGTH);
            schema.AddStringField("viewdef", ViewManager.MAX_VIEW_LENGTH);

            var viewTableInfo = tableManager.GetTableInfo(viewMetadataStorageFilename, _transaction);
            var viewTableCatalogRecordPage = new RecordFile(viewTableInfo, _transaction);

            viewTableCatalogRecordPage.BeforeFirst();
            viewTableCatalogRecordPage.Next();

            var viewName       = viewTableCatalogRecordPage.GetString("viewname");
            var viewDefinition = viewTableCatalogRecordPage.GetString("viewdef");

            Assert.AreEqual("view1", viewName);
            Assert.AreEqual("viewDefinition1", viewDefinition);
        }
Exemple #4
0
        public void CanGetTableInfoInDifferentTableManager()
        {
            var tableMetadataStorageFilename = RandomFilename;
            var fieldMetadataStorageFilename = RandomFilename;

            tableManager = new TableManager(true, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename);
            var schema = new Schema();

            schema.AddIntField("field1");
            schema.AddBlobField("field2", 40);

            tableManager.CreateTable("table1", schema, _transaction);

            _transaction.Commit();

            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            tableManager = new TableManager(false, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename);

            var tableInfo = tableManager.GetTableInfo("table1", _transaction);

            Assert.AreEqual("table1.tbl", tableInfo.Filename);
            Assert.AreEqual(2, tableInfo.Schema.Fields.Count);
            Assert.AreEqual(48, tableInfo.RecordLength);

            var field1 = tableInfo.Schema.Fields["field1"];
            var field2 = tableInfo.Schema.Fields["field2"];

            Assert.AreEqual(FieldType.Integer, field1.Type);
            Assert.AreEqual(FieldType.Blob, field2.Type);
            Assert.AreEqual(40, field2.Length);
        }
Exemple #5
0
 public void CanCreateDefaultConcurrencyManager()
 {
     Assert.DoesNotThrow(() =>
     {
         concurrencyManager = new ConcurrencyManager();
     });
 }
Exemple #6
0
 public void CanCreateConcurrencyManager()
 {
     Assert.DoesNotThrow(() =>
     {
         concurrencyManager = new ConcurrencyManager(lockTable);
     });
 }
Exemple #7
0
        public void Setup()
        {
            _logName            = RandomFilename;
            _fileManager        = new FileManager("temp", "DBs", 1024);
            _logManager         = new LogManager(_fileManager, _logName);
            _bufferManager      = new BufferManager(_fileManager, _logManager, new NaiveBufferPoolStrategy(_logManager, _fileManager, 1000));
            _dispatcher         = new TransactionNumberDispatcher(10);
            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            var schema = new Schema();

            schema.AddIntField("Id");

            tableCatalogName = RandomFilename;
            fieldCatalogName = RandomFilename;
            viewCatalogName  = RandomFilename;

            tableName = RandomFilename;

            tableManager = new TableManager(true, _transaction, tableCatalogName, fieldCatalogName);

            tableInfo = new TableInfo(tableName, schema);
            tableManager.CreateTable(tableName, schema, _transaction);

            viewManager       = new ViewManager(true, tableManager, _transaction, viewCatalogName);
            statisticsManager = new StatisticsManager(tableManager, _transaction, tableCatalogName, fieldCatalogName, 0);
        }
 private void InitializeFakeObjects()
 {
     _storageStub = new Mock<IStorage>();
     var options = new ConcurrencyOptions
     {
         Storage = _storageStub.Object
     };
     _concurrencyManager = new ConcurrencyManager(options);
 }
Exemple #9
0
 public void Setup()
 {
     _logName            = RandomFilename;
     _fileManager        = new FileManager("temp", "DBs", 100);
     _logManager         = new LogManager(_fileManager, _logName);
     _bufferManager      = new BufferManager(_fileManager, _logManager, new NaiveBufferPoolStrategy(_logManager, _fileManager, 5));
     _dispatcher         = new TransactionNumberDispatcher(10);
     _concurrencyManager = new ConcurrencyManager();
 }
Exemple #10
0
        private void InitializeFakeObjects()
        {
            _storageStub = new Mock <IStorage>();
            var options = new ConcurrencyOptions
            {
                Storage = _storageStub.Object
            };

            _concurrencyManager = new ConcurrencyManager(options);
        }
Exemple #11
0
        public void CanTakeExclusiveLock()
        {
            concurrencyManager = new ConcurrencyManager();

            var block = new Block(RandomFilename, 0);

            Assert.DoesNotThrow(() =>
            {
                concurrencyManager.ExclusiveLock(block);
            });
        }
Exemple #12
0
        public void ReleaseMethodDoesNotThrowItNoLocksProvided()
        {
            concurrencyManager = new ConcurrencyManager();

            var block = new Block(RandomFilename, 0);

            Assert.DoesNotThrow(() =>
            {
                concurrencyManager.Release();
            });
        }
Exemple #13
0
        public void CanTakeAndReleaseSharedLock()
        {
            concurrencyManager = new ConcurrencyManager();

            var block = new Block(RandomFilename, 0);

            Assert.DoesNotThrow(() =>
            {
                concurrencyManager.SharedLock(block);
                concurrencyManager.Release();
            });
        }
Exemple #14
0
 public TransactionsManager(
     ILogger <TransactionsManager> logger,
     ITransactionsService transactionsService,
     IPublishEndpoint publishEndpoint,
     IConcurrencyManager concurrencyManager,
     ILicenseManager <ITransactionModel> licenseManager
     )
 {
     _transactionsService = transactionsService;
     _publishEndpoint     = publishEndpoint;
     _concurrencyManager  = concurrencyManager;
     _licenseManager      = licenseManager;
 }
Exemple #15
0
        public void CanTakeExclusiveLockIfAlreadyTaken()
        {
            var lockTable = new LockTable(TimeSpan.FromMilliseconds(300), TimeSpan.FromMilliseconds(100));

            concurrencyManager = new ConcurrencyManager();

            var block = new Block(RandomFilename, 0);

            Assert.DoesNotThrow(() =>
            {
                concurrencyManager.ExclusiveLock(block);
                concurrencyManager.ExclusiveLock(block);
            });
        }
Exemple #16
0
        public void Setup()
        {
            _logName            = RandomFilename;
            _fileManager        = new FileManager("temp", "DBs", 1024);
            _logManager         = new LogManager(_fileManager, _logName);
            _bufferManager      = new BufferManager(_fileManager, _logManager, new NaiveBufferPoolStrategy(_logManager, _fileManager, 10));
            _dispatcher         = new TransactionNumberDispatcher(10);
            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            var tableMetadataStorageFilename = RandomFilename;
            var fieldMetadataStorageFilename = RandomFilename;

            tableManager = new TableManager(true, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename);
        }
Exemple #17
0
        public Transaction(
            ITransactionNumberDispatcher numberDispatcher,
            IBufferManager bufferManager,
            IConcurrencyManager concurrencyManager,
            IFileManager fileManager,
            ILogManager logManager)
        {
            _numberDispatcher   = numberDispatcher;
            _concurrencyManager = concurrencyManager;
            _fileManager        = fileManager;
            _bufferList         = new TransactionBuffersList(bufferManager);

            _transactionNumber = _numberDispatcher.GetNextTransactionNumber();
            _recoveryManager   = new RecoveryManager(bufferManager, logManager, _transactionNumber);
        }
Exemple #18
0
        public void Setup()
        {
            _logName            = RandomFilename;
            _fileManager        = new FileManager("temp", "DBs", 100);
            _logManager         = new LogManager(_fileManager, _logName);
            _bufferManager      = new BufferManager(_fileManager, _logManager, new NaiveBufferPoolStrategy(_logManager, _fileManager, 10));
            _dispatcher         = new TransactionNumberDispatcher(10);
            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            var sch = new Schema();

            sch.AddIntField("field");
            _tableInfo = new TableInfo(RandomFilename, sch);
        }
Exemple #19
0
        public void Setup()
        {
            indexName = "tempIndex";

            schema = new Schema();
            schema.AddIntField("id");

            _logName            = RandomFilename;
            _fileManager        = new FileManager("temp", "DBs", 1024);
            _logManager         = new LogManager(_fileManager, _logName);
            _bufferManager      = new BufferManager(_fileManager, _logManager, new NaiveBufferPoolStrategy(_logManager, _fileManager, 10));
            _dispatcher         = new TransactionNumberDispatcher(10);
            _concurrencyManager = new ConcurrencyManager();
            transaction         = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);
        }
Exemple #20
0
        public void CanGetViewDefinitionInOtherTransaction()
        {
            var viewMetadataStorageFilename = RandomFilename;

            viewManager = new ViewManager(true, tableManager, _transaction, viewMetadataStorageFilename);

            viewManager.CreateView("view1", "viewDefinition1", _transaction);

            _transaction.Commit();
            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            var viewDefinition = viewManager.GetViewDefinition("view1", _transaction);

            Assert.AreEqual("viewDefinition1", viewDefinition);
        }
        public DefaultDatabaseEngine(
            IDatabaseComponentFactory databaseEngineFactory,
            IDatabase database)
        {
            this.compiler           = databaseEngineFactory.CreateQueryCompiler();
            this.executor           = databaseEngineFactory.CreateQueryExecutor();
            this.concurrencyManager = databaseEngineFactory.CreateConcurrencyManager();
            this.transactionHandler = databaseEngineFactory.CreateTransactionHandler();
            this.loggingPort        = databaseEngineFactory.CreateLoggingPort();
            this.serviceProvider    = databaseEngineFactory.CreateServiceProvider();

            foreach (IDatabaseComponent component in
                     this.Components.OfType <IDatabaseComponent>())
            {
                component.Initialize(database);
            }
        }
Exemple #22
0
        public void CanGetStatisticsFromNewTable()
        {
            manager = new StatisticsManager(tableManager, _transaction, tableCatalogName, fieldCatalogName, 1);

            var data = manager.GetStatisticalInfo(tableName, _transaction);

            var newTableName = RandomFilename;

            var schema = new Schema();

            schema.AddIntField("Id");
            schema.AddStringField("Guid", 40);

            var newTableInfo = new TableInfo(newTableName, schema);

            tableManager.CreateTable(newTableName, schema, _transaction);

            var recordFile = new RecordFile(newTableInfo, _transaction);

            recordFile.BeforeFirst();

            for (int i = 0; i < 50; ++i)
            {
                recordFile.Insert();
                recordFile.SetInt("Id", i + 10);
                recordFile.SetString("Guid", Guid.NewGuid().ToString());
            }

            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);
            //Before update

            Assert.AreEqual(1, data.BlocksAccessed);
            Assert.AreEqual(0, data.RecordsOutput);

            Assert.AreEqual(1, data.DistinctValues("Id"));

            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);
            //After update
            var updatedData = manager.GetStatisticalInfo(newTableName, _transaction);

            Assert.AreEqual(50, updatedData.RecordsOutput);
            Assert.AreEqual(3, updatedData.BlocksAccessed);
            Assert.AreEqual(17, updatedData.DistinctValues("Id"));
        }
        public DefaultDatabaseEngine(
            IDatabaseComponentFactory databaseEngineFactory,
            IDatabase database)
        {
            this.compiler = databaseEngineFactory.CreateQueryCompiler();
            this.executor = databaseEngineFactory.CreateQueryExecutor();
            this.concurrencyManager = databaseEngineFactory.CreateConcurrencyManager();
            this.transactionHandler = databaseEngineFactory.CreateTransactionHandler();
            this.loggingPort = databaseEngineFactory.CreateLoggingPort();
            this.serviceProvider = databaseEngineFactory.CreateServiceProvider();

            foreach (IDatabaseComponent component in
                this.Components.OfType<IDatabaseComponent>())
            {
                component.Initialize(database);
            }
        }
Exemple #24
0
        public void WouldGetEmptyStringIfViewWasNotFound()
        {
            var viewMetadataStorageFilename = RandomFilename;

            viewManager = new ViewManager(true, tableManager, _transaction, viewMetadataStorageFilename);

            viewManager.CreateView("view1", "viewDefinition1", _transaction);

            _transaction.Commit();
            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            viewManager = new ViewManager(false, tableManager, _transaction, viewMetadataStorageFilename);

            var viewDefinition = viewManager.GetViewDefinition("view2", _transaction);

            Assert.AreEqual(string.Empty, viewDefinition);
        }
Exemple #25
0
        public void CanGetRecordsOutputOnMoreThanOneBlock()
        {
            var recordFile = new RecordFile(tableInfo, _transaction);

            recordFile.BeforeFirst();

            for (int i = 0; i < 1024; ++i)
            {
                recordFile.Insert();
                recordFile.SetInt("Id", i * i);
            }
            recordFile.Close();
            _transaction.Commit();
            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);


            indexInfo = new IndexInfo("index", tableName, "Id", tableManager, statisticsManager, _transaction, 1024);

            var recordsOutput = indexInfo.RecordsOutput();

            Assert.AreEqual(2, recordsOutput);
        }
Exemple #26
0
        public void WouldGetNullIfTableWasNotFound()
        {
            var tableMetadataStorageFilename = RandomFilename;
            var fieldMetadataStorageFilename = RandomFilename;

            tableManager = new TableManager(true, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename);
            var schema = new Schema();

            schema.AddIntField("field1");
            schema.AddBlobField("field2", 40);

            tableManager.CreateTable("table1", schema, _transaction);

            _transaction.Commit();

            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            tableManager = new TableManager(false, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename);

            var tableInfo = tableManager.GetTableInfo("table2", _transaction);

            Assert.IsNull(tableInfo);
        }
 public ConcurrentSimulationRunner(IConcurrencyManager concurrencyManager)
 {
     _concurrencyManager = concurrencyManager;
 }
 public RepresentationManager(IConcurrencyManager concurrencyManager)
 {
     _concurrencyManager = concurrencyManager;
 }
Exemple #29
0
        public void CanCreateTable()
        {
            var tableMetadataStorageFilename = RandomFilename;
            var fieldMetadataStorageFilename = RandomFilename;

            tableManager = new TableManager(true, _transaction, tableMetadataStorageFilename, fieldMetadataStorageFilename);
            var schema = new Schema();

            schema.AddIntField("field1");
            schema.AddBlobField("field2", 40);

            tableManager.CreateTable("table1", schema, _transaction);

            _transaction.Commit();

            _concurrencyManager = new ConcurrencyManager();
            _transaction        = new Transaction(_dispatcher, _bufferManager, _concurrencyManager, _fileManager, _logManager);

            var tableCatalogSchema = new Schema();

            tableCatalogSchema.AddStringField("tblname", TableManager.MAX_NAME_LENGTH);
            tableCatalogSchema.AddIntField("reclength");

            var tableCatalogInfo       = new TableInfo(tableMetadataStorageFilename, tableCatalogSchema);
            var tableCatalogRecordPage = new RecordFile(tableCatalogInfo, _transaction);

            tableCatalogRecordPage.BeforeFirst();
            tableCatalogRecordPage.Next();

            // skip all tables definition and all fields definition tables
            tableCatalogRecordPage.Next();
            tableCatalogRecordPage.Next();

            var tableName    = tableCatalogRecordPage.GetString("tblname");
            var recordLength = tableCatalogRecordPage.GetInt("reclength");

            Assert.AreEqual("table1", tableName);
            Assert.AreEqual(new TableInfo("table1", schema).RecordLength, recordLength);

            var fieldCatalogSchema = new Schema();

            fieldCatalogSchema.AddStringField("tblname", TableManager.MAX_NAME_LENGTH);
            fieldCatalogSchema.AddStringField("fldname", TableManager.MAX_NAME_LENGTH);
            fieldCatalogSchema.AddIntField("type");
            fieldCatalogSchema.AddIntField("length");
            fieldCatalogSchema.AddIntField("offset");
            var fieldCatalogInfo       = new TableInfo(fieldMetadataStorageFilename, fieldCatalogSchema);
            var fieldCatalogRecordPage = new RecordFile(fieldCatalogInfo, _transaction);

            fieldCatalogRecordPage.BeforeFirst();
            fieldCatalogRecordPage.Next();

            // 2 field for table metadata table, 5 fields for field metadata table
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();
            fieldCatalogRecordPage.Next();

            var field1Table  = fieldCatalogRecordPage.GetString("tblname");
            var field1Name   = fieldCatalogRecordPage.GetString("fldname");
            var field1Type   = fieldCatalogRecordPage.GetInt("type");
            var field1Length = fieldCatalogRecordPage.GetInt("length");
            var field1Offset = fieldCatalogRecordPage.GetInt("offset");

            Assert.AreEqual("table1", field1Table);
            Assert.AreEqual("field1", field1Name);
            Assert.AreEqual(2, field1Type);
            Assert.AreEqual(sizeof(int), field1Length);
            Assert.AreEqual(0, field1Offset);

            fieldCatalogRecordPage.Next();

            var field2Table  = fieldCatalogRecordPage.GetString("tblname");
            var field2Name   = fieldCatalogRecordPage.GetString("fldname");
            var field2Type   = fieldCatalogRecordPage.GetInt("type");
            var field2Length = fieldCatalogRecordPage.GetInt("length");
            var field2Offset = fieldCatalogRecordPage.GetInt("offset");

            Assert.AreEqual("table1", field2Table);
            Assert.AreEqual("field2", field2Name);
            Assert.AreEqual(4, field2Type);
            Assert.AreEqual(40, field2Length);
            Assert.AreEqual(4, field2Offset);
        }
 public RepresentationManager(IConcurrencyManager concurrencyManager)
 {
     _concurrencyManager = concurrencyManager;
 }