public void CanInsertRecordWithByte() { var fn = RandomFilename; var block = new Block(fn, 0); var sch = new Schema(); sch.AddByteField("field"); recordPage = new RecordPage(block, _tableInfo, _transaction, _fileManager); var canInsert = recordPage.Insert(); recordPage.SetByte("field", 20); recordPage.Close(); _transaction.Commit(); var page = _fileManager.ResolvePage(block); page.Read(block); page.GetInt(0, out var isUsed); page.GetByte(4, out var value); Assert.IsTrue(canInsert); Assert.AreEqual(1, isUsed); Assert.AreEqual(20, value); }
public void CanReadWrittenByteRecord() { var tableFile = RandomFilename; var schema = new Schema(); schema.AddByteField("field"); _tableInfo = new TableInfo(tableFile, schema); _recordFile = new RecordFile(_tableInfo, _transaction); _recordFile.MoveToRID(new RID(0, 0)); _recordFile.SetByte("field", 10); _recordFile.Close(); _transaction.Commit(); var cm = new ConcurrencyManager(); var newTr = new Transaction(_dispatcher, _bufferManager, cm, _fileManager, _logManager); var rf = new RecordFile(_tableInfo, newTr); rf.MoveToRID(new RID(0, 0)); var value = rf.GetByte("field"); Assert.AreEqual(10, value); }
public void CanAddAllFieldsFromSchema() { var schema = new Schema(); var newSchema = new Schema(); Assert.DoesNotThrow(() => { schema.AddBoolField("field1"); schema.AddByteField("field2"); newSchema.AddAll(schema); }); var fields = newSchema.Fields; var field1 = fields.First(); var field2 = fields.Last(); Assert.IsNotNull(fields); Assert.AreEqual(2, fields.Count); Assert.AreEqual(FieldType.Bool, field1.Value.Type); Assert.AreEqual("field1", field1.Key); Assert.AreEqual(FieldType.Byte, field2.Value.Type); Assert.AreEqual("field2", field2.Key); }
private Schema CreateSchema() { var schema = new Schema(); schema.AddIntField("blk"); schema.AddIntField("id"); // TODO for all types var indexType = _tableInfo.Schema.FieldType(_fieldName); switch (indexType) { case FieldType.Bool: // lol dude why u want BTree on bool??? Are you insane? schema.AddBoolField("val"); break; case FieldType.Byte: schema.AddByteField("val"); break; case FieldType.Integer: schema.AddIntField("val"); break; case FieldType.Date: schema.AddDateField("val"); break; case FieldType.Blob: var blobFieldLength = _tableInfo.Schema.Length(_fieldName); schema.AddBlobField("val", blobFieldLength); break; case FieldType.String: var stringFieldLength = _tableInfo.Schema.Length(_fieldName); schema.AddStringField("val", stringFieldLength); break; } return(schema); }
public void CanFormatPageWithOneByteFieldInside() { _schema.AddByteField("field"); _tableInfo = new TableInfo(RandomFilename, _schema); _recordFormatter = new RecordFormatter(_tableInfo, _fileManager); var page = _fileManager.ResolvePage(); Assert.DoesNotThrow(() => { _recordFormatter.Format(page); }); }
public void CanCreateCompleteRecord() { var schema = new Schema(); schema.AddIntField("field1"); schema.AddBoolField("field2"); schema.AddByteField("field3"); schema.AddBlobField("field4", 10); schema.AddStringField("field5", 10); schema.AddDateField("field6"); var tableInfo = new TableInfo("table", schema); Assert.AreEqual(42, tableInfo.RecordLength); }
public void CanAddByteField() { var schema = new Schema(); Assert.DoesNotThrow(() => { schema.AddByteField("field"); }); var fields = schema.Fields; var field = fields.First(); Assert.IsNotNull(fields); Assert.AreEqual(1, fields.Count); Assert.AreEqual(FieldType.Byte, field.Value.Type); Assert.AreEqual("field", field.Key); }
public void CanCreateByteIndex() { var indexTableName = RandomFilename; var schema = new Schema(); schema.AddByteField("Field"); tableInfo = new TableInfo(indexTableName, schema); tableManager.CreateTable(indexTableName, schema, _transaction); indexInfo = new IndexInfo("index", indexTableName, "Field", tableManager, statisticsManager, _transaction, 1024); // Todo check them out var indexSchema = indexInfo.Open(); Assert.Pass(); }
public void CanReadByteFromRecord() { var fn = RandomFilename; var block = new Block(fn, 0); var sch = new Schema(); sch.AddByteField("field"); var page = _fileManager.ResolvePage(block); page.Read(block); page.SetInt(0, 4); page.SetByte(4, 10); page.Write(block); recordPage = new RecordPage(block, _tableInfo, _transaction, _fileManager); recordPage.MoveToId(0); var value = recordPage.GetByte("field"); Assert.AreEqual(10, value); }