Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
jobily
Questdb
提交
a3c556ac
Q
Questdb
项目概览
jobily
/
Questdb
12 个月 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Q
Questdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a3c556ac
编写于
12月 20, 2014
作者:
V
Vlad Ilyushchenko
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactoring dates
上级
b83e9643
变更
39
隐藏空白更改
内联
并排
Showing
39 changed file
with
1826 addition
and
1832 deletion
+1826
-1832
nfsdb-core/pom.xml
nfsdb-core/pom.xml
+0
-1
nfsdb-core/src/main/java/com/nfsdb/journal/Journal.java
nfsdb-core/src/main/java/com/nfsdb/journal/Journal.java
+7
-4
nfsdb-core/src/main/java/com/nfsdb/journal/JournalWriter.java
...b-core/src/main/java/com/nfsdb/journal/JournalWriter.java
+3
-3
nfsdb-core/src/main/java/com/nfsdb/journal/Partition.java
nfsdb-core/src/main/java/com/nfsdb/journal/Partition.java
+1
-6
nfsdb-core/src/main/java/com/nfsdb/journal/SymbolIndexProxy.java
...ore/src/main/java/com/nfsdb/journal/SymbolIndexProxy.java
+7
-7
nfsdb-core/src/main/java/com/nfsdb/journal/export/JournalEntryPrinter.java
...in/java/com/nfsdb/journal/export/JournalEntryPrinter.java
+2
-2
nfsdb-core/src/main/java/com/nfsdb/journal/net/comsumer/JournalDeltaConsumer.java
.../com/nfsdb/journal/net/comsumer/JournalDeltaConsumer.java
+1
-2
nfsdb-core/src/main/java/com/nfsdb/journal/printer/converter/DateConverter.java
...va/com/nfsdb/journal/printer/converter/DateConverter.java
+2
-2
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Dates.java
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Dates.java
+413
-75
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Dates2.java
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Dates2.java
+0
-418
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Interval.java
...-core/src/main/java/com/nfsdb/journal/utils/Interval.java
+80
-2
nfsdb-core/src/test/java/com/nfsdb/journal/DatesTest.java
nfsdb-core/src/test/java/com/nfsdb/journal/DatesTest.java
+39
-40
nfsdb-core/src/test/java/com/nfsdb/journal/EmptyJournalTest.java
...ore/src/test/java/com/nfsdb/journal/EmptyJournalTest.java
+3
-3
nfsdb-core/src/test/java/com/nfsdb/journal/GenericAppendPerfTest.java
...rc/test/java/com/nfsdb/journal/GenericAppendPerfTest.java
+2
-2
nfsdb-core/src/test/java/com/nfsdb/journal/IteratorTest.java
nfsdb-core/src/test/java/com/nfsdb/journal/IteratorTest.java
+5
-4
nfsdb-core/src/test/java/com/nfsdb/journal/JournalRecoveryTest.java
.../src/test/java/com/nfsdb/journal/JournalRecoveryTest.java
+5
-5
nfsdb-core/src/test/java/com/nfsdb/journal/JournalRefreshTest.java
...e/src/test/java/com/nfsdb/journal/JournalRefreshTest.java
+12
-13
nfsdb-core/src/test/java/com/nfsdb/journal/JournalTest.java
nfsdb-core/src/test/java/com/nfsdb/journal/JournalTest.java
+16
-16
nfsdb-core/src/test/java/com/nfsdb/journal/LagTest.java
nfsdb-core/src/test/java/com/nfsdb/journal/LagTest.java
+31
-32
nfsdb-core/src/test/java/com/nfsdb/journal/LockTest.java
nfsdb-core/src/test/java/com/nfsdb/journal/LockTest.java
+3
-3
nfsdb-core/src/test/java/com/nfsdb/journal/NullTest.java
nfsdb-core/src/test/java/com/nfsdb/journal/NullTest.java
+2
-2
nfsdb-core/src/test/java/com/nfsdb/journal/PartitionTest.java
...b-core/src/test/java/com/nfsdb/journal/PartitionTest.java
+9
-9
nfsdb-core/src/test/java/com/nfsdb/journal/PerformanceTest.java
...core/src/test/java/com/nfsdb/journal/PerformanceTest.java
+4
-4
nfsdb-core/src/test/java/com/nfsdb/journal/PrinterTest.java
nfsdb-core/src/test/java/com/nfsdb/journal/PrinterTest.java
+2
-2
nfsdb-core/src/test/java/com/nfsdb/journal/QueryTest.java
nfsdb-core/src/test/java/com/nfsdb/journal/QueryTest.java
+19
-17
nfsdb-core/src/test/java/com/nfsdb/journal/ResultSetTest.java
...b-core/src/test/java/com/nfsdb/journal/ResultSetTest.java
+2
-2
nfsdb-core/src/test/java/com/nfsdb/journal/SortTest.java
nfsdb-core/src/test/java/com/nfsdb/journal/SortTest.java
+2
-2
nfsdb-core/src/test/java/com/nfsdb/journal/TimestampTest.java
...b-core/src/test/java/com/nfsdb/journal/TimestampTest.java
+16
-16
nfsdb-core/src/test/java/com/nfsdb/journal/lang/SearchByKeysTest.java
...rc/test/java/com/nfsdb/journal/lang/SearchByKeysTest.java
+1
-1
nfsdb-core/src/test/java/com/nfsdb/journal/lang/SingleJournalSearchTest.java
.../java/com/nfsdb/journal/lang/SingleJournalSearchTest.java
+4
-4
nfsdb-core/src/test/java/com/nfsdb/journal/lang/experimental/ModelGenerationTest.java
.../nfsdb/journal/lang/experimental/ModelGenerationTest.java
+1
-1
nfsdb-core/src/test/java/com/nfsdb/journal/net/JournalLagTest.java
...e/src/test/java/com/nfsdb/journal/net/JournalLagTest.java
+5
-5
nfsdb-core/src/test/java/com/nfsdb/journal/net/JournalTest.java
...core/src/test/java/com/nfsdb/journal/net/JournalTest.java
+6
-6
nfsdb-core/src/test/java/com/nfsdb/journal/net/PartitionTest.java
...re/src/test/java/com/nfsdb/journal/net/PartitionTest.java
+3
-3
nfsdb-core/src/test/java/com/nfsdb/journal/test/tools/TestData.java
.../src/test/java/com/nfsdb/journal/test/tools/TestData.java
+1104
-1104
nfsdb-core/src/test/java/com/nfsdb/journal/test/tools/TestUtils.java
...src/test/java/com/nfsdb/journal/test/tools/TestUtils.java
+2
-2
nfsdb-examples/src/main/java/org/nfsdb/examples/iterate/IntervalExample.java
...main/java/org/nfsdb/examples/iterate/IntervalExample.java
+4
-4
nfsdb-examples/src/main/java/org/nfsdb/examples/query/QueryBuilderExample.java
...in/java/org/nfsdb/examples/query/QueryBuilderExample.java
+4
-4
nfsdb-examples/src/main/java/org/nfsdb/examples/reporting/DailyPriceAverageExample.java
...rg/nfsdb/examples/reporting/DailyPriceAverageExample.java
+4
-4
未找到文件。
nfsdb-core/pom.xml
浏览文件 @
a3c556ac
...
...
@@ -158,7 +158,6 @@
<version>
3.3.0
</version>
</dependency>
<!-- test dependencies -->
<dependency>
...
...
nfsdb-core/src/main/java/com/nfsdb/journal/Journal.java
浏览文件 @
a3c556ac
...
...
@@ -37,7 +37,10 @@ import com.nfsdb.journal.query.api.Query;
import
com.nfsdb.journal.query.spi.QueryImpl
;
import
com.nfsdb.journal.tx.Tx
;
import
com.nfsdb.journal.tx.TxLog
;
import
com.nfsdb.journal.utils.*
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Interval
;
import
com.nfsdb.journal.utils.Rows
;
import
com.nfsdb.journal.utils.Unsafe
;
import
java.io.Closeable
;
import
java.io.File
;
...
...
@@ -576,9 +579,9 @@ public class Journal<T> implements Iterable<T>, Closeable {
if
(
getMetadata
().
getPartitionType
()
!=
PartitionType
.
NONE
)
{
if
(
nonLagPartitionCount
()
>
0
)
{
Interval
lastPartitionInterval
=
partitions
.
get
(
nonLagPartitionCount
()
-
1
).
getInterval
();
interval
=
new
Interval
(
lastPartitionInterval
.
getLo
(),
Dates
2
.
addHours
(
lastPartitionInterval
.
getHi
(),
lag
));
interval
=
new
Interval
(
lastPartitionInterval
.
getLo
(),
Dates
.
addHours
(
lastPartitionInterval
.
getHi
(),
lag
));
}
else
{
interval
=
Dates
.
intervalForDate
(
System
.
currentTimeMillis
(),
getMetadata
().
getPartitionType
());
interval
=
new
Interval
(
System
.
currentTimeMillis
(),
getMetadata
().
getPartitionType
());
}
}
return
new
TempPartition
<>(
this
,
interval
,
nonLagPartitionCount
(),
name
);
...
...
@@ -689,7 +692,7 @@ public class Journal<T> implements Iterable<T>, Closeable {
indexTxAddresses
=
tx
.
indexPointers
;
}
Interval
interval
=
Dates
.
intervalForDirName
(
f
.
getName
(),
getMetadata
().
getPartitionType
());
Interval
interval
=
new
Interval
(
f
.
getName
(),
getMetadata
().
getPartitionType
());
if
(
partition
!=
null
)
{
if
(
partition
.
getInterval
()
==
null
||
partition
.
getInterval
().
equals
(
interval
))
{
partition
.
applyTx
(
txLimit
,
indexTxAddresses
);
...
...
nfsdb-core/src/main/java/com/nfsdb/journal/JournalWriter.java
浏览文件 @
a3c556ac
...
...
@@ -406,12 +406,12 @@ public class JournalWriter<T> extends Journal<T> {
if
(
result
.
getInterval
()
==
null
||
result
.
getInterval
().
contains
(
timestamp
))
{
return
result
.
open
().
access
();
}
else
if
(
result
.
getInterval
().
isBefore
(
timestamp
))
{
return
createPartition
(
Dates
.
intervalForDate
(
timestamp
,
getMetadata
().
getPartitionType
()),
sz
);
return
createPartition
(
new
Interval
(
timestamp
,
getMetadata
().
getPartitionType
()),
sz
);
}
else
{
throw
new
JournalException
(
"%s cannot be appended to %s"
,
Dates
.
toString
(
timestamp
),
this
);
}
}
else
{
return
createPartition
(
Dates
.
intervalForDate
(
timestamp
,
getMetadata
().
getPartitionType
()),
0
);
return
createPartition
(
new
Interval
(
timestamp
,
getMetadata
().
getPartitionType
()),
0
);
}
}
...
...
@@ -716,7 +716,7 @@ public class JournalWriter<T> extends Journal<T> {
if
(
getMetadata
().
getPartitionType
()
!=
PartitionType
.
NONE
)
{
throw
new
JournalException
(
"getAppendPartition() without timestamp on partitioned journal: %s"
,
this
);
}
return
appendPartition
=
createPartition
(
Dates
.
intervalForDate
(
0
,
getMetadata
().
getPartitionType
()),
0
);
return
appendPartition
=
createPartition
(
new
Interval
((
long
)
0
,
getMetadata
().
getPartitionType
()),
0
);
}
}
...
...
nfsdb-core/src/main/java/com/nfsdb/journal/Partition.java
浏览文件 @
a3c556ac
...
...
@@ -62,12 +62,7 @@ public class Partition<T> implements Iterable<T>, Closeable {
this
.
interval
=
interval
;
this
.
txLimit
=
txLimit
;
this
.
columnCount
=
journal
.
getMetadata
().
getColumnCount
();
String
dateStr
=
Dates
.
dirNameForIntervalStart
(
interval
,
journal
.
getMetadata
().
getPartitionType
());
if
(
dateStr
.
length
()
>
0
)
{
setPartitionDir
(
new
File
(
this
.
journal
.
getLocation
(),
dateStr
),
indexTxAddresses
);
}
else
{
setPartitionDir
(
this
.
journal
.
getLocation
(),
indexTxAddresses
);
}
setPartitionDir
(
new
File
(
this
.
journal
.
getLocation
(),
interval
.
getDirName
(
journal
.
getMetadata
().
getPartitionType
())),
indexTxAddresses
);
}
public
Partition
<
T
>
open
()
throws
JournalException
{
...
...
nfsdb-core/src/main/java/com/nfsdb/journal/SymbolIndexProxy.java
浏览文件 @
a3c556ac
...
...
@@ -35,6 +35,13 @@ class SymbolIndexProxy<T> implements Closeable {
private
long
lastAccessed
;
private
long
txAddress
;
SymbolIndexProxy
(
Partition
<
T
>
partition
,
int
columnIndex
,
long
txAddress
)
{
this
.
partition
=
partition
;
this
.
columnIndex
=
columnIndex
;
this
.
txAddress
=
txAddress
;
this
.
timerCache
=
partition
.
getJournal
().
getTimerCache
();
}
public
void
close
()
{
if
(
index
!=
null
)
{
LOGGER
.
trace
(
"Closing "
+
this
);
...
...
@@ -82,11 +89,4 @@ class SymbolIndexProxy<T> implements Closeable {
}
return
index
;
}
SymbolIndexProxy
(
Partition
<
T
>
partition
,
int
columnIndex
,
long
txAddress
)
{
this
.
partition
=
partition
;
this
.
columnIndex
=
columnIndex
;
this
.
txAddress
=
txAddress
;
this
.
timerCache
=
partition
.
getJournal
().
getTimerCache
();
}
}
nfsdb-core/src/main/java/com/nfsdb/journal/export/JournalEntryPrinter.java
浏览文件 @
a3c556ac
...
...
@@ -19,7 +19,7 @@ package com.nfsdb.journal.export;
import
com.nfsdb.journal.factory.configuration.ColumnMetadata
;
import
com.nfsdb.journal.lang.cst.EntrySource
;
import
com.nfsdb.journal.lang.cst.JournalEntry
;
import
com.nfsdb.journal.utils.Dates
2
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Numbers
;
public
class
JournalEntryPrinter
{
...
...
@@ -36,7 +36,7 @@ public class JournalEntryPrinter {
ColumnMetadata
m
=
e
.
partition
.
getJournal
().
getMetadata
().
getColumnMetadata
(
i
);
switch
(
m
.
type
)
{
case
DATE:
Dates
2
.
appendDateTime
(
sink
,
e
.
getLong
(
i
));
Dates
.
appendDateTime
(
sink
,
e
.
getLong
(
i
));
break
;
case
DOUBLE:
Numbers
.
append
(
sink
,
e
.
getDouble
(
i
),
12
);
...
...
nfsdb-core/src/main/java/com/nfsdb/journal/net/comsumer/JournalDeltaConsumer.java
浏览文件 @
a3c556ac
...
...
@@ -23,7 +23,6 @@ import com.nfsdb.journal.exceptions.JournalNetworkException;
import
com.nfsdb.journal.exceptions.JournalRuntimeException
;
import
com.nfsdb.journal.net.AbstractChannelConsumer
;
import
com.nfsdb.journal.net.model.JournalServerState
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Interval
;
import
com.nfsdb.journal.utils.Lists
;
...
...
@@ -163,7 +162,7 @@ public class JournalDeltaConsumer extends AbstractChannelConsumer {
for
(
int
i
=
0
;
i
<
metadata
.
getNonLagPartitionCount
();
i
++)
{
JournalServerState
.
PartitionMetadata
partitionMetadata
=
metadata
.
getMeta
(
i
);
if
(
partitionMetadata
.
getPartitionIndex
()
>=
pc
)
{
Interval
interval
=
Dates
.
interval
(
partitionMetadata
.
getIntervalStart
(),
partitionMetadata
.
getIntervalEnd
());
Interval
interval
=
new
Interval
(
partitionMetadata
.
getIntervalEnd
(),
partitionMetadata
.
getIntervalStart
());
journal
.
createPartition
(
interval
,
partitionMetadata
.
getPartitionIndex
());
}
}
...
...
nfsdb-core/src/main/java/com/nfsdb/journal/printer/converter/DateConverter.java
浏览文件 @
a3c556ac
...
...
@@ -18,7 +18,7 @@ package com.nfsdb.journal.printer.converter;
import
com.nfsdb.journal.export.StringSink
;
import
com.nfsdb.journal.printer.JournalPrinter
;
import
com.nfsdb.journal.utils.Dates
2
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Unsafe
;
public
class
DateConverter
extends
AbstractConverter
{
...
...
@@ -34,7 +34,7 @@ public class DateConverter extends AbstractConverter {
if
(
millis
==
0
)
{
stringBuilder
.
append
(
getPrinter
().
getNullString
());
}
else
{
Dates
2
.
appendDateTime
(
sink
,
millis
);
Dates
.
appendDateTime
(
sink
,
millis
);
stringBuilder
.
append
(
sink
);
sink
.
clear
();
}
...
...
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Dates.java
浏览文件 @
a3c556ac
...
...
@@ -16,109 +16,447 @@
package
com.nfsdb.journal.utils
;
import
com.nfsdb.journal.PartitionType
;
import
com.nfsdb.journal.exceptions.JournalUnsupportedTypeException
;
import
com.nfsdb.journal.export.CharSink
;
import
com.nfsdb.journal.export.StringSink
;
public
final
class
Dates
{
final
public
class
Dates
{
public
static
final
long
DAY_MILLIS
=
86400000L
;
public
static
final
long
AVG_YEAR_MILLIS
=
(
long
)
(
365.25
*
DAY_MILLIS
);
public
static
final
long
YEAR_MILLIS
=
365
*
DAY_MILLIS
;
public
static
final
long
LEAP_YEAR_MILLIS
=
366
*
DAY_MILLIS
;
public
static
final
long
HALF_YEAR_MILLIS
=
AVG_YEAR_MILLIS
/
2
;
public
static
final
long
EPOCH_MILLIS
=
1970L
*
AVG_YEAR_MILLIS
;
public
static
final
long
HALF_EPOCH_MILLIS
=
EPOCH_MILLIS
/
2
;
public
static
final
long
HOUR_MILLIS
=
3600000L
;
public
static
final
int
DAY_HOURS
=
24
;
public
static
final
int
HOUR_MINUTES
=
60
;
public
static
final
int
MINUTE_MILLIS
=
60000
;
public
static
final
int
SECOND_MILLIS
=
1000
;
public
static
final
int
MINUTE_SECONDS
=
60
;
private
static
final
int
DAYS_0000_TO_1970
=
719527
;
private
static
final
int
[]
DAYS_PER_MONTH
=
{
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
private
static
final
long
[]
MIN_MONTH_OF_YEAR_MILLIS
=
new
long
[
12
];
private
static
final
long
[]
MAX_MONTH_OF_YEAR_MILLIS
=
new
long
[
12
];
static
{
long
minSum
=
0
;
long
maxSum
=
0
;
for
(
int
i
=
0
;
i
<
11
;
i
++)
{
minSum
+=
DAYS_PER_MONTH
[
i
]
*
DAY_MILLIS
;
MIN_MONTH_OF_YEAR_MILLIS
[
i
+
1
]
=
minSum
;
maxSum
+=
getDaysPerMonth
(
i
+
1
,
true
)
*
DAY_MILLIS
;
MAX_MONTH_OF_YEAR_MILLIS
[
i
+
1
]
=
maxSum
;
}
}
private
Dates
()
{
}
// Prevent construction.
}
public
static
String
toString
(
long
millis
)
{
StringSink
sink
=
new
StringSink
();
Dates2
.
appendDateTime
(
sink
,
millis
);
return
sink
.
toString
();
/**
* Calculates if year is leap year using following algorithm:
* <p/>
* http://en.wikipedia.org/wiki/Leap_year
*
* @param year the year
* @return true if year is leap
*/
public
static
boolean
isLeapYear
(
int
year
)
{
return
((
year
&
3
)
==
0
)
&&
((
year
%
100
)
!=
0
||
(
year
%
400
)
==
0
);
}
public
static
Interval
interval
(
String
start
,
String
end
)
{
return
interval
(
toMillis
(
start
),
toMillis
(
end
));
/**
* Days in a given month. This method expects you to know if month is in leap year.
*
* @param m month from 1 to 12
* @param leap true if this is for leap year
* @return number of days in month.
*/
public
static
int
getDaysPerMonth
(
int
m
,
boolean
leap
)
{
return
leap
&
m
==
2
?
29
:
DAYS_PER_MONTH
[
m
-
1
];
}
public
static
Interval
interval
(
long
start
,
long
end
)
{
if
(
end
<
start
)
{
return
new
Interval
(
end
,
start
);
/**
* Calculated start of year in millis. For example of year 2008 this is
* equivalent to parsing "2008-01-01T00:00:00.000Z", except this method is faster.
*
* @param year the year
* @param leap true if give year is leap year
* @return millis for start of year.
*/
public
static
long
yearMillis
(
int
year
,
boolean
leap
)
{
int
leapYears
=
year
/
100
;
if
(
year
<
0
)
{
leapYears
=
((
year
+
3
)
>>
2
)
-
leapYears
+
((
leapYears
+
3
)
>>
2
)
-
1
;
}
else
{
return
new
Interval
(
start
,
end
);
leapYears
=
(
year
>>
2
)
-
leapYears
+
(
leapYears
>>
2
);
if
(
leap
)
{
leapYears
--;
}
}
return
(
year
*
365L
+
(
leapYears
-
DAYS_0000_TO_1970
))
*
DAY_MILLIS
;
}
/**
* Calculates year number from millis.
*
* @param millis time millis.
* @return year
*/
public
static
int
getYear
(
long
millis
)
{
long
mid
=
(
millis
>>
1
)
+
HALF_EPOCH_MILLIS
;
if
(
mid
<
0
)
{
mid
=
mid
-
HALF_YEAR_MILLIS
+
1
;
}
int
year
=
(
int
)
(
mid
/
HALF_YEAR_MILLIS
);
boolean
leap
=
isLeapYear
(
year
);
long
yearStart
=
yearMillis
(
year
,
leap
);
long
diff
=
millis
-
yearStart
;
if
(
diff
<
0
)
{
year
--;
}
else
if
(
diff
>=
YEAR_MILLIS
)
{
yearStart
+=
leap
?
LEAP_YEAR_MILLIS
:
YEAR_MILLIS
;
if
(
yearStart
<=
millis
)
{
year
++;
}
}
return
year
;
}
/**
* Calculates month of year from absolute millis.
*
* @param millis millis since 1970
* @param year year of month
* @param leap true if year was leap
* @return month of year
*/
public
static
int
getMonthOfYear
(
long
millis
,
int
year
,
boolean
leap
)
{
int
i
=
(
int
)
((
millis
-
yearMillis
(
year
,
leap
))
>>
10
);
return
leap
?
((
i
<
182
*
84375
)
?
((
i
<
91
*
84375
)
?
((
i
<
31
*
84375
)
?
1
:
(
i
<
60
*
84375
)
?
2
:
3
)
:
((
i
<
121
*
84375
)
?
4
:
(
i
<
152
*
84375
)
?
5
:
6
))
:
((
i
<
274
*
84375
)
?
((
i
<
213
*
84375
)
?
7
:
(
i
<
244
*
84375
)
?
8
:
9
)
:
((
i
<
305
*
84375
)
?
10
:
(
i
<
335
*
84375
)
?
11
:
12
)))
:
((
i
<
181
*
84375
)
?
((
i
<
90
*
84375
)
?
((
i
<
31
*
84375
)
?
1
:
(
i
<
59
*
84375
)
?
2
:
3
)
:
((
i
<
120
*
84375
)
?
4
:
(
i
<
151
*
84375
)
?
5
:
6
))
:
((
i
<
273
*
84375
)
?
((
i
<
212
*
84375
)
?
7
:
(
i
<
243
*
84375
)
?
8
:
9
)
:
((
i
<
304
*
84375
)
?
10
:
(
i
<
334
*
84375
)
?
11
:
12
)));
}
public
static
long
toMillis
(
String
date
)
{
return
Dates2
.
parseDateTime
(
date
)
;
public
static
long
monthOfYearMillis
(
int
month
,
boolean
leap
)
{
return
leap
?
MAX_MONTH_OF_YEAR_MILLIS
[
month
-
1
]
:
MIN_MONTH_OF_YEAR_MILLIS
[
month
-
1
]
;
}
public
static
Interval
lastMonth
()
{
long
millis
=
System
.
currentTimeMillis
();
return
new
Interval
(
millis
-
30
*
Dates2
.
DAY_MILLIS
,
millis
);
public
static
int
getDayOfMonth
(
long
millis
,
int
year
,
int
month
,
boolean
leap
)
{
long
dateMillis
=
yearMillis
(
year
,
leap
);
dateMillis
+=
monthOfYearMillis
(
month
,
leap
);
return
(
int
)
((
millis
-
dateMillis
)
/
DAY_MILLIS
)
+
1
;
}
public
static
Interval
intervalForDirName
(
String
name
,
PartitionType
partitionType
)
{
switch
(
partitionType
)
{
case
YEAR:
return
intervalForDate
(
Dates2
.
parseDateTime
(
name
+
"-01-01T00:00:00.000Z"
),
partitionType
);
case
MONTH:
return
intervalForDate
(
Dates2
.
parseDateTime
(
name
+
"-01T00:00:00.000Z"
),
partitionType
);
case
DAY:
return
intervalForDate
(
Dates2
.
parseDateTime
(
name
+
"T00:00:00.000Z"
),
partitionType
);
case
NONE:
if
(
"default"
.
equals
(
name
))
{
return
new
Interval
(
0
,
Long
.
MAX_VALUE
);
}
default
:
throw
new
JournalUnsupportedTypeException
(
partitionType
);
public
static
int
getHourOfDay
(
long
millis
)
{
if
(
millis
>=
0
)
{
return
(
int
)
((
millis
/
HOUR_MILLIS
)
%
DAY_HOURS
);
}
else
{
return
DAY_HOURS
-
1
+
(
int
)
(((
millis
+
1
)
/
HOUR_MILLIS
)
%
DAY_HOURS
);
}
}
public
static
Interval
intervalForDate
(
long
timestamp
,
PartitionType
partitionType
)
{
switch
(
partitionType
)
{
case
NONE:
return
new
Interval
(
0
,
Long
.
MAX_VALUE
);
default
:
long
lo
=
intervalStart
(
timestamp
,
partitionType
);
long
hi
=
intervalEnd
(
lo
,
partitionType
);
return
new
Interval
(
lo
,
hi
);
public
static
int
getMinuteOfHour
(
long
millis
)
{
if
(
millis
>=
0
)
{
return
(
int
)
((
millis
/
MINUTE_MILLIS
)
%
HOUR_MINUTES
);
}
else
{
return
HOUR_MINUTES
-
1
+
(
int
)
(((
millis
+
1
)
/
MINUTE_MILLIS
)
%
HOUR_MINUTES
);
}
}
public
static
String
dirNameForIntervalStart
(
Interval
interval
,
PartitionType
partitionType
)
{
StringSink
sink
=
new
StringSink
();
switch
(
partitionType
)
{
case
YEAR:
Dates2
.
appendYear
(
sink
,
interval
.
getLo
());
break
;
case
MONTH:
Dates2
.
appendCalDate2
(
sink
,
interval
.
getLo
());
break
;
case
DAY:
Dates2
.
appendCalDate1
(
sink
,
interval
.
getLo
());
break
;
case
NONE:
return
"default"
;
public
static
int
getSecondOfMinute
(
long
millis
)
{
if
(
millis
>=
0
)
{
return
(
int
)
((
millis
/
SECOND_MILLIS
)
%
MINUTE_SECONDS
);
}
else
{
return
MINUTE_SECONDS
-
1
+
(
int
)
(((
millis
+
1
)
/
SECOND_MILLIS
)
%
MINUTE_SECONDS
);
}
}
public
static
int
getMillisOfSecond
(
long
millis
)
{
if
(
millis
>=
0
)
{
return
(
int
)
(
millis
%
1000
);
}
else
{
return
1000
-
1
+
(
int
)
((
millis
+
1
)
%
1000
);
}
}
// YYYY-MM-DDThh:mm:ss.mmmmZ
public
static
void
appendDateTime
(
CharSink
sink
,
long
millis
)
{
int
y
=
getYear
(
millis
);
boolean
l
=
isLeapYear
(
y
);
int
m
=
getMonthOfYear
(
millis
,
y
,
l
);
append0000
(
sink
,
y
);
append0
(
sink
.
put
(
'-'
),
m
);
append0
(
sink
.
put
(
'-'
),
getDayOfMonth
(
millis
,
y
,
m
,
l
));
append0
(
sink
.
put
(
'T'
),
getHourOfDay
(
millis
));
append0
(
sink
.
put
(
':'
),
getMinuteOfHour
(
millis
));
append0
(
sink
.
put
(
':'
),
getSecondOfMinute
(
millis
));
append00
(
sink
.
put
(
"."
),
getMillisOfSecond
(
millis
));
sink
.
put
(
"Z"
);
}
// YYYY-MM-DD
public
static
void
formatDashYYYYMMDD
(
CharSink
sink
,
long
millis
)
{
int
y
=
getYear
(
millis
);
boolean
l
=
isLeapYear
(
y
);
int
m
=
getMonthOfYear
(
millis
,
y
,
l
);
Numbers
.
append
(
sink
,
y
);
append0
(
sink
.
put
(
'-'
),
m
);
append0
(
sink
.
put
(
'-'
),
getDayOfMonth
(
millis
,
y
,
m
,
l
));
}
// YYYY-MM
public
static
void
formatYYYYMM
(
CharSink
sink
,
long
millis
)
{
int
y
=
getYear
(
millis
);
int
m
=
getMonthOfYear
(
millis
,
y
,
isLeapYear
(
y
));
Numbers
.
append
(
sink
,
y
);
append0
(
sink
.
put
(
'-'
),
m
);
}
// YYYYMMDD
public
static
void
formatYYYYMMDD
(
CharSink
sink
,
long
millis
)
{
int
y
=
getYear
(
millis
);
boolean
l
=
isLeapYear
(
y
);
int
m
=
getMonthOfYear
(
millis
,
y
,
l
);
Numbers
.
append
(
sink
,
y
);
append0
(
sink
,
m
);
append0
(
sink
,
getDayOfMonth
(
millis
,
y
,
m
,
l
));
}
// YYYY
public
static
void
formatYYYY
(
CharSink
sink
,
long
millis
)
{
Numbers
.
append
(
sink
,
getYear
(
millis
));
}
private
static
CharSink
append0
(
CharSink
sink
,
int
val
)
{
if
(
val
<
10
)
{
sink
.
put
(
'0'
);
}
Numbers
.
append
(
sink
,
val
);
return
sink
;
}
private
static
CharSink
append00
(
CharSink
sink
,
int
val
)
{
if
(
val
<
10
)
{
sink
.
put
(
'0'
).
put
(
'0'
);
}
else
if
(
val
<
100
)
{
sink
.
put
(
'0'
);
}
Numbers
.
append
(
sink
,
val
);
return
sink
;
}
private
static
CharSink
append0000
(
CharSink
sink
,
int
val
)
{
if
(
val
<
10
)
{
sink
.
put
(
'0'
).
put
(
'0'
).
put
(
'0'
);
}
else
if
(
val
<
100
)
{
sink
.
put
(
'0'
).
put
(
'0'
);
}
else
if
(
val
<
1000
)
{
sink
.
put
(
'0'
);
}
Numbers
.
append
(
sink
,
val
);
return
sink
;
}
private
static
void
checkChar
(
CharSequence
s
,
int
p
,
char
c
)
{
if
(
s
.
charAt
(
p
)
!=
c
)
{
throw
new
NumberFormatException
(
"Expected "
+
c
+
" at "
+
p
);
}
return
sink
.
toString
();
}
private
static
long
intervalStart
(
long
timestamp
,
PartitionType
partitionType
)
{
switch
(
partitionType
)
{
case
YEAR:
return
Dates2
.
floorYYYY
(
timestamp
);
case
MONTH:
return
Dates2
.
floorMM
(
timestamp
);
case
DAY:
return
Dates2
.
floorDD
(
timestamp
);
private
static
void
checkRange
(
int
x
,
int
min
,
int
max
,
String
what
)
{
if
(
x
<
min
||
x
>
max
)
{
throw
new
NumberFormatException
(
what
+
" not in range: "
+
x
);
}
return
0
;
}
private
static
long
intervalEnd
(
long
start
,
PartitionType
partitionType
)
{
switch
(
partitionType
)
{
case
YEAR:
return
Dates2
.
ceilYYYY
(
start
);
case
MONTH:
return
Dates2
.
ceilMM
(
start
);
case
DAY:
return
Dates2
.
ceilDD
(
start
);
// YYYY-MM-DDThh:mm:ss.mmm
public
static
long
parseDateTime
(
CharSequence
seq
)
{
int
p
=
0
;
int
year
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
4
);
checkChar
(
seq
,
p
++,
'-'
);
int
month
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
month
,
1
,
12
,
"Month"
);
checkChar
(
seq
,
p
++,
'-'
);
boolean
l
=
isLeapYear
(
year
);
int
day
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
day
,
1
,
getDaysPerMonth
(
month
,
l
),
"Day"
);
checkChar
(
seq
,
p
++,
'T'
);
int
hour
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
hour
,
0
,
23
,
"Hour"
);
checkChar
(
seq
,
p
++,
':'
);
int
min
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
min
,
0
,
59
,
"Minute"
);
checkChar
(
seq
,
p
++,
':'
);
int
sec
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
sec
,
0
,
59
,
"Second"
);
int
mil
=
0
;
if
(
seq
.
charAt
(
p
)
==
'.'
)
{
mil
=
Numbers
.
parseInt
(
seq
,
++
p
,
p
+=
3
);
checkRange
(
mil
,
0
,
999
,
"Millis"
);
}
if
(
p
<
seq
.
length
())
{
checkChar
(
seq
,
p
,
'Z'
);
}
return
0
;
return
yearMillis
(
year
,
l
)
+
monthOfYearMillis
(
month
,
l
)
+
(
day
-
1
)
*
DAY_MILLIS
+
hour
*
HOUR_MILLIS
+
min
*
MINUTE_MILLIS
+
sec
*
SECOND_MILLIS
+
mil
;
}
public
static
long
floorYYYY
(
long
millis
)
{
int
y
;
return
yearMillis
(
y
=
getYear
(
millis
),
isLeapYear
(
y
));
}
public
static
long
floorMM
(
long
millis
)
{
int
y
;
boolean
l
;
return
yearMillis
(
y
=
getYear
(
millis
),
l
=
isLeapYear
(
y
))
+
monthOfYearMillis
(
getMonthOfYear
(
millis
,
y
,
l
),
l
);
}
public
static
long
floorDD
(
long
millis
)
{
return
millis
-
getTime
(
millis
);
}
public
static
long
floorHH
(
long
millis
)
{
return
millis
-
millis
%
HOUR_MILLIS
;
}
public
static
long
ceilYYYY
(
long
millis
)
{
int
y
;
boolean
l
;
return
yearMillis
(
y
=
getYear
(
millis
),
l
=
isLeapYear
(
y
))
+
monthOfYearMillis
(
12
,
l
)
+
(
DAYS_PER_MONTH
[
11
]
-
1
)
*
DAY_MILLIS
+
23
*
HOUR_MILLIS
+
59
*
MINUTE_MILLIS
+
59
*
SECOND_MILLIS
+
999L
;
}
public
static
long
ceilMM
(
long
millis
)
{
int
y
,
m
;
boolean
l
;
return
yearMillis
(
y
=
getYear
(
millis
),
l
=
isLeapYear
(
y
))
+
monthOfYearMillis
(
m
=
getMonthOfYear
(
millis
,
y
,
l
),
l
)
+
(
getDaysPerMonth
(
m
,
l
)
-
1
)
*
DAY_MILLIS
+
23
*
HOUR_MILLIS
+
59
*
MINUTE_MILLIS
+
59
*
SECOND_MILLIS
+
999L
;
}
public
static
long
ceilDD
(
long
millis
)
{
int
y
,
m
;
boolean
l
;
return
yearMillis
(
y
=
getYear
(
millis
),
l
=
isLeapYear
(
y
))
+
monthOfYearMillis
(
m
=
getMonthOfYear
(
millis
,
y
,
l
),
l
)
+
(
getDayOfMonth
(
millis
,
y
,
m
,
l
)
-
1
)
*
DAY_MILLIS
+
23
*
HOUR_MILLIS
+
59
*
MINUTE_MILLIS
+
59
*
SECOND_MILLIS
+
999L
;
}
public
static
long
toMillis
(
int
y
,
int
m
,
int
d
)
{
boolean
l
=
isLeapYear
(
y
);
return
yearMillis
(
y
,
l
)
+
monthOfYearMillis
(
m
,
l
)
+
(
d
-
1
)
*
DAY_MILLIS
;
}
}
public
static
long
toMillis
(
int
y
,
int
m
,
int
d
,
int
h
,
int
mi
)
{
boolean
l
=
isLeapYear
(
y
);
return
yearMillis
(
y
,
l
)
+
monthOfYearMillis
(
m
,
l
)
+
(
d
-
1
)
*
DAY_MILLIS
+
h
*
HOUR_MILLIS
+
mi
*
MINUTE_MILLIS
;
}
public
static
long
getTime
(
long
millis
)
{
return
millis
<
0
?
DAY_MILLIS
-
1
+
(
millis
%
DAY_MILLIS
)
:
millis
%
DAY_MILLIS
;
}
public
static
long
addMonths
(
final
long
millis
,
int
months
)
{
if
(
months
==
0
)
{
return
millis
;
}
boolean
l
;
int
y
=
getYear
(
millis
);
int
m
=
getMonthOfYear
(
millis
,
y
,
l
=
isLeapYear
(
y
));
int
_y
;
int
_m
=
m
-
1
+
months
;
if
(
_m
>=
0
)
{
_y
=
y
+
_m
/
12
;
_m
=
(
_m
%
12
)
+
1
;
}
else
{
_y
=
y
+
_m
/
12
-
1
;
_m
=
-
_m
%
12
;
if
(
_m
==
0
)
{
_m
=
12
;
}
_m
=
12
-
_m
+
1
;
if
(
_m
==
1
)
{
_y
+=
1
;
}
}
int
_d
=
getDayOfMonth
(
millis
,
y
,
m
,
l
);
int
maxDay
=
getDaysPerMonth
(
_m
,
isLeapYear
(
_y
));
if
(
_d
>
maxDay
)
{
_d
=
maxDay
;
}
return
toMillis
(
_y
,
_m
,
_d
)
+
getTime
(
millis
)
+
(
millis
<
0
?
1
:
0
);
}
public
static
long
addYear
(
long
millis
,
int
years
)
{
if
(
years
==
0
)
{
return
millis
;
}
int
y
,
m
;
boolean
l
;
return
yearMillis
((
y
=
getYear
(
millis
))
+
years
,
l
=
isLeapYear
(
y
+
years
))
+
monthOfYearMillis
(
m
=
getMonthOfYear
(
millis
,
y
,
l
),
l
)
+
(
getDayOfMonth
(
millis
,
y
,
m
,
l
)
-
1
)
*
DAY_MILLIS
+
getTime
(
millis
)
+
(
millis
<
0
?
1
:
0
);
}
public
static
long
addDays
(
long
millis
,
int
days
)
{
return
millis
+
days
*
DAY_MILLIS
;
}
public
static
long
addHours
(
long
millis
,
int
hours
)
{
return
millis
+
hours
*
HOUR_MILLIS
;
}
public
static
String
toString
(
long
millis
)
{
StringSink
sink
=
new
StringSink
();
Dates
.
appendDateTime
(
sink
,
millis
);
return
sink
.
toString
();
}
}
\ No newline at end of file
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Dates2.java
已删除
100644 → 0
浏览文件 @
b83e9643
/*
* Copyright (c) 2014-2015. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
com.nfsdb.journal.utils
;
import
com.nfsdb.journal.export.CharSink
;
final
public
class
Dates2
{
public
static
final
long
DAY_MILLIS
=
86400000L
;
public
static
final
long
AVG_YEAR_MILLIS
=
(
long
)
(
365.25
*
DAY_MILLIS
);
public
static
final
long
YEAR_MILLIS
=
365
*
DAY_MILLIS
;
public
static
final
long
LEAP_YEAR_MILLIS
=
366
*
DAY_MILLIS
;
public
static
final
long
HALF_YEAR_MILLIS
=
AVG_YEAR_MILLIS
/
2
;
public
static
final
long
EPOCH_MILLIS
=
1970L
*
AVG_YEAR_MILLIS
;
public
static
final
long
HALF_EPOCH_MILLIS
=
EPOCH_MILLIS
/
2
;
public
static
final
long
HOUR_MILLIS
=
3600000L
;
public
static
final
int
DAY_HOURS
=
24
;
public
static
final
int
HOUR_MINUTES
=
60
;
public
static
final
int
MINUTE_MILLIS
=
60000
;
public
static
final
int
SECOND_MILLIS
=
1000
;
public
static
final
int
MINUTE_SECONDS
=
60
;
private
static
final
int
DAYS_0000_TO_1970
=
719527
;
private
static
final
int
[]
DAYS_PER_MONTH
=
{
31
,
28
,
31
,
30
,
31
,
30
,
31
,
31
,
30
,
31
,
30
,
31
};
private
static
final
long
[]
MIN_MONTH_OF_YEAR_MILLIS
=
new
long
[
12
];
private
static
final
long
[]
MAX_MONTH_OF_YEAR_MILLIS
=
new
long
[
12
];
static
{
long
minSum
=
0
;
long
maxSum
=
0
;
for
(
int
i
=
0
;
i
<
11
;
i
++)
{
minSum
+=
DAYS_PER_MONTH
[
i
]
*
DAY_MILLIS
;
MIN_MONTH_OF_YEAR_MILLIS
[
i
+
1
]
=
minSum
;
maxSum
+=
getDaysPerMonth
(
i
+
1
,
true
)
*
DAY_MILLIS
;
MAX_MONTH_OF_YEAR_MILLIS
[
i
+
1
]
=
maxSum
;
}
}
private
Dates2
()
{
}
public
static
boolean
isLeapYear
(
int
year
)
{
return
((
year
&
3
)
==
0
)
&&
((
year
%
100
)
!=
0
||
(
year
%
400
)
==
0
);
}
public
static
int
getDaysPerMonth
(
int
m
,
boolean
leap
)
{
return
leap
&
m
==
2
?
29
:
DAYS_PER_MONTH
[
m
-
1
];
}
public
static
long
yearMillis
(
int
year
,
boolean
leap
)
{
int
leapYears
=
year
/
100
;
if
(
year
<
0
)
{
leapYears
=
((
year
+
3
)
>>
2
)
-
leapYears
+
((
leapYears
+
3
)
>>
2
)
-
1
;
}
else
{
leapYears
=
(
year
>>
2
)
-
leapYears
+
(
leapYears
>>
2
);
if
(
leap
)
{
leapYears
--;
}
}
return
(
year
*
365L
+
(
leapYears
-
DAYS_0000_TO_1970
))
*
DAY_MILLIS
;
}
public
static
int
getYear
(
long
millis
)
{
long
mid
=
(
millis
>>
1
)
+
HALF_EPOCH_MILLIS
;
if
(
mid
<
0
)
{
mid
=
mid
-
HALF_YEAR_MILLIS
+
1
;
}
int
year
=
(
int
)
(
mid
/
HALF_YEAR_MILLIS
);
boolean
leap
=
isLeapYear
(
year
);
long
yearStart
=
yearMillis
(
year
,
leap
);
long
diff
=
millis
-
yearStart
;
if
(
diff
<
0
)
{
year
--;
}
else
if
(
diff
>=
YEAR_MILLIS
)
{
yearStart
+=
leap
?
LEAP_YEAR_MILLIS
:
YEAR_MILLIS
;
if
(
yearStart
<=
millis
)
{
year
++;
}
}
return
year
;
}
public
static
int
getMonthOfYear
(
long
millis
,
int
year
,
boolean
leap
)
{
int
i
=
(
int
)
((
millis
-
yearMillis
(
year
,
leap
))
>>
10
);
return
leap
?
((
i
<
182
*
84375
)
?
((
i
<
91
*
84375
)
?
((
i
<
31
*
84375
)
?
1
:
(
i
<
60
*
84375
)
?
2
:
3
)
:
((
i
<
121
*
84375
)
?
4
:
(
i
<
152
*
84375
)
?
5
:
6
))
:
((
i
<
274
*
84375
)
?
((
i
<
213
*
84375
)
?
7
:
(
i
<
244
*
84375
)
?
8
:
9
)
:
((
i
<
305
*
84375
)
?
10
:
(
i
<
335
*
84375
)
?
11
:
12
)))
:
((
i
<
181
*
84375
)
?
((
i
<
90
*
84375
)
?
((
i
<
31
*
84375
)
?
1
:
(
i
<
59
*
84375
)
?
2
:
3
)
:
((
i
<
120
*
84375
)
?
4
:
(
i
<
151
*
84375
)
?
5
:
6
))
:
((
i
<
273
*
84375
)
?
((
i
<
212
*
84375
)
?
7
:
(
i
<
243
*
84375
)
?
8
:
9
)
:
((
i
<
304
*
84375
)
?
10
:
(
i
<
334
*
84375
)
?
11
:
12
)));
}
public
static
long
monthOfYearMillis
(
int
month
,
boolean
leap
)
{
return
leap
?
MAX_MONTH_OF_YEAR_MILLIS
[
month
-
1
]
:
MIN_MONTH_OF_YEAR_MILLIS
[
month
-
1
];
}
public
static
int
getDayOfMonth
(
long
millis
,
int
year
,
int
month
,
boolean
leap
)
{
long
dateMillis
=
yearMillis
(
year
,
leap
);
dateMillis
+=
monthOfYearMillis
(
month
,
leap
);
return
(
int
)
((
millis
-
dateMillis
)
/
DAY_MILLIS
)
+
1
;
}
public
static
int
getHourOfDay
(
long
millis
)
{
if
(
millis
>=
0
)
{
return
(
int
)
((
millis
/
HOUR_MILLIS
)
%
DAY_HOURS
);
}
else
{
return
DAY_HOURS
-
1
+
(
int
)
(((
millis
+
1
)
/
HOUR_MILLIS
)
%
DAY_HOURS
);
}
}
public
static
int
getMinuteOfHour
(
long
millis
)
{
if
(
millis
>=
0
)
{
return
(
int
)
((
millis
/
MINUTE_MILLIS
)
%
HOUR_MINUTES
);
}
else
{
return
HOUR_MINUTES
-
1
+
(
int
)
(((
millis
+
1
)
/
MINUTE_MILLIS
)
%
HOUR_MINUTES
);
}
}
public
static
int
getSecondOfMinute
(
long
millis
)
{
if
(
millis
>=
0
)
{
return
(
int
)
((
millis
/
SECOND_MILLIS
)
%
MINUTE_SECONDS
);
}
else
{
return
MINUTE_SECONDS
-
1
+
(
int
)
(((
millis
+
1
)
/
SECOND_MILLIS
)
%
MINUTE_SECONDS
);
}
}
public
static
int
getMillisOfSecond
(
long
millis
)
{
if
(
millis
>=
0
)
{
return
(
int
)
(
millis
%
1000
);
}
else
{
return
1000
-
1
+
(
int
)
((
millis
+
1
)
%
1000
);
}
}
// YYYY-MM-DDThh:mm:ss.mmmmZ
public
static
void
appendDateTime
(
CharSink
sink
,
long
millis
)
{
int
y
=
getYear
(
millis
);
boolean
l
=
isLeapYear
(
y
);
int
m
=
getMonthOfYear
(
millis
,
y
,
l
);
append0000
(
sink
,
y
);
append0
(
sink
.
put
(
'-'
),
m
);
append0
(
sink
.
put
(
'-'
),
getDayOfMonth
(
millis
,
y
,
m
,
l
));
append0
(
sink
.
put
(
'T'
),
getHourOfDay
(
millis
));
append0
(
sink
.
put
(
':'
),
getMinuteOfHour
(
millis
));
append0
(
sink
.
put
(
':'
),
getSecondOfMinute
(
millis
));
append00
(
sink
.
put
(
"."
),
getMillisOfSecond
(
millis
));
sink
.
put
(
"Z"
);
}
// YYYY-MM-DD
public
static
void
appendCalDate1
(
CharSink
sink
,
long
millis
)
{
int
y
=
getYear
(
millis
);
boolean
l
=
isLeapYear
(
y
);
int
m
=
getMonthOfYear
(
millis
,
y
,
l
);
Numbers
.
append
(
sink
,
y
);
append0
(
sink
.
put
(
'-'
),
m
);
append0
(
sink
.
put
(
'-'
),
getDayOfMonth
(
millis
,
y
,
m
,
l
));
}
// YYYY-MM
public
static
void
appendCalDate2
(
CharSink
sink
,
long
millis
)
{
int
y
=
getYear
(
millis
);
int
m
=
getMonthOfYear
(
millis
,
y
,
isLeapYear
(
y
));
Numbers
.
append
(
sink
,
y
);
append0
(
sink
.
put
(
'-'
),
m
);
}
// YYYYMMDD
public
static
void
appendCalDate3
(
CharSink
sink
,
long
millis
)
{
int
y
=
getYear
(
millis
);
boolean
l
=
isLeapYear
(
y
);
int
m
=
getMonthOfYear
(
millis
,
y
,
l
);
Numbers
.
append
(
sink
,
y
);
append0
(
sink
,
m
);
append0
(
sink
,
getDayOfMonth
(
millis
,
y
,
m
,
l
));
}
// YYYY
public
static
void
appendYear
(
CharSink
sink
,
long
millis
)
{
Numbers
.
append
(
sink
,
getYear
(
millis
));
}
private
static
CharSink
append0
(
CharSink
sink
,
int
val
)
{
if
(
val
<
10
)
{
sink
.
put
(
'0'
);
}
Numbers
.
append
(
sink
,
val
);
return
sink
;
}
private
static
CharSink
append00
(
CharSink
sink
,
int
val
)
{
if
(
val
<
10
)
{
sink
.
put
(
'0'
).
put
(
'0'
);
}
else
if
(
val
<
100
)
{
sink
.
put
(
'0'
);
}
Numbers
.
append
(
sink
,
val
);
return
sink
;
}
private
static
CharSink
append0000
(
CharSink
sink
,
int
val
)
{
if
(
val
<
10
)
{
sink
.
put
(
'0'
).
put
(
'0'
).
put
(
'0'
);
}
else
if
(
val
<
100
)
{
sink
.
put
(
'0'
).
put
(
'0'
);
}
else
if
(
val
<
1000
)
{
sink
.
put
(
'0'
);
}
Numbers
.
append
(
sink
,
val
);
return
sink
;
}
private
static
void
checkChar
(
CharSequence
s
,
int
p
,
char
c
)
{
if
(
s
.
charAt
(
p
)
!=
c
)
{
throw
new
NumberFormatException
(
"Expected "
+
c
+
" at "
+
p
);
}
}
private
static
void
checkRange
(
int
x
,
int
min
,
int
max
,
String
what
)
{
if
(
x
<
min
||
x
>
max
)
{
throw
new
NumberFormatException
(
what
+
" not in range: "
+
x
);
}
}
// YYYY-MM-DDThh:mm:ss.mmm
public
static
long
parseDateTime
(
CharSequence
seq
)
{
int
p
=
0
;
int
year
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
4
);
checkChar
(
seq
,
p
++,
'-'
);
int
month
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
month
,
1
,
12
,
"Month"
);
checkChar
(
seq
,
p
++,
'-'
);
boolean
l
=
isLeapYear
(
year
);
int
day
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
day
,
1
,
getDaysPerMonth
(
month
,
l
),
"Day"
);
checkChar
(
seq
,
p
++,
'T'
);
int
hour
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
hour
,
0
,
23
,
"Hour"
);
checkChar
(
seq
,
p
++,
':'
);
int
min
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
min
,
0
,
59
,
"Minute"
);
checkChar
(
seq
,
p
++,
':'
);
int
sec
=
Numbers
.
parseInt
(
seq
,
p
,
p
+=
2
);
checkRange
(
sec
,
0
,
59
,
"Second"
);
int
mil
=
0
;
if
(
seq
.
charAt
(
p
)
==
'.'
)
{
mil
=
Numbers
.
parseInt
(
seq
,
++
p
,
p
+=
3
);
checkRange
(
mil
,
0
,
999
,
"Millis"
);
}
if
(
p
<
seq
.
length
())
{
checkChar
(
seq
,
p
,
'Z'
);
}
return
yearMillis
(
year
,
l
)
+
monthOfYearMillis
(
month
,
l
)
+
(
day
-
1
)
*
DAY_MILLIS
+
hour
*
HOUR_MILLIS
+
min
*
MINUTE_MILLIS
+
sec
*
SECOND_MILLIS
+
mil
;
}
public
static
long
floorYYYY
(
long
millis
)
{
int
y
;
return
yearMillis
(
y
=
getYear
(
millis
),
isLeapYear
(
y
));
}
public
static
long
floorMM
(
long
millis
)
{
int
y
;
boolean
l
;
return
yearMillis
(
y
=
getYear
(
millis
),
l
=
isLeapYear
(
y
))
+
monthOfYearMillis
(
getMonthOfYear
(
millis
,
y
,
l
),
l
);
}
public
static
long
floorDD
(
long
millis
)
{
return
millis
-
getTime
(
millis
);
}
public
static
long
floorHH
(
long
millis
)
{
return
millis
-
millis
%
HOUR_MILLIS
;
}
public
static
long
ceilYYYY
(
long
millis
)
{
int
y
;
boolean
l
;
return
yearMillis
(
y
=
getYear
(
millis
),
l
=
isLeapYear
(
y
))
+
monthOfYearMillis
(
12
,
l
)
+
(
DAYS_PER_MONTH
[
11
]
-
1
)
*
DAY_MILLIS
+
23
*
HOUR_MILLIS
+
59
*
MINUTE_MILLIS
+
59
*
SECOND_MILLIS
+
999L
;
}
public
static
long
ceilMM
(
long
millis
)
{
int
y
,
m
;
boolean
l
;
return
yearMillis
(
y
=
getYear
(
millis
),
l
=
isLeapYear
(
y
))
+
monthOfYearMillis
(
m
=
getMonthOfYear
(
millis
,
y
,
l
),
l
)
+
(
getDaysPerMonth
(
m
,
l
)
-
1
)
*
DAY_MILLIS
+
23
*
HOUR_MILLIS
+
59
*
MINUTE_MILLIS
+
59
*
SECOND_MILLIS
+
999L
;
}
public
static
long
ceilDD
(
long
millis
)
{
int
y
,
m
;
boolean
l
;
return
yearMillis
(
y
=
getYear
(
millis
),
l
=
isLeapYear
(
y
))
+
monthOfYearMillis
(
m
=
getMonthOfYear
(
millis
,
y
,
l
),
l
)
+
(
getDayOfMonth
(
millis
,
y
,
m
,
l
)
-
1
)
*
DAY_MILLIS
+
23
*
HOUR_MILLIS
+
59
*
MINUTE_MILLIS
+
59
*
SECOND_MILLIS
+
999L
;
}
public
static
long
toMillis
(
int
y
,
int
m
,
int
d
)
{
boolean
l
=
isLeapYear
(
y
);
return
yearMillis
(
y
,
l
)
+
monthOfYearMillis
(
m
,
l
)
+
(
d
-
1
)
*
DAY_MILLIS
;
}
public
static
long
toMillis
(
int
y
,
int
m
,
int
d
,
int
h
,
int
mi
)
{
boolean
l
=
isLeapYear
(
y
);
return
yearMillis
(
y
,
l
)
+
monthOfYearMillis
(
m
,
l
)
+
(
d
-
1
)
*
DAY_MILLIS
+
h
*
HOUR_MILLIS
+
mi
*
MINUTE_MILLIS
;
}
public
static
long
getTime
(
long
millis
)
{
return
millis
<
0
?
DAY_MILLIS
-
1
+
(
millis
%
DAY_MILLIS
)
:
millis
%
DAY_MILLIS
;
}
public
static
long
addMonths
(
final
long
millis
,
int
months
)
{
if
(
months
==
0
)
{
return
millis
;
}
boolean
l
;
int
y
=
getYear
(
millis
);
int
m
=
getMonthOfYear
(
millis
,
y
,
l
=
isLeapYear
(
y
));
int
_y
;
int
_m
=
m
-
1
+
months
;
if
(
_m
>=
0
)
{
_y
=
y
+
_m
/
12
;
_m
=
(
_m
%
12
)
+
1
;
}
else
{
_y
=
y
+
_m
/
12
-
1
;
_m
=
-
_m
%
12
;
if
(
_m
==
0
)
{
_m
=
12
;
}
_m
=
12
-
_m
+
1
;
if
(
_m
==
1
)
{
_y
+=
1
;
}
}
int
_d
=
getDayOfMonth
(
millis
,
y
,
m
,
l
);
int
maxDay
=
getDaysPerMonth
(
_m
,
isLeapYear
(
_y
));
if
(
_d
>
maxDay
)
{
_d
=
maxDay
;
}
return
toMillis
(
_y
,
_m
,
_d
)
+
getTime
(
millis
)
+
(
millis
<
0
?
1
:
0
);
}
public
static
long
addYear
(
long
millis
,
int
years
)
{
if
(
years
==
0
)
{
return
millis
;
}
int
y
,
m
;
boolean
l
;
return
yearMillis
((
y
=
getYear
(
millis
))
+
years
,
l
=
isLeapYear
(
y
+
years
))
+
monthOfYearMillis
(
m
=
getMonthOfYear
(
millis
,
y
,
l
),
l
)
+
(
getDayOfMonth
(
millis
,
y
,
m
,
l
)
-
1
)
*
DAY_MILLIS
+
getTime
(
millis
)
+
(
millis
<
0
?
1
:
0
);
}
public
static
long
addDays
(
long
millis
,
int
days
)
{
return
millis
+
days
*
DAY_MILLIS
;
}
public
static
long
addHours
(
long
millis
,
int
hours
)
{
return
millis
+
hours
*
HOUR_MILLIS
;
}
}
\ No newline at end of file
nfsdb-core/src/main/java/com/nfsdb/journal/utils/Interval.java
浏览文件 @
a3c556ac
...
...
@@ -16,13 +16,73 @@
package
com.nfsdb.journal.utils
;
import
com.nfsdb.journal.PartitionType
;
import
com.nfsdb.journal.exceptions.JournalUnsupportedTypeException
;
import
com.nfsdb.journal.export.StringSink
;
public
class
Interval
{
private
final
long
lo
;
private
final
long
hi
;
public
Interval
(
long
lo
,
long
hi
)
{
this
.
lo
=
lo
;
this
.
hi
=
hi
;
if
(
hi
<
lo
)
{
this
.
lo
=
hi
;
this
.
hi
=
lo
;
}
else
{
this
.
lo
=
lo
;
this
.
hi
=
hi
;
}
}
public
Interval
(
CharSequence
lo
,
CharSequence
hi
)
{
this
(
Dates
.
parseDateTime
(
lo
),
Dates
.
parseDateTime
(
hi
));
}
public
Interval
(
long
millis
,
PartitionType
t
)
{
switch
(
t
)
{
case
YEAR:
this
.
lo
=
Dates
.
floorYYYY
(
millis
);
this
.
hi
=
Dates
.
ceilYYYY
(
millis
);
break
;
case
MONTH:
this
.
lo
=
Dates
.
floorMM
(
millis
);
this
.
hi
=
Dates
.
ceilMM
(
millis
);
break
;
case
DAY:
this
.
lo
=
Dates
.
floorDD
(
millis
);
this
.
hi
=
Dates
.
ceilMM
(
millis
);
break
;
default
:
this
.
lo
=
0
;
this
.
hi
=
Long
.
MAX_VALUE
;
}
}
public
Interval
(
String
dir
,
PartitionType
t
)
{
long
millis
;
switch
(
t
)
{
case
YEAR:
millis
=
Dates
.
parseDateTime
(
dir
+
"-01-01T00:00:00.000Z"
);
this
.
lo
=
Dates
.
floorYYYY
(
millis
);
this
.
hi
=
Dates
.
ceilYYYY
(
millis
);
break
;
case
MONTH:
millis
=
Dates
.
parseDateTime
(
dir
+
"-01T00:00:00.000Z"
);
this
.
lo
=
Dates
.
floorMM
(
millis
);
this
.
hi
=
Dates
.
ceilMM
(
millis
);
break
;
case
DAY:
millis
=
Dates
.
parseDateTime
(
dir
+
"T00:00:00.000Z"
);
this
.
lo
=
Dates
.
floorDD
(
millis
);
this
.
hi
=
Dates
.
ceilDD
(
millis
);
break
;
default
:
if
(!
"default"
.
equals
(
dir
))
{
throw
new
JournalUnsupportedTypeException
(
t
);
}
this
.
lo
=
0
;
this
.
hi
=
Long
.
MAX_VALUE
;
}
}
public
long
getLo
()
{
...
...
@@ -63,5 +123,23 @@ public class Interval {
result
=
31
*
result
+
(
int
)
(
hi
^
(
hi
>>>
32
));
return
result
;
}
public
String
getDirName
(
PartitionType
t
)
{
StringSink
sink
=
new
StringSink
();
switch
(
t
)
{
case
YEAR:
Dates
.
formatYYYY
(
sink
,
lo
);
break
;
case
MONTH:
Dates
.
formatYYYYMM
(
sink
,
lo
);
break
;
case
DAY:
Dates
.
formatDashYYYYMMDD
(
sink
,
lo
);
break
;
default
:
return
"default"
;
}
return
sink
.
toString
();
}
}
nfsdb-core/src/test/java/com/nfsdb/journal/Dates
2
Test.java
→
nfsdb-core/src/test/java/com/nfsdb/journal/DatesTest.java
浏览文件 @
a3c556ac
...
...
@@ -18,12 +18,11 @@ package com.nfsdb.journal;
import
com.nfsdb.journal.export.StringSink
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Dates2
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
public
class
Dates
2
Test
{
public
class
DatesTest
{
private
final
StringSink
sink
=
new
StringSink
();
...
...
@@ -42,24 +41,24 @@ public class Dates2Test {
@Test
public
void
testFormatCalDate1
()
throws
Exception
{
Dates
2
.
appendCalDate1
(
sink
,
Dates
.
toMillis
(
"2008-05-10T12:31:02.008Z"
));
Dates
.
formatDashYYYYMMDD
(
sink
,
Dates
.
parseDateTime
(
"2008-05-10T12:31:02.008Z"
));
Assert
.
assertEquals
(
"2008-05-10"
,
sink
.
toString
());
}
@Test
public
void
testFormatCalDate2
()
throws
Exception
{
Dates
2
.
appendCalDate2
(
sink
,
Dates
.
toMillis
(
"2008-05-10T12:31:02.008Z"
));
Dates
.
formatYYYYMM
(
sink
,
Dates
.
parseDateTime
(
"2008-05-10T12:31:02.008Z"
));
Assert
.
assertEquals
(
"2008-05"
,
sink
.
toString
());
}
@Test
public
void
testFormatCalDate3
()
throws
Exception
{
Dates
2
.
appendCalDate3
(
sink
,
Dates
.
toMillis
(
"2008-05-10T12:31:02.008Z"
));
Dates
.
formatYYYYMMDD
(
sink
,
Dates
.
parseDateTime
(
"2008-05-10T12:31:02.008Z"
));
Assert
.
assertEquals
(
"20080510"
,
sink
.
toString
());
}
private
void
assertTrue
(
String
date
)
{
Dates
2
.
appendDateTime
(
sink
,
Dates
.
toMillis
(
date
));
Dates
.
appendDateTime
(
sink
,
Dates
.
parseDateTime
(
date
));
Assert
.
assertEquals
(
date
,
sink
.
toString
());
sink
.
clear
();
}
...
...
@@ -67,136 +66,136 @@ public class Dates2Test {
@Test
public
void
testParseDateTime
()
throws
Exception
{
String
date
=
"2008-02-29T10:54:01.010Z"
;
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
parseDateTime
(
date
));
Dates
.
appendDateTime
(
sink
,
Dates
.
parseDateTime
(
date
));
Assert
.
assertEquals
(
date
,
sink
.
toString
());
}
@Test
public
void
testParseDateTimePrevEpoch
()
throws
Exception
{
String
date
=
"1812-02-29T10:54:01.010Z"
;
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
parseDateTime
(
date
));
Dates
.
appendDateTime
(
sink
,
Dates
.
parseDateTime
(
date
));
Assert
.
assertEquals
(
date
,
sink
.
toString
());
}
@Test
(
expected
=
NumberFormatException
.
class
)
public
void
testParseWrongMonth
()
throws
Exception
{
Dates
2
.
parseDateTime
(
"2013-00-12T00:00:00.000Z"
);
Dates
.
parseDateTime
(
"2013-00-12T00:00:00.000Z"
);
}
@Test
(
expected
=
NumberFormatException
.
class
)
public
void
testParseWrongDay
()
throws
Exception
{
Dates
2
.
parseDateTime
(
"2013-09-31T00:00:00.000Z"
);
Dates
.
parseDateTime
(
"2013-09-31T00:00:00.000Z"
);
}
@Test
(
expected
=
NumberFormatException
.
class
)
public
void
testParseWrongHour
()
throws
Exception
{
Dates
2
.
parseDateTime
(
"2013-09-30T24:00:00.000Z"
);
Dates
.
parseDateTime
(
"2013-09-30T24:00:00.000Z"
);
}
@Test
(
expected
=
NumberFormatException
.
class
)
public
void
testParseWrongMinute
()
throws
Exception
{
Dates
2
.
parseDateTime
(
"2013-09-30T22:61:00.000Z"
);
Dates
.
parseDateTime
(
"2013-09-30T22:61:00.000Z"
);
}
@Test
(
expected
=
NumberFormatException
.
class
)
public
void
testParseWrongSecond
()
throws
Exception
{
Dates
2
.
parseDateTime
(
"2013-09-30T22:04:60.000Z"
);
Dates
.
parseDateTime
(
"2013-09-30T22:04:60.000Z"
);
}
@Test
(
expected
=
NumberFormatException
.
class
)
public
void
testParseWrongMillis
()
throws
Exception
{
Dates
2
.
parseDateTime
(
"2013-09-30T22:04:34.1024Z"
);
Dates
.
parseDateTime
(
"2013-09-30T22:04:34.1024Z"
);
}
@Test
public
void
testFloorYYYY
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
floorYYYY
(
millis
));
long
millis
=
Dates
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
floorYYYY
(
millis
));
Assert
.
assertEquals
(
"2008-01-01T00:00:00.000Z"
,
sink
.
toString
());
}
@Test
public
void
testFloorMM
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
floorMM
(
millis
));
long
millis
=
Dates
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
floorMM
(
millis
));
Assert
.
assertEquals
(
"2008-05-01T00:00:00.000Z"
,
sink
.
toString
());
}
@Test
public
void
testFloorDD
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
floorDD
(
millis
));
long
millis
=
Dates
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
floorDD
(
millis
));
Assert
.
assertEquals
(
"2008-05-12T00:00:00.000Z"
,
sink
.
toString
());
}
@Test
public
void
testFloorHH
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
floorHH
(
millis
));
long
millis
=
Dates
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
floorHH
(
millis
));
Assert
.
assertEquals
(
"2008-05-12T23:00:00.000Z"
,
sink
.
toString
());
}
@Test
public
void
testCeilYYYY
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
ceilYYYY
(
millis
));
long
millis
=
Dates
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
ceilYYYY
(
millis
));
Assert
.
assertEquals
(
"2008-12-31T23:59:59.999Z"
,
sink
.
toString
());
}
@Test
public
void
testCeilMM
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
ceilMM
(
millis
));
long
millis
=
Dates
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
ceilMM
(
millis
));
Assert
.
assertEquals
(
"2008-05-31T23:59:59.999Z"
,
sink
.
toString
());
}
@Test
public
void
testCeilDD
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
ceilDD
(
millis
));
long
millis
=
Dates
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
ceilDD
(
millis
));
Assert
.
assertEquals
(
"2008-05-12T23:59:59.999Z"
,
sink
.
toString
());
}
@Test
public
void
testCeilDDPrevEpoch
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"1888-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
ceilDD
(
millis
));
long
millis
=
Dates
.
parseDateTime
(
"1888-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
ceilDD
(
millis
));
Assert
.
assertEquals
(
"1888-05-12T23:59:59.999Z"
,
sink
.
toString
());
}
@Test
public
void
testAddMonths
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
addMonths
(
millis
,
-
10
));
long
millis
=
Dates
.
parseDateTime
(
"2008-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
addMonths
(
millis
,
-
10
));
Assert
.
assertEquals
(
"2007-07-12T23:45:51.045Z"
,
sink
.
toString
());
}
@Test
public
void
testAddMonthsPrevEpoch
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"1888-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
addMonths
(
millis
,
-
10
));
long
millis
=
Dates
.
parseDateTime
(
"1888-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
addMonths
(
millis
,
-
10
));
Assert
.
assertEquals
(
"1887-07-12T23:45:51.045Z"
,
sink
.
toString
());
}
@Test
public
void
testAddYears
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"1988-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
addYear
(
millis
,
10
));
long
millis
=
Dates
.
parseDateTime
(
"1988-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
addYear
(
millis
,
10
));
Assert
.
assertEquals
(
"1998-05-12T23:45:51.045Z"
,
sink
.
toString
());
}
@Test
public
void
testAddYearsPrevEpoch
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"1888-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
addYear
(
millis
,
10
));
long
millis
=
Dates
.
parseDateTime
(
"1888-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
addYear
(
millis
,
10
));
Assert
.
assertEquals
(
"1898-05-12T23:45:51.045Z"
,
sink
.
toString
());
}
@Test
public
void
testAddDaysPrevEpoch
()
throws
Exception
{
long
millis
=
Dates
2
.
parseDateTime
(
"1888-05-12T23:45:51.045Z"
);
Dates
2
.
appendDateTime
(
sink
,
Dates2
.
addDays
(
millis
,
24
));
long
millis
=
Dates
.
parseDateTime
(
"1888-05-12T23:45:51.045Z"
);
Dates
.
appendDateTime
(
sink
,
Dates
.
addDays
(
millis
,
24
));
Assert
.
assertEquals
(
"1888-06-05T23:45:51.045Z"
,
sink
.
toString
());
}
}
nfsdb-core/src/test/java/com/nfsdb/journal/EmptyJournalTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -32,8 +32,8 @@ public class EmptyJournalTest extends AbstractTest {
@Test
public
void
testJournalWithEmptyPartition
()
throws
Exception
{
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
);
w
.
getAppendPartition
(
Dates
.
toMillis
(
"2012-02-10T10:00:00.000Z"
));
w
.
getAppendPartition
(
Dates
.
toMillis
(
"2012-03-10T10:00:00.000Z"
));
w
.
getAppendPartition
(
Dates
.
parseDateTime
(
"2012-02-10T10:00:00.000Z"
));
w
.
getAppendPartition
(
Dates
.
parseDateTime
(
"2012-03-10T10:00:00.000Z"
));
testJournalIterator
(
w
);
}
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/GenericAppendPerfTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -48,7 +48,7 @@ public class GenericAppendPerfTest extends AbstractTest {
);
long
t
=
System
.
nanoTime
();
TestUtils
.
generateQuoteDataGeneric
(
wg
,
TEST_DATA_SIZE
,
Dates
.
toMillis
(
"2013-10-05T10:00:00.000Z"
),
1000
);
TestUtils
.
generateQuoteDataGeneric
(
wg
,
TEST_DATA_SIZE
,
Dates
.
parseDateTime
(
"2013-10-05T10:00:00.000Z"
),
1000
);
wg
.
commit
();
long
result
=
System
.
nanoTime
()
-
t
;
LOGGER
.
info
(
"generic append (1M): "
+
TimeUnit
.
NANOSECONDS
.
toMillis
(
result
)
/
2
+
"ms"
);
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/IteratorTest.java
浏览文件 @
a3c556ac
...
...
@@ -23,6 +23,7 @@ import com.nfsdb.journal.model.Quote;
import
com.nfsdb.journal.test.tools.AbstractTest
;
import
com.nfsdb.journal.test.tools.TestUtils
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Interval
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -75,8 +76,8 @@ public class IteratorTest extends AbstractTest {
@Test
public
void
testEmptyPartitionFollowedByNonEmpty
()
throws
Exception
{
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
);
w
.
getAppendPartition
(
Dates
.
toMillis
(
"2012-01-10T10:00:00.000Z"
));
w
.
append
(
new
Quote
().
setSym
(
"TST"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-02-10T10:00:00.000Z"
)));
w
.
getAppendPartition
(
Dates
.
parseDateTime
(
"2012-01-10T10:00:00.000Z"
));
w
.
append
(
new
Quote
().
setSym
(
"TST"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-02-10T10:00:00.000Z"
)));
Assert
.
assertTrue
(
w
.
iterator
().
hasNext
());
}
...
...
@@ -137,7 +138,7 @@ public class IteratorTest extends AbstractTest {
@Test
public
void
testPartitionParallelIterator
()
throws
Exception
{
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
);
TestUtils
.
generateQuoteData
(
w
,
100000
,
Dates
.
i
nterval
(
"2014-01-01T00:00:00.000Z"
,
"2014-02-10T00:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
w
,
100000
,
new
I
nterval
(
"2014-01-01T00:00:00.000Z"
,
"2014-02-10T00:00:00.000Z"
));
Journal
<
Quote
>
r1
=
factory
.
reader
(
Quote
.
class
);
Journal
<
Quote
>
r2
=
factory
.
reader
(
Quote
.
class
);
...
...
@@ -153,7 +154,7 @@ public class IteratorTest extends AbstractTest {
@Test
public
void
testResultSetParallelIterator
()
throws
Exception
{
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
);
TestUtils
.
generateQuoteData
(
w
,
100000
,
Dates
.
i
nterval
(
"2014-01-01T00:00:00.000Z"
,
"2014-02-10T00:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
w
,
100000
,
new
I
nterval
(
"2014-01-01T00:00:00.000Z"
,
"2014-02-10T00:00:00.000Z"
));
Journal
<
Quote
>
r1
=
factory
.
reader
(
Quote
.
class
);
Journal
<
Quote
>
r2
=
factory
.
reader
(
Quote
.
class
);
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/JournalRecoveryTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -19,7 +19,7 @@ package com.nfsdb.journal;
import
com.nfsdb.journal.model.Quote
;
import
com.nfsdb.journal.test.tools.AbstractTest
;
import
com.nfsdb.journal.test.tools.TestUtils
;
import
com.nfsdb.journal.utils.
Dates
;
import
com.nfsdb.journal.utils.
Interval
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -31,9 +31,9 @@ public class JournalRecoveryTest extends AbstractTest {
try
(
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
))
{
w
.
setCommitOnClose
(
false
);
Assert
.
assertFalse
(
w
.
isCommitOnClose
());
TestUtils
.
generateQuoteData
(
w
,
10000
,
Dates
.
i
nterval
(
"2013-01-01T00:00:00.000Z"
,
"2013-02-28T12:55:00.000Z"
));
TestUtils
.
generateQuoteData
(
w
,
10000
,
new
I
nterval
(
"2013-01-01T00:00:00.000Z"
,
"2013-02-28T12:55:00.000Z"
));
ts
=
w
.
getMaxTimestamp
();
TestUtils
.
generateQuoteData
(
w
,
10000
,
Dates
.
i
nterval
(
"2013-03-01T00:00:00.000Z"
,
"2013-05-30T12:55:00.000Z"
),
false
);
TestUtils
.
generateQuoteData
(
w
,
10000
,
new
I
nterval
(
"2013-03-01T00:00:00.000Z"
,
"2013-05-30T12:55:00.000Z"
),
false
);
Assert
.
assertTrue
(
w
.
getMaxTimestamp
()
>
ts
);
}
...
...
@@ -52,7 +52,7 @@ public class JournalRecoveryTest extends AbstractTest {
@Test
public
void
testLagRecovery
()
throws
Exception
{
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
);
TestUtils
.
generateQuoteData
(
origin
,
100000
,
Dates
.
i
nterval
(
"2013-01-01T00:00:00.000Z"
,
"2013-05-30T12:55:00.000Z"
));
TestUtils
.
generateQuoteData
(
origin
,
100000
,
new
I
nterval
(
"2013-01-01T00:00:00.000Z"
,
"2013-05-30T12:55:00.000Z"
));
try
(
Journal
<
Quote
>
r
=
factory
.
reader
(
Quote
.
class
,
"origin"
))
{
Assert
.
assertEquals
(
100000
,
r
.
size
());
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/JournalRefreshTest.java
浏览文件 @
a3c556ac
...
...
@@ -21,7 +21,6 @@ import com.nfsdb.journal.model.Quote;
import
com.nfsdb.journal.test.tools.AbstractTest
;
import
com.nfsdb.journal.test.tools.TestUtils
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Dates2
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -40,16 +39,16 @@ public class JournalRefreshTest extends AbstractTest {
@Test
public
void
testRefreshScenarios
()
throws
JournalException
{
// initial data
rw
.
append
(
new
Quote
().
setSym
(
"IMO-1"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
10
,
10
,
0
)));
rw
.
append
(
new
Quote
().
setSym
(
"IMO-2"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
10
,
14
,
0
)));
rw
.
append
(
new
Quote
().
setSym
(
"IMO-1"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
10
,
10
,
0
)));
rw
.
append
(
new
Quote
().
setSym
(
"IMO-2"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
10
,
14
,
0
)));
rw
.
commit
();
Journal
<
Quote
>
r
=
factory
.
reader
(
Quote
.
class
);
Assert
.
assertEquals
(
2
,
r
.
size
());
// append data to same partition
rw
.
append
(
new
Quote
().
setSym
(
"IMO-1"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
10
,
15
,
0
)));
rw
.
append
(
new
Quote
().
setSym
(
"IMO-2"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
10
,
16
,
0
)));
rw
.
append
(
new
Quote
().
setSym
(
"IMO-1"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
10
,
15
,
0
)));
rw
.
append
(
new
Quote
().
setSym
(
"IMO-2"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
10
,
16
,
0
)));
rw
.
commit
();
// check that size didn't change before we call refresh
...
...
@@ -60,8 +59,8 @@ public class JournalRefreshTest extends AbstractTest {
Assert
.
assertEquals
(
4
,
r
.
size
());
// append data to new partition
rw
.
append
(
new
Quote
().
setSym
(
"IMO-3"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
15
,
0
)));
rw
.
append
(
new
Quote
().
setSym
(
"IMO-4"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
16
,
0
)));
rw
.
append
(
new
Quote
().
setSym
(
"IMO-3"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
15
,
0
)));
rw
.
append
(
new
Quote
().
setSym
(
"IMO-4"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
16
,
0
)));
// check that size didn't change before we call refresh
Assert
.
assertEquals
(
4
,
r
.
size
());
...
...
@@ -75,8 +74,8 @@ public class JournalRefreshTest extends AbstractTest {
Assert
.
assertEquals
(
6
,
r
.
size
());
List
<
Quote
>
data
=
new
ArrayList
<>();
data
.
add
(
new
Quote
().
setSym
(
"IMO-5"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
3
,
10
,
15
,
0
)));
data
.
add
(
new
Quote
().
setSym
(
"IMO-6"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
3
,
10
,
16
,
0
)));
data
.
add
(
new
Quote
().
setSym
(
"IMO-5"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
3
,
10
,
15
,
0
)));
data
.
add
(
new
Quote
().
setSym
(
"IMO-6"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
3
,
10
,
16
,
0
)));
rw
.
mergeAppend
(
data
);
rw
.
commit
();
...
...
@@ -90,7 +89,7 @@ public class JournalRefreshTest extends AbstractTest {
@Test
public
void
testTruncateRefresh
()
throws
Exception
{
TestUtils
.
generateQuoteData
(
rw
,
1000
,
Dates
.
toMillis
(
"2013-09-04T10:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
rw
,
1000
,
Dates
.
parseDateTime
(
"2013-09-04T10:00:00.000Z"
));
rw
.
commit
();
Journal
<
Quote
>
r
=
factory
.
reader
(
Quote
.
class
);
...
...
@@ -114,7 +113,7 @@ public class JournalRefreshTest extends AbstractTest {
reader
.
refresh
();
Assert
.
assertEquals
(
1001
,
reader
.
size
());
TestUtils
.
generateQuoteData
(
rw
,
302
,
Dates
.
toMillis
(
"2014-02-10T10:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
rw
,
302
,
Dates
.
parseDateTime
(
"2014-02-10T10:00:00.000Z"
));
reader
.
refresh
();
Assert
.
assertEquals
(
1001
,
reader
.
size
());
...
...
@@ -153,8 +152,8 @@ public class JournalRefreshTest extends AbstractTest {
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
);
Journal
<
Quote
>
reader
=
factory
.
reader
(
Quote
.
class
);
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
toMillis
(
"2014-02-10T02:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
toMillis
(
"2014-02-10T10:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
parseDateTime
(
"2014-02-10T02:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
parseDateTime
(
"2014-02-10T10:00:00.000Z"
));
rw
.
append
(
origin
.
query
().
all
().
asResultSet
().
subset
(
0
,
500
));
rw
.
commit
();
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/JournalTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -93,8 +93,8 @@ public class JournalTest extends AbstractTest {
@Test
(
expected
=
JournalException
.
class
)
public
void
testAddPartitionOutOfOrder
()
throws
Exception
{
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
);
w
.
getAppendPartition
(
Dates
.
toMillis
(
"2012-02-10T10:00:00.000Z"
));
w
.
getAppendPartition
(
Dates
.
toMillis
(
"2012-01-10T10:00:00.000Z"
));
w
.
getAppendPartition
(
Dates
.
parseDateTime
(
"2012-02-10T10:00:00.000Z"
));
w
.
getAppendPartition
(
Dates
.
parseDateTime
(
"2012-01-10T10:00:00.000Z"
));
}
@Test
...
...
@@ -183,7 +183,7 @@ public class JournalTest extends AbstractTest {
@Test
public
void
testMaxRowIDOnReader
()
throws
Exception
{
try
(
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
))
{
TestUtils
.
generateQuoteData
(
w
,
1000
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
w
,
1000
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
100000
);
w
.
commit
();
}
...
...
@@ -205,7 +205,7 @@ public class JournalTest extends AbstractTest {
public
void
testTxRollbackToEmpty
()
throws
Exception
{
int
SIZE
=
100000
;
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
,
SIZE
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
100000
);
origin
.
commit
();
try
(
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"quote"
,
SIZE
))
{
...
...
@@ -227,12 +227,12 @@ public class JournalTest extends AbstractTest {
public
void
testTxRollbackSamePartition
()
throws
Exception
{
int
SIZE
=
50000
;
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
,
SIZE
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
100000
);
origin
.
commit
();
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"quote"
,
SIZE
);
w
.
append
(
origin
);
w
.
commit
();
TestUtils
.
generateQuoteData
(
w
,
20
,
Dates
.
toMillis
(
"2014-03-30T00:11:00Z"
),
100
);
TestUtils
.
generateQuoteData
(
w
,
20
,
Dates
.
parseDateTime
(
"2014-03-30T00:11:00Z"
),
100
);
Assert
.
assertEquals
(
50020
,
w
.
size
());
Assert
.
assertEquals
(
50000
,
origin
.
size
());
w
.
rollback
();
...
...
@@ -243,14 +243,14 @@ public class JournalTest extends AbstractTest {
public
void
testTxRollbackMultiplePartitions
()
throws
Exception
{
int
SIZE
=
50000
;
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
,
SIZE
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
100000
);
origin
.
commit
();
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"quote"
,
SIZE
);
w
.
append
(
origin
);
w
.
commit
();
TestUtils
.
generateQuoteData
(
w
,
50000
,
Dates
.
toMillis
(
"2014-03-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
w
,
50000
,
Dates
.
parseDateTime
(
"2014-03-30T00:11:00Z"
),
100000
);
Assert
.
assertEquals
(
100000
,
w
.
size
());
Assert
.
assertEquals
(
50000
,
origin
.
size
());
...
...
@@ -263,7 +263,7 @@ public class JournalTest extends AbstractTest {
public
void
testTxRefresh
()
throws
Exception
{
int
SIZE
=
50000
;
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
,
SIZE
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
100000
);
origin
.
commit
();
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"quote"
,
SIZE
);
...
...
@@ -279,7 +279,7 @@ public class JournalTest extends AbstractTest {
int
SIZE
=
50000
;
File
location
;
try
(
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
,
SIZE
))
{
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
100000
);
origin
.
commit
();
location
=
new
File
(
origin
.
getLocation
(),
"2014-03"
);
}
...
...
@@ -288,7 +288,7 @@ public class JournalTest extends AbstractTest {
try
(
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
))
{
Assert
.
assertEquals
(
25914
,
origin
.
size
());
TestUtils
.
generateQuoteData
(
origin
,
3000
,
Dates
.
toMillis
(
"2014-03-30T00:11:00Z"
),
10000
);
TestUtils
.
generateQuoteData
(
origin
,
3000
,
Dates
.
parseDateTime
(
"2014-03-30T00:11:00Z"
),
10000
);
Assert
.
assertEquals
(
28914
,
origin
.
size
());
origin
.
rollback
();
Assert
.
assertEquals
(
25914
,
origin
.
size
());
...
...
@@ -299,7 +299,7 @@ public class JournalTest extends AbstractTest {
public
void
testTxRollbackLag
()
throws
JournalException
{
int
SIZE
=
150000
;
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
,
SIZE
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
100000
);
origin
.
commit
();
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
);
...
...
@@ -327,7 +327,7 @@ public class JournalTest extends AbstractTest {
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
,
SIZE
/
12
);
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"q"
,
SIZE
/
12
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
100000
);
origin
.
commit
();
ResultSet
<
Quote
>
originRs
=
origin
.
query
().
all
().
asResultSet
();
...
...
@@ -360,7 +360,7 @@ public class JournalTest extends AbstractTest {
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
,
SIZE
/
12
);
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"q"
,
SIZE
/
12
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
100000
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
100000
);
origin
.
commit
();
ResultSet
<
Quote
>
originRs
=
origin
.
query
().
all
().
asResultSet
();
...
...
@@ -395,7 +395,7 @@ public class JournalTest extends AbstractTest {
JournalWriter
<
Quote
>
origin
=
factory
.
writer
(
Quote
.
class
,
"origin"
);
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"q"
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
toMillis
(
"2014-01-30T00:11:00Z"
),
SIZE
);
TestUtils
.
generateQuoteData
(
origin
,
SIZE
,
Dates
.
parseDateTime
(
"2014-01-30T00:11:00Z"
),
SIZE
);
origin
.
commit
();
TestTxListener
lsnr
=
new
TestTxListener
();
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/LagTest.java
浏览文件 @
a3c556ac
...
...
@@ -21,7 +21,6 @@ import com.nfsdb.journal.model.Quote;
import
com.nfsdb.journal.test.tools.AbstractTest
;
import
com.nfsdb.journal.test.tools.TestData
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Dates2
;
import
org.junit.Assert
;
import
org.junit.Before
;
import
org.junit.Test
;
...
...
@@ -44,9 +43,9 @@ public class LagTest extends AbstractTest {
public
void
testOpenWithLag
()
throws
JournalException
{
Partition
<
Quote
>
partition
=
rw
.
openOrCreateLagPartition
();
Quote
v1
=
new
Quote
().
setSym
(
"1"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-06-11T00:00:00Z"
));
Quote
v2
=
new
Quote
().
setSym
(
"2"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-06-11T10:00:00Z"
));
Quote
v3
=
new
Quote
().
setSym
(
"2"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-06-11T06:00:00Z"
));
Quote
v1
=
new
Quote
().
setSym
(
"1"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-06-11T00:00:00Z"
));
Quote
v2
=
new
Quote
().
setSym
(
"2"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-06-11T10:00:00Z"
));
Quote
v3
=
new
Quote
().
setSym
(
"2"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-06-11T06:00:00Z"
));
rw
.
append
(
v1
);
partition
.
append
(
v2
);
...
...
@@ -60,11 +59,11 @@ public class LagTest extends AbstractTest {
@Test
public
void
testLagWorkflow
()
throws
JournalException
{
Quote
v1
=
new
Quote
().
setSym
(
"1"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-06-10T00:00:00Z"
));
Quote
v2
=
new
Quote
().
setSym
(
"2"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-06-10T10:00:00Z"
));
Quote
v3
=
new
Quote
().
setSym
(
"2"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-06-10T16:00:00Z"
));
Quote
v4
=
new
Quote
().
setSym
(
"3"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-06-10T19:00:00Z"
));
Quote
v5
=
new
Quote
().
setSym
(
"4"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-06-10T22:00:00Z"
));
Quote
v1
=
new
Quote
().
setSym
(
"1"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-06-10T00:00:00Z"
));
Quote
v2
=
new
Quote
().
setSym
(
"2"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-06-10T10:00:00Z"
));
Quote
v3
=
new
Quote
().
setSym
(
"2"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-06-10T16:00:00Z"
));
Quote
v4
=
new
Quote
().
setSym
(
"3"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-06-10T19:00:00Z"
));
Quote
v5
=
new
Quote
().
setSym
(
"4"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-06-10T22:00:00Z"
));
rw
.
append
(
v1
);
...
...
@@ -74,7 +73,7 @@ public class LagTest extends AbstractTest {
p
.
append
(
v4
);
p
.
append
(
v5
);
Quote
v6
=
new
Quote
().
setSym
(
"5"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-06-11T08:00:00Z"
));
Quote
v6
=
new
Quote
().
setSym
(
"5"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-06-11T08:00:00Z"
));
List
<
Quote
>
data
=
new
ArrayList
<>();
data
.
add
(
v6
);
rw
.
mergeAppend
(
data
);
...
...
@@ -96,8 +95,8 @@ public class LagTest extends AbstractTest {
// initial data
List
<
Quote
>
data1
=
new
ArrayList
<>();
data1
.
add
(
new
Quote
().
setSym
(
"S1"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
10
,
10
,
0
)));
data1
.
add
(
new
Quote
().
setSym
(
"S2"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
10
,
14
,
0
)));
data1
.
add
(
new
Quote
().
setSym
(
"S1"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
10
,
10
,
0
)));
data1
.
add
(
new
Quote
().
setSym
(
"S2"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
10
,
14
,
0
)));
rw
.
mergeAppend
(
data1
);
rw
.
commit
();
...
...
@@ -107,62 +106,62 @@ public class LagTest extends AbstractTest {
// simple append scenario
List
<
Quote
>
data2
=
new
ArrayList
<>();
data2
.
add
(
new
Quote
().
setSym
(
"S3"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
10
,
15
,
0
)));
data2
.
add
(
new
Quote
().
setSym
(
"S4"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
10
,
16
,
0
)));
data2
.
add
(
new
Quote
().
setSym
(
"S3"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
10
,
15
,
0
)));
data2
.
add
(
new
Quote
().
setSym
(
"S4"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
10
,
16
,
0
)));
rw
.
mergeAppend
(
data2
);
// simple append + lag split (30 days increment)
List
<
Quote
>
data3
=
new
ArrayList
<>();
data3
.
add
(
new
Quote
().
setSym
(
"S8"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
15
,
0
)));
data3
.
add
(
new
Quote
().
setSym
(
"S9"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
16
,
0
)));
data3
.
add
(
new
Quote
().
setSym
(
"S8"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
15
,
0
)));
data3
.
add
(
new
Quote
().
setSym
(
"S9"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
16
,
0
)));
rw
.
mergeAppend
(
data3
);
// data on fully above lag
List
<
Quote
>
data4
=
new
ArrayList
<>();
data4
.
add
(
new
Quote
().
setSym
(
"S6"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
10
,
0
)));
data4
.
add
(
new
Quote
().
setSym
(
"S7"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
11
,
0
)));
data4
.
add
(
new
Quote
().
setSym
(
"S6"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
10
,
0
)));
data4
.
add
(
new
Quote
().
setSym
(
"S7"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
11
,
0
)));
rw
.
mergeAppend
(
data4
);
// lag is fully inside data
List
<
Quote
>
data5
=
new
ArrayList
<>();
data5
.
add
(
new
Quote
().
setSym
(
"S5"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
9
,
0
)));
data5
.
add
(
new
Quote
().
setSym
(
"S10"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
17
,
0
)));
data5
.
add
(
new
Quote
().
setSym
(
"S5"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
9
,
0
)));
data5
.
add
(
new
Quote
().
setSym
(
"S10"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
17
,
0
)));
rw
.
mergeAppend
(
data5
);
// lag and data have equal boundaries
List
<
Quote
>
data6
=
new
ArrayList
<>();
data6
.
add
(
new
Quote
().
setSym
(
"near-S5"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
9
,
0
)));
data6
.
add
(
new
Quote
().
setSym
(
"near-S10"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
17
,
0
)));
data6
.
add
(
new
Quote
().
setSym
(
"near-S5"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
9
,
0
)));
data6
.
add
(
new
Quote
().
setSym
(
"near-S10"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
17
,
0
)));
rw
.
mergeAppend
(
data6
);
// bottom part of data overlaps top part of lag
List
<
Quote
>
data7
=
new
ArrayList
<>();
data7
.
add
(
new
Quote
().
setSym
(
"after-S4"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
9
,
9
,
0
)));
data7
.
add
(
new
Quote
().
setSym
(
"after-S9"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
16
,
30
)));
data7
.
add
(
new
Quote
().
setSym
(
"after-S4"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
9
,
9
,
0
)));
data7
.
add
(
new
Quote
().
setSym
(
"after-S9"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
16
,
30
)));
rw
.
mergeAppend
(
data7
);
// top part of data overlaps bottom part of lag
List
<
Quote
>
data8
=
new
ArrayList
<>();
data8
.
add
(
new
Quote
().
setSym
(
"after-S8"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
15
,
30
)));
data8
.
add
(
new
Quote
().
setSym
(
"after-S10"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
18
,
30
)));
data8
.
add
(
new
Quote
().
setSym
(
"after-S8"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
15
,
30
)));
data8
.
add
(
new
Quote
().
setSym
(
"after-S10"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
18
,
30
)));
rw
.
mergeAppend
(
data8
);
// data is fully inside of lag
List
<
Quote
>
data9
=
new
ArrayList
<>();
data9
.
add
(
new
Quote
().
setSym
(
"after-S6"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
10
,
30
)));
data9
.
add
(
new
Quote
().
setSym
(
"before-S10"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
16
,
45
)));
data9
.
add
(
new
Quote
().
setSym
(
"after-S6"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
10
,
30
)));
data9
.
add
(
new
Quote
().
setSym
(
"before-S10"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
16
,
45
)));
rw
.
mergeAppend
(
data9
);
// full discard
List
<
Quote
>
data10
=
new
ArrayList
<>();
data10
.
add
(
new
Quote
().
setSym
(
"discard-S1"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
1
,
10
,
30
)));
data10
.
add
(
new
Quote
().
setSym
(
"discard-S2"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
1
,
16
,
45
)));
data10
.
add
(
new
Quote
().
setSym
(
"discard-S1"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
1
,
10
,
30
)));
data10
.
add
(
new
Quote
().
setSym
(
"discard-S2"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
1
,
16
,
45
)));
rw
.
mergeAppend
(
data10
);
// full discard
List
<
Quote
>
data11
=
new
ArrayList
<>();
data11
.
add
(
new
Quote
().
setSym
(
"discard-S3"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
1
,
1
,
10
,
30
)));
data11
.
add
(
new
Quote
().
setSym
(
"before-S6"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
2
,
10
,
9
,
45
)));
data11
.
add
(
new
Quote
().
setSym
(
"discard-S3"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
1
,
1
,
10
,
30
)));
data11
.
add
(
new
Quote
().
setSym
(
"before-S6"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
2
,
10
,
9
,
45
)));
rw
.
mergeAppend
(
data11
);
String
expected
[]
=
{
"S1"
,
"S2"
,
"S3"
,
"S4"
,
"after-S4"
,
"S5"
,
"near-S5"
,
"before-S6"
,
"S6"
,
"after-S6"
,
"S7"
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/LockTest.java
浏览文件 @
a3c556ac
...
...
@@ -21,7 +21,7 @@ import com.nfsdb.journal.factory.JournalFactory;
import
com.nfsdb.journal.model.Quote
;
import
com.nfsdb.journal.model.configuration.ModelConfiguration
;
import
com.nfsdb.journal.test.tools.AbstractTest
;
import
com.nfsdb.journal.utils.Dates
2
;
import
com.nfsdb.journal.utils.Dates
;
import
org.junit.Assert
;
import
org.junit.Test
;
...
...
@@ -44,8 +44,8 @@ public class LockTest extends AbstractTest {
rw
=
factory
.
writer
(
Quote
.
class
);
List
<
Quote
>
data
=
new
ArrayList
<>();
data
.
add
(
new
Quote
().
setSym
(
"S1"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
3
,
10
,
15
,
0
)));
data
.
add
(
new
Quote
().
setSym
(
"S2"
).
setTimestamp
(
Dates
2
.
toMillis
(
2013
,
3
,
10
,
16
,
0
)));
data
.
add
(
new
Quote
().
setSym
(
"S1"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
3
,
10
,
15
,
0
)));
data
.
add
(
new
Quote
().
setSym
(
"S2"
).
setTimestamp
(
Dates
.
toMillis
(
2013
,
3
,
10
,
16
,
0
)));
rw
.
mergeAppend
(
data
);
rw
.
commit
();
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/NullTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -30,7 +30,7 @@ public class NullTest extends AbstractTest {
public
void
tumbleTryNullTest
()
throws
JournalException
{
final
int
TEST_DATA_SIZE
=
(
int
)
1
E3
;
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"quote"
,
1000
);
long
timestamp
=
Dates
.
toMillis
(
"2013-10-05T10:00:00.000Z"
);
long
timestamp
=
Dates
.
parseDateTime
(
"2013-10-05T10:00:00.000Z"
);
String
symbols
[]
=
{
"AGK.L"
,
"BP.L"
,
"TLW.L"
,
"ABF.L"
,
"LLOY.L"
,
"BT-A.L"
,
"WTB.L"
,
"RRS.L"
,
"ADM.L"
,
"GKN.L"
,
"HSBA.L"
};
Quote
q
=
new
Quote
();
int
increment
=
6000
;
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/PartitionTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -29,10 +29,10 @@ public class PartitionTest extends AbstractTest {
public
void
testIndexOf
()
throws
JournalException
{
JournalWriter
<
Quote
>
journal
=
factory
.
writer
(
Quote
.
class
);
long
ts1
=
Dates
.
toMillis
(
"2012-06-05T00:00:00.000"
);
long
ts2
=
Dates
.
toMillis
(
"2012-07-03T00:00:00.000"
);
long
ts3
=
Dates
.
toMillis
(
"2012-06-04T00:00:00.000"
);
long
ts4
=
Dates
.
toMillis
(
"2012-06-06T00:00:00.000"
);
long
ts1
=
Dates
.
parseDateTime
(
"2012-06-05T00:00:00.000"
);
long
ts2
=
Dates
.
parseDateTime
(
"2012-07-03T00:00:00.000"
);
long
ts3
=
Dates
.
parseDateTime
(
"2012-06-04T00:00:00.000"
);
long
ts4
=
Dates
.
parseDateTime
(
"2012-06-06T00:00:00.000"
);
Quote
q9
=
new
Quote
().
setSym
(
"S5"
).
setTimestamp
(
ts3
);
Quote
q10
=
new
Quote
().
setSym
(
"S5"
).
setTimestamp
(
ts4
);
...
...
@@ -61,20 +61,20 @@ public class PartitionTest extends AbstractTest {
Assert
.
assertEquals
(
2
,
journal
.
getPartitionCount
());
long
tsA
=
Dates
.
toMillis
(
"2012-06-15T00:00:00.000"
);
long
tsA
=
Dates
.
parseDateTime
(
"2012-06-15T00:00:00.000"
);
Partition
<
Quote
>
partition1
=
journal
.
getPartitionForTimestamp
(
tsA
).
open
();
Assert
.
assertNotNull
(
"getPartition(timestamp) failed"
,
partition1
);
Assert
.
assertEquals
(-
2
,
partition1
.
indexOf
(
tsA
,
BinarySearch
.
SearchType
.
NEWER_OR_SAME
));
Assert
.
assertEquals
(-
1
,
partition1
.
indexOf
(
Dates
.
toMillis
(
"2012-06-03T00:00:00.000"
),
BinarySearch
.
SearchType
.
OLDER_OR_SAME
));
Assert
.
assertEquals
(
0
,
partition1
.
indexOf
(
Dates
.
toMillis
(
"2012-06-03T00:00:00.000"
),
BinarySearch
.
SearchType
.
NEWER_OR_SAME
));
Assert
.
assertEquals
(-
1
,
partition1
.
indexOf
(
Dates
.
parseDateTime
(
"2012-06-03T00:00:00.000"
),
BinarySearch
.
SearchType
.
OLDER_OR_SAME
));
Assert
.
assertEquals
(
0
,
partition1
.
indexOf
(
Dates
.
parseDateTime
(
"2012-06-03T00:00:00.000"
),
BinarySearch
.
SearchType
.
NEWER_OR_SAME
));
Assert
.
assertEquals
(
4
,
partition1
.
indexOf
(
ts1
,
BinarySearch
.
SearchType
.
OLDER_OR_SAME
));
Assert
.
assertEquals
(
1
,
partition1
.
indexOf
(
ts1
,
BinarySearch
.
SearchType
.
NEWER_OR_SAME
));
Partition
<
Quote
>
p
=
journal
.
openOrCreateLagPartition
();
long
result
=
p
.
indexOf
(
Dates
.
toMillis
(
"2012-06-15T00:00:00.000"
),
BinarySearch
.
SearchType
.
OLDER_OR_SAME
);
long
result
=
p
.
indexOf
(
Dates
.
parseDateTime
(
"2012-06-15T00:00:00.000"
),
BinarySearch
.
SearchType
.
OLDER_OR_SAME
);
Assert
.
assertEquals
(-
1
,
result
);
}
}
nfsdb-core/src/test/java/com/nfsdb/journal/PerformanceTest.java
浏览文件 @
a3c556ac
...
...
@@ -58,7 +58,7 @@ public class PerformanceTest extends AbstractTest {
if
(
i
==
0
)
{
t
=
System
.
nanoTime
();
}
TestUtils
.
generateQuoteData
(
w
,
TEST_DATA_SIZE
,
Dates
.
toMillis
(
"2013-10-05T10:00:00.000Z"
),
1000
);
TestUtils
.
generateQuoteData
(
w
,
TEST_DATA_SIZE
,
Dates
.
parseDateTime
(
"2013-10-05T10:00:00.000Z"
),
1000
);
w
.
commit
();
}
...
...
@@ -170,12 +170,12 @@ public class PerformanceTest extends AbstractTest {
public
void
testAllBySymbolValueOverInterval
()
throws
JournalException
{
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"quote"
,
TEST_DATA_SIZE
);
TestUtils
.
generateQuoteData
(
w
,
TEST_DATA_SIZE
,
Dates
.
toMillis
(
"2013-10-05T10:00:00.000Z"
),
1000
);
TestUtils
.
generateQuoteData
(
w
,
TEST_DATA_SIZE
,
Dates
.
parseDateTime
(
"2013-10-05T10:00:00.000Z"
),
1000
);
w
.
commit
();
try
(
Journal
<
Quote
>
journal
=
factory
.
reader
(
Quote
.
class
))
{
int
count
=
1000
;
Interval
interval
=
Dates
.
interval
(
Dates
.
toMillis
(
"2013-10-05T10:00:00.000Z"
),
Dates
.
toMillis
(
"2013-10-1
5T10:00:00.000Z"
));
Interval
interval
=
new
Interval
(
Dates
.
parseDateTime
(
"2013-10-15T10:00:00.000Z"
),
Dates
.
parseDateTime
(
"2013-10-0
5T10:00:00.000Z"
));
long
t
=
0
;
QueryAllBuilder
<
Quote
>
builder
=
journal
.
query
().
all
().
withKeys
(
"LLOY.L"
).
slice
(
interval
);
for
(
int
i
=
-
1000
;
i
<
count
;
i
++)
{
...
...
@@ -192,7 +192,7 @@ public class PerformanceTest extends AbstractTest {
public
void
testLatestBySymbol
()
throws
JournalException
{
JournalWriter
<
Quote
>
w
=
factory
.
writer
(
Quote
.
class
,
"quote"
,
TEST_DATA_SIZE
);
TestUtils
.
generateQuoteData
(
w
,
TEST_DATA_SIZE
,
Dates
.
toMillis
(
"2013-10-05T10:00:00.000Z"
),
1000
);
TestUtils
.
generateQuoteData
(
w
,
TEST_DATA_SIZE
,
Dates
.
parseDateTime
(
"2013-10-05T10:00:00.000Z"
),
1000
);
w
.
commit
();
try
(
Journal
<
Quote
>
journal
=
factory
.
reader
(
Quote
.
class
))
{
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/PrinterTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -38,7 +38,7 @@ public class PrinterTest {
@Test
public
void
testDateConversion
()
throws
Exception
{
long
millis
=
Dates
.
toMillis
(
"2013-10-11T10:00:00.000Z"
);
long
millis
=
Dates
.
parseDateTime
(
"2013-10-11T10:00:00.000Z"
);
Quote
position1
=
new
Quote
().
setBidSize
(
10
).
setTimestamp
(
millis
);
Quote
position2
=
new
Quote
().
setTimestamp
(
millis
);
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/QueryTest.java
浏览文件 @
a3c556ac
...
...
@@ -34,8 +34,8 @@ import org.junit.Test;
public
class
QueryTest
extends
AbstractTest
{
private
final
long
ts1
=
Dates
.
toMillis
(
"2013-04-28T17:20:00.000Z"
);
private
final
long
ts2
=
Dates
.
toMillis
(
"2013-05-03T23:43:20.000Z"
);
private
final
long
ts1
=
Dates
.
parseDateTime
(
"2013-04-28T17:20:00.000Z"
);
private
final
long
ts2
=
Dates
.
parseDateTime
(
"2013-05-03T23:43:20.000Z"
);
private
Query
<
Quote
>
q
;
private
JournalWriter
<
Quote
>
w
;
...
...
@@ -58,7 +58,7 @@ public class QueryTest extends AbstractTest {
"2013-04-28T22:53:20.000Z\tRRS.L\t0.7787230809761455\t0.25803443163774886\t857471455\t190622110\tFast trading\tLXE\n"
+
"2013-04-28T18:43:20.000Z\tRRS.L\t0.18670502698896196\t0.0885706583279452\t505468688\t2038459861\tFast trading\tGR"
;
ResultSet
<
Quote
>
rs
=
q
.
all
().
withKeys
(
"RRS.L"
).
slice
(
Dates
.
interval
(
ts1
,
ts2
)).
asResultSet
();
ResultSet
<
Quote
>
rs
=
q
.
all
().
withKeys
(
"RRS.L"
).
slice
(
new
Interval
(
ts2
,
ts1
)).
asResultSet
();
TestUtils
.
assertOrderDesc
(
rs
.
bufferedIterator
());
TestUtils
.
assertEquals
(
expected
,
rs
);
}
...
...
@@ -75,7 +75,7 @@ public class QueryTest extends AbstractTest {
"2013-04-28T22:53:20.000Z\tRRS.L\t0.7787230809761455\t0.25803443163774886\t857471455\t190622110\tFast trading\tLXE\n"
+
"2013-04-28T18:43:20.000Z\tRRS.L\t0.18670502698896196\t0.0885706583279452\t505468688\t2038459861\tFast trading\tGR"
;
ResultSet
<
Quote
>
rs
=
q
.
all
().
withKeys
(
"RRS.L"
).
slice
(
Dates
.
interval
(
ts1
,
ts2
)).
asResultSet
();
ResultSet
<
Quote
>
rs
=
q
.
all
().
withKeys
(
"RRS.L"
).
slice
(
new
Interval
(
ts2
,
ts1
)).
asResultSet
();
TestUtils
.
assertOrderDesc
(
rs
.
bufferedIterator
());
TestUtils
.
assertEquals
(
expected
,
rs
);
}
...
...
@@ -92,7 +92,7 @@ public class QueryTest extends AbstractTest {
"2013-04-30T17:56:40.000Z\tGKN.L\t0.9957244238271116\t0.22502876454673404\t1074244114\t1402712074\tFast trading\tLXE\n"
+
"2013-04-29T11:23:20.000Z\tGKN.L\t0.4466437532316928\t0.32495899970572273\t2015090903\t1376158663\tFast trading\tLXE\n"
+
"2013-04-29T05:50:00.000Z\tGKN.L\t0.17560585850669297\t0.6791795548403247\t2114761437\t561608998\tFast trading\tLXE"
;
ResultSet
<
Quote
>
rs
=
q
.
all
().
withKeys
(
"GKN.L"
).
slice
(
Dates
.
interval
(
ts1
,
ts2
)).
asResultSet
();
ResultSet
<
Quote
>
rs
=
q
.
all
().
withKeys
(
"GKN.L"
).
slice
(
new
Interval
(
ts2
,
ts1
)).
asResultSet
();
TestUtils
.
assertOrderDesc
(
rs
.
bufferedIterator
());
TestUtils
.
assertEquals
(
expected
,
rs
);
}
...
...
@@ -268,7 +268,7 @@ public class QueryTest extends AbstractTest {
.
withKeys
(
"TLW.L"
,
"BP.L"
)
.
filter
(
"ex"
,
"SK"
)
.
filter
(
"ex"
,
"GR"
)
.
slice
(
Dates
.
interval
(
ts1
,
ts2
))
.
slice
(
new
Interval
(
ts2
,
ts1
))
.
asResultSet
();
TestUtils
.
assertEquals
(
expected
,
rs
.
sort
());
...
...
@@ -276,7 +276,7 @@ public class QueryTest extends AbstractTest {
@Test
public
void
testAllBySymbolValuesOverInterval
()
throws
Exception
{
ResultSet
<
Quote
>
rs
=
q
.
all
().
withKeys
().
slice
(
Dates
.
interval
(
ts1
,
ts2
)).
asResultSet
();
ResultSet
<
Quote
>
rs
=
q
.
all
().
withKeys
().
slice
(
new
Interval
(
ts2
,
ts1
)).
asResultSet
();
Assert
.
assertEquals
(
0
,
rs
.
size
());
String
expected
=
"2013-04-29T01:40:00.000Z\tWTB.L\t0.154905273744959\t0.3463641298845208\t1190004376\t548681062\tFast trading\tSK\n"
+
...
...
@@ -294,7 +294,7 @@ public class QueryTest extends AbstractTest {
"2013-05-02T22:43:20.000Z\tBT-A.L\t0.12282110119740142\t0.822933043281861\t997442403\t430556502\tFast trading\tSK\n"
+
"2013-05-03T01:30:00.000Z\tWTB.L\t0.6696457609278927\t0.7177695674107006\t1859909396\t1567568718\tFast trading\tSK\n"
+
"2013-05-03T07:03:20.000Z\tBT-A.L\t0.008144226019699663\t0.8149620429664706\t1492076657\t2143247261\tFast trading\tLXE\n"
;
rs
=
q
.
all
().
withKeys
(
"WTB.L"
,
"BT-A.L"
).
slice
(
Dates
.
interval
(
ts1
,
ts2
)).
asResultSet
();
rs
=
q
.
all
().
withKeys
(
"WTB.L"
,
"BT-A.L"
).
slice
(
new
Interval
(
ts2
,
ts1
)).
asResultSet
();
TestUtils
.
assertEquals
(
expected
,
rs
.
sort
());
}
...
...
@@ -392,8 +392,8 @@ public class QueryTest extends AbstractTest {
"2013-05-03T20:56:40.000Z\tAGK.L\t0.5512691746253235\t0.2622798544196908\t523767429\t834063697\tFast trading\tSK\n"
+
"2013-05-03T22:20:00.000Z\tAGK.L\t0.9788182552381814\t0.3069421348721998\t2053761104\t1032198554\tFast trading\tLXE\n"
+
"2013-05-03T23:43:20.000Z\tLLOY.L\t0.26716989176964423\t0.21548997929605662\t1042166874\t578687855\tFast trading\tSK\n"
;
TestUtils
.
assertOrder
(
q
.
all
().
bufferedIterator
(
Dates
.
interval
(
ts1
,
ts2
)));
TestUtils
.
assertEquals
(
expected
,
q
.
all
().
bufferedIterator
(
Dates
.
interval
(
ts1
,
ts2
)));
TestUtils
.
assertOrder
(
q
.
all
().
bufferedIterator
(
new
Interval
(
ts2
,
ts1
)));
TestUtils
.
assertEquals
(
expected
,
q
.
all
().
bufferedIterator
(
new
Interval
(
ts2
,
ts1
)));
}
@Test
...
...
@@ -494,7 +494,9 @@ public class QueryTest extends AbstractTest {
@Test
public
void
testLatestByKeyWithinMonths
()
throws
Exception
{
Query
<
Quote
>
q
=
advanceTestData
();
UnorderedResultSet
<
Quote
>
rs
=
q
.
getJournal
().
query
().
head
().
withKeys
().
limit
(
Dates
.
lastMonth
()).
asResultSet
();
long
millis
;
Interval
interval
=
new
Interval
(
Dates
.
addMonths
(
millis
=
System
.
currentTimeMillis
(),
-
1
),
millis
);
UnorderedResultSet
<
Quote
>
rs
=
q
.
getJournal
().
query
().
head
().
withKeys
().
limit
(
interval
).
asResultSet
();
Assert
.
assertEquals
(
10
,
rs
.
size
());
}
...
...
@@ -510,7 +512,7 @@ public class QueryTest extends AbstractTest {
"2013-05-03T19:33:20.000Z\tADM.L\t0.8577260763596468\t0.01591134909601677\t901921998\t767627517\tFast trading\tSK\n"
+
"2013-05-03T22:20:00.000Z\tAGK.L\t0.9788182552381814\t0.3069421348721998\t2053761104\t1032198554\tFast trading\tLXE\n"
+
"2013-05-03T23:43:20.000Z\tLLOY.L\t0.26716989176964423\t0.21548997929605662\t1042166874\t578687855\tFast trading\tSK\n"
;
UnorderedResultSet
<
Quote
>
rs
=
q
.
head
().
withKeys
().
limit
(
Dates
.
interval
(
ts1
,
ts2
)).
asResultSet
();
UnorderedResultSet
<
Quote
>
rs
=
q
.
head
().
withKeys
().
limit
(
new
Interval
(
ts2
,
ts1
)).
asResultSet
();
TestUtils
.
assertEquals
(
expected
,
rs
.
sort
());
}
...
...
@@ -519,7 +521,7 @@ public class QueryTest extends AbstractTest {
String
expected
=
"2013-05-03T22:20:00.000Z\tAGK.L\t0.9788182552381814\t0.3069421348721998\t2053761104\t1032198554\tFast trading\tLXE\n"
+
"2013-05-03T16:46:40.000Z\tBP.L\t0.800516898126557\t0.17852653385834039\t39877735\t1842395295\tFast trading\tGR\n"
+
"2013-05-03T23:43:20.000Z\tLLOY.L\t0.26716989176964423\t0.21548997929605662\t1042166874\t578687855\tFast trading\tSK\n"
;
UnorderedResultSet
<
Quote
>
rs
=
q
.
head
().
withSymValues
(
"ex"
).
limit
(
Dates
.
interval
(
ts1
,
ts2
)).
asResultSet
();
UnorderedResultSet
<
Quote
>
rs
=
q
.
head
().
withSymValues
(
"ex"
).
limit
(
new
Interval
(
ts2
,
ts1
)).
asResultSet
();
TestUtils
.
assertEquals
(
expected
,
rs
);
}
...
...
@@ -527,7 +529,7 @@ public class QueryTest extends AbstractTest {
public
void
testLatestByKeyValuesOverInterval
()
throws
Exception
{
String
expected
=
"2013-05-03T18:10:00.000Z\tBP.L\t0.02942030917851568\t0.572757460747041\t683641977\t1362036057\tFast trading\tLXE\n"
+
"2013-05-03T22:20:00.000Z\tAGK.L\t0.9788182552381814\t0.3069421348721998\t2053761104\t1032198554\tFast trading\tLXE\n"
;
UnorderedResultSet
<
Quote
>
rs
=
q
.
head
().
withKeys
(
"BP.L"
,
"AGK.L"
,
"BAD"
).
limit
(
Dates
.
interval
(
ts1
,
ts2
)).
asResultSet
();
UnorderedResultSet
<
Quote
>
rs
=
q
.
head
().
withKeys
(
"BP.L"
,
"AGK.L"
,
"BAD"
).
limit
(
new
Interval
(
ts2
,
ts1
)).
asResultSet
();
TestUtils
.
assertEquals
(
expected
,
rs
);
}
...
...
@@ -603,7 +605,7 @@ public class QueryTest extends AbstractTest {
public
void
testIterateOverInterval
()
throws
Exception
{
int
count
=
0
;
long
timestamp
=
0
;
for
(
Quote
a
:
q
.
all
().
bufferedIterator
(
Dates
.
interval
(
ts1
,
ts2
)))
{
for
(
Quote
a
:
q
.
all
().
bufferedIterator
(
new
Interval
(
ts2
,
ts1
)))
{
count
++;
Assert
.
assertTrue
(
timestamp
<=
a
.
getTimestamp
());
timestamp
=
a
.
getTimestamp
();
...
...
@@ -647,14 +649,14 @@ public class QueryTest extends AbstractTest {
@Test
public
void
testLatestByKeyValueOverInterval
()
throws
JournalException
{
Quote
Quote
=
q
.
head
().
withKeys
(
"RRS.L"
).
limit
(
Dates
.
interval
(
ts1
,
ts2
)).
asResultSet
().
readFirst
();
Quote
Quote
=
q
.
head
().
withKeys
(
"RRS.L"
).
limit
(
new
Interval
(
ts2
,
ts1
)).
asResultSet
().
readFirst
();
Assert
.
assertNotNull
(
Quote
);
Assert
.
assertEquals
(
0.5590262812936236
,
Quote
.
getBid
(),
0.00000000001
);
}
@Test
public
void
testParallelIteratorInterval
()
throws
Exception
{
Interval
interval
=
Dates
.
i
nterval
(
"2013-05-04T06:40:00.000Z"
,
"2013-05-05T17:23:20.000Z"
);
Interval
interval
=
new
I
nterval
(
"2013-05-04T06:40:00.000Z"
,
"2013-05-05T17:23:20.000Z"
);
Query
<
Quote
>
q2
=
factory
.
reader
(
Quote
.
class
).
query
();
JournalIterator
<
Quote
>
expected
=
q
.
all
().
iterator
(
interval
);
try
(
ConcurrentIterator
<
Quote
>
actual
=
q2
.
all
().
concurrentIterator
(
interval
))
{
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/ResultSetTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -43,7 +43,7 @@ public class ResultSetTest extends AbstractTest {
@Test
public
void
testReadPrimitive
()
throws
Exception
{
JournalWriter
<
TestEntity
>
w
=
factory
.
writer
(
TestEntity
.
class
);
TestUtils
.
generateTestEntityData
(
w
,
10000
,
Dates
.
toMillis
(
"2012-05-15T10:55:00.000Z"
),
100000
);
TestUtils
.
generateTestEntityData
(
w
,
10000
,
Dates
.
parseDateTime
(
"2012-05-15T10:55:00.000Z"
),
100000
);
ResultSet
<
TestEntity
>
rs
=
w
.
query
().
all
().
asResultSet
();
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/SortTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -34,7 +34,7 @@ public class SortTest extends AbstractTest {
@Before
public
void
setUp
()
throws
Exception
{
JournalWriter
<
TestEntity
>
w
=
factory
.
writer
(
TestEntity
.
class
);
TestUtils
.
generateTestEntityData
(
w
,
1000
,
Dates
.
toMillis
(
"2012-05-15T10:55:00.000Z"
),
100000
);
TestUtils
.
generateTestEntityData
(
w
,
1000
,
Dates
.
parseDateTime
(
"2012-05-15T10:55:00.000Z"
),
100000
);
q
=
w
.
query
();
}
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/TimestampTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -37,15 +37,15 @@ public class TimestampTest extends AbstractTest {
Assert
.
assertEquals
(
0
,
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
0
,
journal
.
getMaxTimestamp
());
Quote
quote21
=
new
Quote
().
setSym
(
"123"
).
setTimestamp
(
Dates
.
toMillis
(
"2011-09-10T10:00:00Z"
));
Quote
quote22
=
new
Quote
().
setSym
(
"345"
).
setTimestamp
(
Dates
.
toMillis
(
"2011-09-11T10:00:00Z"
));
Quote
quote21
=
new
Quote
().
setSym
(
"123"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2011-09-10T10:00:00Z"
));
Quote
quote22
=
new
Quote
().
setSym
(
"345"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2011-09-11T10:00:00Z"
));
journal
.
append
(
quote21
,
quote22
);
journal
.
commit
();
// make sure both hard and soft timestamps are the same
// because we are not touching lag partition
// and also both timestamps equal to max of two timestamps we inserted
Assert
.
assertEquals
(
Dates
.
toMillis
(
"2011-09-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
Dates
.
parseDateTime
(
"2011-09-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
journal
.
getMaxTimestamp
(),
journal
.
getAppendTimestampLo
());
}
...
...
@@ -53,37 +53,37 @@ public class TimestampTest extends AbstractTest {
// open journal again and check that timestamps are ok
try
(
JournalWriter
<
Quote
>
journal
=
factory
.
writer
(
Quote
.
class
))
{
Assert
.
assertEquals
(
Dates
.
toMillis
(
"2011-09-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
Dates
.
parseDateTime
(
"2011-09-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
journal
.
getMaxTimestamp
(),
journal
.
getAppendTimestampLo
());
// utc add some more data, which goes into new partition
Quote
quote23
=
new
Quote
().
setSym
(
"333"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-08-11T10:00:00Z"
));
Quote
quote23
=
new
Quote
().
setSym
(
"333"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-08-11T10:00:00Z"
));
journal
.
append
(
quote23
);
// make sure timestamps moved on
Assert
.
assertEquals
(
Dates
.
toMillis
(
"2012-08-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
Dates
.
parseDateTime
(
"2012-08-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
journal
.
getMaxTimestamp
(),
journal
.
getAppendTimestampLo
());
// populate lag (lag is configured to 48 hours)
Quote
quote24
=
new
Quote
().
setSym
(
"444"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-08-11T15:00:00Z"
));
Quote
quote24
=
new
Quote
().
setSym
(
"444"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-08-11T15:00:00Z"
));
data
.
add
(
quote24
);
journal
.
mergeAppend
(
data
);
journal
.
commit
();
// check that hard timestamp hasn't changed
Assert
.
assertEquals
(
Dates
.
toMillis
(
"2012-08-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
Dates
.
parseDateTime
(
"2012-08-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
// check that soft timestamp has changed
Assert
.
assertEquals
(
Dates
.
toMillis
(
"2012-08-11T15:00:00Z"
),
journal
.
getMaxTimestamp
());
Assert
.
assertEquals
(
Dates
.
parseDateTime
(
"2012-08-11T15:00:00Z"
),
journal
.
getMaxTimestamp
());
}
// reopen journal and check timestamps
try
(
JournalWriter
<
Quote
>
journal
=
factory
.
writer
(
Quote
.
class
))
{
Assert
.
assertEquals
(
Dates
.
toMillis
(
"2012-08-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
Dates
.
toMillis
(
"2012-08-11T15:00:00Z"
),
journal
.
getMaxTimestamp
());
Assert
.
assertEquals
(
Dates
.
parseDateTime
(
"2012-08-11T10:00:00Z"
),
journal
.
getAppendTimestampLo
());
Assert
.
assertEquals
(
Dates
.
parseDateTime
(
"2012-08-11T15:00:00Z"
),
journal
.
getMaxTimestamp
());
// append timestamp that would make lag shift
Quote
quote25
=
new
Quote
().
setSym
(
"555"
).
setTimestamp
(
Dates
.
toMillis
(
"2012-08-12T16:00:00Z"
));
Quote
quote25
=
new
Quote
().
setSym
(
"555"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2012-08-12T16:00:00Z"
));
data
.
clear
();
data
.
add
(
quote25
);
journal
.
mergeAppend
(
data
);
...
...
@@ -92,7 +92,7 @@ public class TimestampTest extends AbstractTest {
Assert
.
assertEquals
(
"2012-08-12T16:00:00.000Z"
,
Dates
.
toString
(
journal
.
getMaxTimestamp
()));
// create new empty partition
journal
.
getAppendPartition
(
Dates
.
toMillis
(
"2013-08-12T16:00:00Z"
));
journal
.
getAppendPartition
(
Dates
.
parseDateTime
(
"2013-08-12T16:00:00Z"
));
// check timestamps again
Assert
.
assertEquals
(
"2012-08-11T10:00:00.000Z"
,
Dates
.
toString
(
journal
.
getAppendTimestampLo
()));
...
...
@@ -102,8 +102,8 @@ public class TimestampTest extends AbstractTest {
@Test
public
void
testLagOnEmptyJournal
()
throws
JournalException
{
Quote
quote21
=
new
Quote
().
setSym
(
"123"
).
setTimestamp
(
Dates
.
toMillis
(
"2011-09-10T10:00:00Z"
));
Quote
quote22
=
new
Quote
().
setSym
(
"345"
).
setTimestamp
(
Dates
.
toMillis
(
"2011-09-11T10:00:00Z"
));
Quote
quote21
=
new
Quote
().
setSym
(
"123"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2011-09-10T10:00:00Z"
));
Quote
quote22
=
new
Quote
().
setSym
(
"345"
).
setTimestamp
(
Dates
.
parseDateTime
(
"2011-09-11T10:00:00Z"
));
List
<
Quote
>
data
=
new
ArrayList
<>();
data
.
add
(
quote21
);
data
.
add
(
quote22
);
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/lang/SearchByKeysTest.java
浏览文件 @
a3c556ac
...
...
@@ -59,7 +59,7 @@ public class SearchByKeysTest {
@Before
public
void
setUp
()
throws
Exception
{
timestamp
=
Dates
.
toMillis
(
"2013-01-01T00:00:00.000Z"
);
timestamp
=
Dates
.
parseDateTime
(
"2013-01-01T00:00:00.000Z"
);
// total 1500 rows to append
// over 3 days
// millis
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/lang/SingleJournalSearchTest.java
浏览文件 @
a3c556ac
...
...
@@ -39,8 +39,8 @@ import com.nfsdb.journal.model.Band;
import
com.nfsdb.journal.model.Quote
;
import
com.nfsdb.journal.test.tools.JournalTestFactory
;
import
com.nfsdb.journal.test.tools.TestData
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Files
;
import
com.nfsdb.journal.utils.Interval
;
import
org.junit.Assert
;
import
org.junit.BeforeClass
;
import
org.junit.ClassRule
;
...
...
@@ -90,7 +90,7 @@ public class SingleJournalSearchTest {
StringRef
sym
=
new
StringRef
(
"sym"
);
// from quote where timestamp in ("2013-03-12T00:00:00.000Z", "2013-03-13T00:00:00.000Z") and (sym in ("BP.L", "XXX") or sym = "WTB.L")
assertEquals
(
expected
,
new
JournalSourceImpl
(
new
IntervalPartitionSource
(
new
JournalPartitionSource
(
journal
,
false
),
Dates
.
i
nterval
(
"2013-03-12T00:00:00.000Z"
,
"2013-03-13T00:00:00.000Z"
)),
new
FilteredRowSource
(
assertEquals
(
expected
,
new
JournalSourceImpl
(
new
IntervalPartitionSource
(
new
JournalPartitionSource
(
journal
,
false
),
new
I
nterval
(
"2013-03-12T00:00:00.000Z"
,
"2013-03-13T00:00:00.000Z"
)),
new
FilteredRowSource
(
new
UnionRowSource
(
new
RowSource
[]{
new
KvIndexRowSource
(
...
...
@@ -132,7 +132,7 @@ public class SingleJournalSearchTest {
new
JournalSourceImpl
(
new
IntervalPartitionSource
(
new
JournalPartitionSource
(
journal
,
false
)
,
Dates
.
i
nterval
(
"2013-03-12T00:00:00.000Z"
,
"2013-03-15T00:00:00.000Z"
)
,
new
I
nterval
(
"2013-03-12T00:00:00.000Z"
,
"2013-03-15T00:00:00.000Z"
)
),
new
KvIndexHeadRowSource
(
sym
,
...
...
@@ -168,7 +168,7 @@ public class SingleJournalSearchTest {
journal
,
false
)
,
Dates
.
i
nterval
(
"2013-03-12T00:00:00.000Z"
,
"2013-03-15T00:00:00.000Z"
))
,
new
I
nterval
(
"2013-03-12T00:00:00.000Z"
,
"2013-03-15T00:00:00.000Z"
))
,
new
KvIndexHeadRowSource
(
sym
,
new
SymbolKeySource
(
sym
),
1
,
0
,
new
SymbolEqualsRowFilter
(
ex
,
exValue
))
)
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/lang/experimental/ModelGenerationTest.java
浏览文件 @
a3c556ac
...
...
@@ -73,7 +73,7 @@ public class ModelGenerationTest extends AbstractTest {
// generate 100,000 bands
// at rate of 5-10 per day
long
ts
=
Dates
.
toMillis
(
"2014-03-01T00:00:00.000Z"
);
long
ts
=
Dates
.
parseDateTime
(
"2014-03-01T00:00:00.000Z"
);
long
ts0
=
ts
;
int
nextBump
=
rnd
.
nextPositiveInt
()
%
6
+
5
;
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/net/JournalLagTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -28,10 +28,10 @@ public class JournalLagTest extends AbstractJournalTest {
@Override
public
void
setUp
()
throws
Exception
{
super
.
setUp
();
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
toMillis
(
"2013-02-01T00:00:00.000Z"
),
100
);
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
toMillis
(
"2013-02-01T01:00:00.000Z"
),
100
);
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
toMillis
(
"2013-02-01T13:00:00.000Z"
),
100
);
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
toMillis
(
"2013-05-01T00:00:00.000Z"
),
100
);
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
parseDateTime
(
"2013-02-01T00:00:00.000Z"
),
100
);
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
parseDateTime
(
"2013-02-01T01:00:00.000Z"
),
100
);
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
parseDateTime
(
"2013-02-01T13:00:00.000Z"
),
100
);
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
parseDateTime
(
"2013-05-01T00:00:00.000Z"
),
100
);
}
@Test
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/net/JournalTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -77,9 +77,9 @@ public class JournalTest extends AbstractJournalTest {
public
void
testConsumerPartitionEdge
()
throws
Exception
{
origin
.
truncate
();
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
toMillis
(
"2013-10-01T00:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
toMillis
(
"2013-11-01T00:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
toMillis
(
"2013-12-01T00:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
parseDateTime
(
"2013-10-01T00:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
parseDateTime
(
"2013-11-01T00:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
origin
,
500
,
Dates
.
parseDateTime
(
"2013-12-01T00:00:00.000Z"
));
master
.
append
(
origin
);
master
.
commit
();
...
...
@@ -127,8 +127,8 @@ public class JournalTest extends AbstractJournalTest {
@Test
public
void
testEmptyPartitionAdd
()
throws
Exception
{
master
.
append
(
origin
);
master
.
getAppendPartition
(
Dates
.
toMillis
(
"2013-12-01T00:00:00.000Z"
));
master
.
append
(
new
Quote
().
setTimestamp
(
Dates
.
toMillis
(
"2014-01-01T00:00:00.000Z"
)));
master
.
getAppendPartition
(
Dates
.
parseDateTime
(
"2013-12-01T00:00:00.000Z"
));
master
.
append
(
new
Quote
().
setTimestamp
(
Dates
.
parseDateTime
(
"2014-01-01T00:00:00.000Z"
)));
master
.
commit
();
executeSequence
(
true
);
Assert
.
assertEquals
(
master
.
getPartitionCount
(),
slave
.
getPartitionCount
());
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/net/PartitionTest.java
浏览文件 @
a3c556ac
/*
* Copyright (c) 2014. Vlad Ilyushchenko
* Copyright (c) 2014
-2015
. Vlad Ilyushchenko
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -36,7 +36,7 @@ import org.junit.Test;
public
class
PartitionTest
extends
AbstractTest
{
private
static
final
long
timestamp
=
Dates
.
toMillis
(
"2013-12-12T00:00:00.000Z"
);
private
static
final
long
timestamp
=
Dates
.
parseDateTime
(
"2013-12-12T00:00:00.000Z"
);
private
JournalWriter
<
Quote
>
origin
;
private
JournalWriter
<
Quote
>
master
;
private
JournalWriter
<
Quote
>
slave
;
...
...
@@ -139,7 +139,7 @@ public class PartitionTest extends AbstractTest {
consumer
.
read
(
channel
);
comparePartitions
();
TestUtils
.
generateQuoteData
(
master
,
200
,
Dates
.
toMillis
(
"2014-01-01T00:00:00.000Z"
));
TestUtils
.
generateQuoteData
(
master
,
200
,
Dates
.
parseDateTime
(
"2014-01-01T00:00:00.000Z"
));
producer
.
configure
(
slave
.
size
());
consumer
.
reset
();
producer
.
write
(
channel
);
...
...
nfsdb-core/src/test/java/com/nfsdb/journal/test/tools/TestData.java
浏览文件 @
a3c556ac
因为 它太大了无法显示 source diff 。你可以改为
查看blob
。
nfsdb-core/src/test/java/com/nfsdb/journal/test/tools/TestUtils.java
浏览文件 @
a3c556ac
...
...
@@ -45,7 +45,7 @@ public final class TestUtils {
public
static
void
generateQuoteData
(
JournalWriter
<
Quote
>
w
,
int
count
)
throws
JournalException
{
String
symbols
[]
=
{
"AGK.L"
,
"BP.L"
,
"TLW.L"
,
"ABF.L"
,
"LLOY.L"
,
"BT-A.L"
,
"WTB.L"
,
"RRS.L"
,
"ADM.L"
,
"GKN.L"
,
"HSBA.L"
};
long
timestamps
[]
=
{
Dates
.
toMillis
(
"2013-09-04T10:00:00.000Z"
),
Dates
.
toMillis
(
"2013-10-04T10:00:00.000Z"
),
Dates
.
toMillis
(
"2013-11-04T10:00:00.000Z"
)};
long
timestamps
[]
=
{
Dates
.
parseDateTime
(
"2013-09-04T10:00:00.000Z"
),
Dates
.
parseDateTime
(
"2013-10-04T10:00:00.000Z"
),
Dates
.
parseDateTime
(
"2013-11-04T10:00:00.000Z"
)};
Quote
q
=
new
Quote
();
Rnd
r
=
new
Rnd
(
System
.
currentTimeMillis
(),
System
.
currentTimeMillis
());
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
...
...
@@ -233,7 +233,7 @@ public final class TestUtils {
}
public
static
void
generateTestEntityData
(
JournalWriter
<
TestEntity
>
w
,
int
count
)
throws
JournalException
{
generateTestEntityData
(
w
,
count
,
Dates
.
toMillis
(
"2012-05-15T10:55:00.000Z"
),
count
*
100
);
generateTestEntityData
(
w
,
count
,
Dates
.
parseDateTime
(
"2012-05-15T10:55:00.000Z"
),
count
*
100
);
}
public
static
<
T
>
void
assertDataEquals
(
Journal
<
T
>
expected
,
Journal
<
T
>
actual
)
throws
JournalException
{
...
...
nfsdb-examples/src/main/java/org/nfsdb/examples/iterate/IntervalExample.java
浏览文件 @
a3c556ac
...
...
@@ -23,8 +23,8 @@ import com.nfsdb.journal.exceptions.JournalException;
import
com.nfsdb.journal.factory.JournalFactory
;
import
com.nfsdb.journal.factory.configuration.JournalConfigurationBuilder
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Dates2
;
import
com.nfsdb.journal.utils.Files
;
import
com.nfsdb.journal.utils.Interval
;
import
org.nfsdb.examples.model.Quote
;
import
org.nfsdb.examples.support.QuoteGenerator
;
...
...
@@ -59,11 +59,11 @@ public class IntervalExample {
int
count
=
0
;
long
t
=
System
.
nanoTime
();
long
lo
=
Dates
2
.
addDays
(
System
.
currentTimeMillis
(),
10
);
long
hi
=
Dates
2
.
addDays
(
lo
,
10
);
long
lo
=
Dates
.
addDays
(
System
.
currentTimeMillis
(),
10
);
long
hi
=
Dates
.
addDays
(
lo
,
10
);
// iterate the interval between lo and hi millis.
for
(
Quote
q
:
journal
.
query
().
all
().
iterator
(
Dates
.
interval
(
lo
,
hi
)))
{
for
(
Quote
q
:
journal
.
query
().
all
().
iterator
(
new
Interval
(
hi
,
lo
)))
{
assert
q
!=
null
;
count
++;
}
...
...
nfsdb-examples/src/main/java/org/nfsdb/examples/query/QueryBuilderExample.java
浏览文件 @
a3c556ac
...
...
@@ -22,8 +22,8 @@ import com.nfsdb.journal.exceptions.JournalException;
import
com.nfsdb.journal.factory.JournalFactory
;
import
com.nfsdb.journal.query.api.QueryAllBuilder
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Dates2
;
import
com.nfsdb.journal.utils.Files
;
import
com.nfsdb.journal.utils.Interval
;
import
org.nfsdb.examples.model.ModelConfiguration
;
import
org.nfsdb.examples.model.Quote
;
import
org.nfsdb.examples.support.QuoteGenerator
;
...
...
@@ -71,11 +71,11 @@ public class QueryBuilderExample {
//
// reuse builder to narrow down query interval
//
long
lo
=
Dates
2
.
addDays
(
System
.
currentTimeMillis
(),
10
);
long
hi
=
Dates
2
.
addDays
(
lo
,
10
);
long
lo
=
Dates
.
addDays
(
System
.
currentTimeMillis
(),
10
);
long
hi
=
Dates
.
addDays
(
lo
,
10
);
t
=
System
.
nanoTime
();
count
=
0
;
for
(
Quote
q
:
builder
.
slice
(
Dates
.
interval
(
lo
,
hi
)).
asResultSet
().
bufferedIterator
())
{
for
(
Quote
q
:
builder
.
slice
(
new
Interval
(
hi
,
lo
)).
asResultSet
().
bufferedIterator
())
{
assert
q
!=
null
;
count
++;
}
...
...
nfsdb-examples/src/main/java/org/nfsdb/examples/reporting/DailyPriceAverageExample.java
浏览文件 @
a3c556ac
...
...
@@ -24,7 +24,7 @@ import com.nfsdb.journal.factory.JournalFactory;
import
com.nfsdb.journal.printer.JournalPrinter
;
import
com.nfsdb.journal.printer.appender.StdOutAppender
;
import
com.nfsdb.journal.query.api.QueryAllBuilder
;
import
com.nfsdb.journal.utils.Dates
2
;
import
com.nfsdb.journal.utils.Dates
;
import
com.nfsdb.journal.utils.Files
;
import
org.nfsdb.examples.model.ModelConfiguration
;
import
org.nfsdb.examples.model.Quote
;
...
...
@@ -89,10 +89,10 @@ public class DailyPriceAverageExample {
// so this loop leverages data order by printing out result when
// day of year changes
for
(
Quote
q
:
builder
.
asResultSet
().
bufferedIterator
())
{
long
thisDay
=
Dates
2
.
floorDD
(
q
.
getTimestamp
());
long
thisDay
=
Dates
.
floorDD
(
q
.
getTimestamp
());
if
(
thisDay
!=
previousDay
)
{
if
(
previousDay
!=
-
1
)
{
Dates
2
.
appendCalDate1
(
sink
,
previousDay
);
Dates
.
formatDashYYYYMMDD
(
sink
,
previousDay
);
printer
.
out
(
symbol
,
sink
.
toString
(),
avgSum
/
avgCount
);
sink
.
clear
();
}
...
...
@@ -107,7 +107,7 @@ public class DailyPriceAverageExample {
}
if
(
previousDay
!=
-
1
)
{
Dates
2
.
appendCalDate1
(
sink
,
previousDay
);
Dates
.
formatDashYYYYMMDD
(
sink
,
previousDay
);
printer
.
out
(
symbol
,
sink
.
toString
(),
avgSum
/
avgCount
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录