本文整理汇总了Java中net.openhft.chronicle.ExcerptAppender.writeInt方法的典型用法代码示例。如果您正苦于以下问题:Java ExcerptAppender.writeInt方法的具体用法?Java ExcerptAppender.writeInt怎么用?Java ExcerptAppender.writeInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.openhft.chronicle.ExcerptAppender
的用法示例。
在下文中一共展示了ExcerptAppender.writeInt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFindRange
import net.openhft.chronicle.ExcerptAppender; //导入方法依赖的package包/类
@Ignore
@Test(expected = UnsupportedOperationException.class)
public void testFindRange() throws IOException {
final String baseDir = getTestPath();
assertNotNull(baseDir);
final VanillaChronicle chronicle = new VanillaChronicle(baseDir);
try {
ExcerptAppender appender = chronicle.createAppender();
List<Integer> ints = new ArrayList<Integer>();
for (int i = 0; i < 1000; i += 10) {
appender.startExcerpt();
appender.writeInt(i);
appender.finish();
ints.add(i);
}
appender.close();
Excerpt excerpt = chronicle.createExcerpt();
final MyExcerptComparator mec = new MyExcerptComparator();
// exact matches at a the start
mec.lo = mec.hi = -1;
assertEquals(~0, excerpt.findMatch(mec));
mec.lo = mec.hi = 0;
assertEquals(0, excerpt.findMatch(mec));
mec.lo = mec.hi = 9;
assertEquals(~1, excerpt.findMatch(mec));
mec.lo = mec.hi = 10;
assertEquals(1, excerpt.findMatch(mec));
// exact matches at a the end
mec.lo = mec.hi = 980;
assertEquals(98, excerpt.findMatch(mec));
mec.lo = mec.hi = 981;
assertEquals(~99, excerpt.findMatch(mec));
mec.lo = mec.hi = 990;
assertEquals(99, excerpt.findMatch(mec));
mec.lo = mec.hi = 1000;
assertEquals(~100, excerpt.findMatch(mec));
// range match near the start
long[] startEnd = new long[2];
mec.lo = 0;
mec.hi = 3;
excerpt.findRange(startEnd, mec);
assertEquals("[0, 1]", Arrays.toString(startEnd));
mec.lo = 21;
mec.hi = 29;
excerpt.findRange(startEnd, mec);
assertEquals("[3, 3]", Arrays.toString(startEnd));
/*
* mec.lo = 129; mec.hi = 631; testSearchRange(ints, excerpt, mec,
* startEnd);
*/
Random rand = new Random(1);
for (int i = 0; i < 1000; i++) {
int x = rand.nextInt(1010) - 5;
int y = rand.nextInt(1010) - 5;
mec.lo = Math.min(x, y);
mec.hi = Math.max(x, y);
testSearchRange(ints, excerpt, mec, startEnd);
}
excerpt.close();
chronicle.checkCounts(1, 1);
} finally {
chronicle.close();
chronicle.clear();
assertFalse(new File(baseDir).exists());
}
}
示例2: testMultipleCycles2
import net.openhft.chronicle.ExcerptAppender; //导入方法依赖的package包/类
@Test
public void testMultipleCycles2() throws Exception {
final String baseDir = "build/vanilla";
assertNotNull(baseDir);
FileUtil.removeIfExist(baseDir, false);
// Create with small data and index sizes so that the test frequently
// generates new files
VanillaChronicleConfig config = new VanillaChronicleConfig();
config.cycleFormat("yyyy-MM-dd-HH:mm:ss");
config.cycleLength(60 * 1000, false);
config.entriesPerCycle(512 * 1024);
config.dataBlockSize(4 * 1024 * 1024);
config.indexBlockSize(1 * 1024 * 1024);
final VanillaChronicle chronicle = new VanillaChronicle(baseDir, config);
chronicle.clear();
try {
ExcerptAppender appender = chronicle.createAppender();
long start = System.currentTimeMillis() ;
for(int j = 0; j < 4500000; j++) {
appender.startExcerpt();
appender.writeInt(j + 1);
appender.finish();
}
long exec = System.currentTimeMillis() - start ;
System.out.println("Append in " + exec + "ms");
for(int i = 0; i < 5; i++) {
long sum = 0 ;
AtomicInteger count = new AtomicInteger() ;
ExcerptTailer tailer = chronicle.createTailer();
int lastValue = 0 ;
while(tailer.nextIndex()) {
count.incrementAndGet() ;
lastValue = tailer.readInt();
sum += lastValue;
tailer.finish();
}
//tailer.flush() ;
tailer.close();
System.out.println("files = " +tailer.file()) ;
System.out.println(
"count = " + count.get() + ", sum = " + sum + ", last value = " + lastValue + ", last index = " + chronicle.lastIndex() +
", was padding = " + tailer.wasPadding() + ", nextIndex = " + tailer.nextIndex() +
", finished = " + tailer.isFinished());
}
appender.close();
chronicle.checkCounts(1, 1);
} finally {
chronicle.close();
}
}