1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/*
* Copyright (c) 2023, Google LLC and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
package org.eclipse.jgit.internal.storage.file;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.eclipse.jgit.internal.storage.file.BasePackBitmapIndex.StoredBitmap;
import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectIdOwnerMap;
import org.junit.Before;
import org.junit.Test;
import com.googlecode.javaewah.EWAHCompressedBitmap;
public class BasePackBitmapIndexTest {
private ObjectId baseOid;
private StoredBitmap baseBitmap;
private ObjectId xorOid;
private StoredBitmap xorBitmap;
private ObjectIdOwnerMap<StoredBitmap> bitmaps;
@Before
public void setUp() {
baseOid = ObjectId
.fromString("c46f36f2bfc96d6d6f75bd71ee33625293aee690");
baseBitmap = newBaseStoredBitmap(baseOid, bitmapOf(100));
xorOid = ObjectId
.fromString("52c18ae15f8fa3787f920e68791367dae2e1af2d");
xorBitmap = newXorStoredBitmap(xorOid, bitmapOf(200, 300), baseBitmap);
bitmaps = new ObjectIdOwnerMap<>();
bitmaps.add(baseBitmap);
bitmaps.add(xorBitmap);
}
@Test
public void testBitmapCounts() {
TestPackBitmapIndex index = new TestPackBitmapIndex(bitmaps);
assertEquals(1, index.getBaseBitmapCount());
assertEquals(1, index.getXorBitmapCount());
assertEquals(2, index.getBitmapCount());
}
@Test
public void testBitmapCounts_xorResolved() {
TestPackBitmapIndex index = new TestPackBitmapIndex(bitmaps);
index.getBitmap(xorOid);
assertEquals(2, index.getBaseBitmapCount());
assertEquals(0, index.getXorBitmapCount());
assertEquals(2, index.getBitmapCount());
}
@Test
public void testBitmapSizes() {
TestPackBitmapIndex index = new TestPackBitmapIndex(bitmaps);
assertEquals(baseBitmap.getCurrentSizeInBytes(),
index.getBaseBitmapSizeInBytes());
assertEquals(xorBitmap.getCurrentSizeInBytes(),
index.getXorBitmapSizeInBytes());
}
@Test
public void testBitmapSizes_xorResolved() {
TestPackBitmapIndex index = new TestPackBitmapIndex(bitmaps);
index.getBitmap(xorOid);
assertTrue(baseBitmap.getCurrentSizeInBytes() < index
.getBaseBitmapSizeInBytes());
assertEquals(0, index.getXorBitmapSizeInBytes());
}
private static final StoredBitmap newBaseStoredBitmap(ObjectId oid,
EWAHCompressedBitmap base) {
return new StoredBitmap(oid, base, null, 0);
}
private static StoredBitmap newXorStoredBitmap(ObjectId oid,
EWAHCompressedBitmap xorMask, StoredBitmap base) {
return new StoredBitmap(oid, xorMask, base, 0);
}
private static final EWAHCompressedBitmap bitmapOf(int... bits) {
EWAHCompressedBitmap b = new EWAHCompressedBitmap();
for (int bit : bits)
b.set(bit);
return b;
}
private static class TestPackBitmapIndex extends BasePackBitmapIndex {
TestPackBitmapIndex(ObjectIdOwnerMap<StoredBitmap> bitmaps) {
super(bitmaps);
}
@Override
public int findPosition(AnyObjectId objectId) {
throw new IllegalStateException();
}
@Override
public ObjectId getObject(int position)
throws IllegalArgumentException {
throw new IllegalStateException();
}
@Override
public EWAHCompressedBitmap ofObjectType(EWAHCompressedBitmap bitmap,
int type) {
throw new IllegalStateException();
}
@Override
public int getObjectCount() {
throw new IllegalStateException();
}
@Override
public int getBitmapCount() {
return getBitmaps().size();
}
}
}
|