DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
SqlLongStringTests.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2014 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 using System;
17 using System.IO;
18 using System.Text;
19 
20 using Deveel.Data.Store;
21 
22 using NUnit.Framework;
23 
24 namespace Deveel.Data.Sql.Objects {
25  [TestFixture]
26  public class SqlLongStringTests {
30 
31  private ILargeObject CreateLargeObject(long size, bool compressed) {
32  return objStore.CreateNewObject(size, compressed);
33  }
34 
36  return objStore.GetObject(id);
37  }
38 
39  private void WriteToObject(ILargeObject obj, Encoding encoding, string text) {
40  using (var stream = new ObjectStream(obj)) {
41  using (var streamWriter = new StreamWriter(stream, encoding)) {
42  streamWriter.Write(text);
43  streamWriter.Flush();
44  }
45  }
46  }
47 
48  [SetUp]
49  public void TestSetUp() {
50  storageSystem = new InMemoryStorageSystem();
51  testStore = storageSystem.CreateStore("TestStore");
52  objStore = new ObjectStore(1, testStore);
53  objStore.Create();
54  }
55 
56  [TearDown]
57  public void TestTearDown() {
58  storageSystem.DeleteStore(testStore);
59  storageSystem.Dispose();
60  storageSystem = null;
61  }
62 
63  [Test]
65  var obj = CreateLargeObject(2048, false);
66  var stringObj = SqlLongString.Unicode(obj);
67  Assert.IsNotNull(stringObj);
68  Assert.IsFalse(stringObj.IsNull);
69  }
70 
71  [Test]
72  public void WriteAndRead_Unicode() {
73  const string testLine = "A simple test string that can span several characters, " +
74  "that is trying to be the longest possible, just to prove" +
75  "the capacity of a LONG VARCHAR to handle very long strings. " +
76  "Anyway it is virtually impossible to reach the maximum size " +
77  "of a long object, that is organized in 64k byte pages and " +
78  "spans within the local system without any constraint of size. " +
79  "For sake of memory anyway, the maximum size of the test object " +
80  "is set to just 2048 bytes.";
81 
82  var obj = CreateLargeObject(2048, false);
83 
84  WriteToObject(obj, Encoding.Unicode, testLine);
85 
86  obj.Complete();
87 
88  var objId = obj.Id;
89 
90  var stringObj = SqlLongString.Unicode(obj);
91  Assert.IsNotNull(stringObj);
92  Assert.IsFalse(stringObj.IsNull);
93 
94  obj = GetLargeObject(objId);
95  Assert.IsTrue(obj.IsComplete);
96  Assert.IsFalse(obj.IsCompressed);
97 
98  stringObj = SqlLongString.Unicode(obj);
99  var reader = stringObj.GetInput(Encoding.Unicode);
100  Assert.IsNotNull(reader);
101 
102  string line = null;
103  Assert.DoesNotThrow(() => line = reader.ReadLine());
104  Assert.IsNotNull(line);
105  Assert.IsNotEmpty(line);
106 
107  Assert.AreEqual(testLine, line);
108  }
109  }
110 }
ILargeObject CreateLargeObject(long size, bool compressed)
ILargeObject CreateNewObject(long maxSize, bool compressed)
Creates a new large object returning a reference to it.
Definition: ObjectStore.cs:178
Defines a referenced object that can be accessed on a multi-phase level.
Definition: ILargeObject.cs:35
static SqlLongString Unicode(ILargeObject largeObject)
TextReader GetInput(Encoding encoding)
ILargeObject GetObject(ObjectId id)
Gets an object that was previously created for the given unique identifier.
Definition: ObjectStore.cs:490
bool IStoreSystem. DeleteStore(IStore store)
Permanently deletes a store from the system - use with care!
An implementation of IStore that persists data in the application memory.
void WriteToObject(ILargeObject obj, Encoding encoding, string text)
A unique identifier of an object within a database system, that is composed by a reference to the sto...
Definition: ObjectId.cs:31
IStore IStoreSystem. CreateStore(string name)