mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +02:00
Add assertions to ensure the index has a write-lock when it is written to.
This commit is contained in:
parent
d1db017310
commit
2c80cfda68
6 changed files with 18 additions and 1 deletions
|
@ -53,6 +53,7 @@ public class BTreeTests extends BaseTestCase {
|
||||||
protected void init(int degree) throws Exception {
|
protected void init(int degree) throws Exception {
|
||||||
dbFile = File.createTempFile("pdomtest", "db");
|
dbFile = File.createTempFile("pdomtest", "db");
|
||||||
db = new Database(dbFile, new ChunkCache(), 0);
|
db = new Database(dbFile, new ChunkCache(), 0);
|
||||||
|
db.setWritable();
|
||||||
rootRecord = Database.DATA_AREA;
|
rootRecord = Database.DATA_AREA;
|
||||||
comparator = new BTMockRecordComparator();
|
comparator = new BTMockRecordComparator();
|
||||||
btree = new BTree(db, rootRecord, degree, comparator);
|
btree = new BTree(db, rootRecord, degree, comparator);
|
||||||
|
|
|
@ -38,6 +38,7 @@ public class DBPropertiesTests extends BaseTestCase {
|
||||||
dbLoc = File.createTempFile("test", "db");
|
dbLoc = File.createTempFile("test", "db");
|
||||||
dbLoc.deleteOnExit();
|
dbLoc.deleteOnExit();
|
||||||
db = new Database(dbLoc, new ChunkCache(), 0);
|
db = new Database(dbLoc, new ChunkCache(), 0);
|
||||||
|
db.setWritable();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tearDown() throws Exception {
|
protected void tearDown() throws Exception {
|
||||||
|
@ -45,6 +46,7 @@ public class DBPropertiesTests extends BaseTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBasic() throws CoreException {
|
public void testBasic() throws CoreException {
|
||||||
|
db.setWritable();
|
||||||
DBProperties properties = new DBProperties(db);
|
DBProperties properties = new DBProperties(db);
|
||||||
Properties expected = System.getProperties();
|
Properties expected = System.getProperties();
|
||||||
for(Iterator i = expected.keySet().iterator(); i.hasNext(); ) {
|
for(Iterator i = expected.keySet().iterator(); i.hasNext(); ) {
|
||||||
|
|
|
@ -127,6 +127,7 @@ public class DBTest extends BaseTestCase {
|
||||||
File f = getTestDir().append("testStrings.dat").toFile();
|
File f = getTestDir().append("testStrings.dat").toFile();
|
||||||
f.delete();
|
f.delete();
|
||||||
final Database db = new Database(f, new ChunkCache(), 0);
|
final Database db = new Database(f, new ChunkCache(), 0);
|
||||||
|
db.setWritable();
|
||||||
|
|
||||||
String[] names = {
|
String[] names = {
|
||||||
"ARLENE",
|
"ARLENE",
|
||||||
|
|
|
@ -249,6 +249,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
}
|
}
|
||||||
|
|
||||||
void reloadFromFile(File file) throws CoreException {
|
void reloadFromFile(File file) throws CoreException {
|
||||||
|
assert lockCount < 0; // must have write lock.
|
||||||
File oldFile= fPath;
|
File oldFile= fPath;
|
||||||
fLinkageIDCache.clear();
|
fLinkageIDCache.clear();
|
||||||
try {
|
try {
|
||||||
|
@ -257,6 +258,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
CCorePlugin.log(e);
|
CCorePlugin.log(e);
|
||||||
}
|
}
|
||||||
loadDatabase(file, db.getChunkCache());
|
loadDatabase(file, db.getChunkCache());
|
||||||
|
db.setWritable();
|
||||||
oldFile.delete();
|
oldFile.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -750,7 +752,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
||||||
db.resetCacheCounters();
|
db.resetCacheCounters();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void flush() throws CoreException {
|
protected void flush() throws CoreException {
|
||||||
db.flush();
|
db.flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -72,6 +72,10 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
|
||||||
super.clear();
|
super.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void flush() throws CoreException {
|
||||||
|
super.flush();
|
||||||
|
}
|
||||||
|
|
||||||
public PDOMBinding addBinding(IASTName name) throws CoreException {
|
public PDOMBinding addBinding(IASTName name) throws CoreException {
|
||||||
PDOMBinding result= null;
|
PDOMBinding result= null;
|
||||||
PDOMLinkage linkage= createLinkage(name.getLinkage().getID());
|
PDOMLinkage linkage= createLinkage(name.getLinkage().getID());
|
||||||
|
|
|
@ -57,6 +57,7 @@ final class Chunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putByte(int offset, byte value) {
|
public void putByte(int offset, byte value) {
|
||||||
|
assert fLocked;
|
||||||
fDirty= true;
|
fDirty= true;
|
||||||
fBuffer.put(offset % Database.CHUNK_SIZE, value);
|
fBuffer.put(offset % Database.CHUNK_SIZE, value);
|
||||||
}
|
}
|
||||||
|
@ -73,12 +74,14 @@ final class Chunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putBytes(int offset, byte[] bytes) {
|
public void putBytes(int offset, byte[] bytes) {
|
||||||
|
assert fLocked;
|
||||||
fDirty= true;
|
fDirty= true;
|
||||||
fBuffer.position(offset % Database.CHUNK_SIZE);
|
fBuffer.position(offset % Database.CHUNK_SIZE);
|
||||||
fBuffer.put(bytes, 0, bytes.length);
|
fBuffer.put(bytes, 0, bytes.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putInt(int offset, int value) {
|
public void putInt(int offset, int value) {
|
||||||
|
assert fLocked;
|
||||||
fDirty= true;
|
fDirty= true;
|
||||||
fBuffer.putInt(offset % Database.CHUNK_SIZE, value);
|
fBuffer.putInt(offset % Database.CHUNK_SIZE, value);
|
||||||
}
|
}
|
||||||
|
@ -88,6 +91,7 @@ final class Chunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putShort(int offset, short value) {
|
public void putShort(int offset, short value) {
|
||||||
|
assert fLocked;
|
||||||
fDirty= true;
|
fDirty= true;
|
||||||
fBuffer.putShort(offset % Database.CHUNK_SIZE, value);
|
fBuffer.putShort(offset % Database.CHUNK_SIZE, value);
|
||||||
}
|
}
|
||||||
|
@ -101,11 +105,13 @@ final class Chunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putLong(int offset, long value) {
|
public void putLong(int offset, long value) {
|
||||||
|
assert fLocked;
|
||||||
fDirty= true;
|
fDirty= true;
|
||||||
fBuffer.putLong(offset % Database.CHUNK_SIZE, value);
|
fBuffer.putLong(offset % Database.CHUNK_SIZE, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void putChar(int offset, char value) {
|
public void putChar(int offset, char value) {
|
||||||
|
assert fLocked;
|
||||||
fDirty= true;
|
fDirty= true;
|
||||||
fBuffer.putChar(offset % Database.CHUNK_SIZE, value);
|
fBuffer.putChar(offset % Database.CHUNK_SIZE, value);
|
||||||
}
|
}
|
||||||
|
@ -120,6 +126,7 @@ final class Chunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear(int offset, int length) {
|
void clear(int offset, int length) {
|
||||||
|
assert fLocked;
|
||||||
fDirty= true;
|
fDirty= true;
|
||||||
fBuffer.position(offset % Database.CHUNK_SIZE);
|
fBuffer.position(offset % Database.CHUNK_SIZE);
|
||||||
fBuffer.put(new byte[length]);
|
fBuffer.put(new byte[length]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue