Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 81 lines (70 sloc) 2.559 kB
de00424 @dizzyd Adding test to validate hint file CRCs after timeshift
dizzyd authored
1 %% -------------------------------------------------------------------
2 %%
3 %% bitcask: Eric Brewer-inspired key/value store
4 %%
5 %% Copyright (c) 2012 Basho Technologies, Inc. All Rights Reserved.
6 %%
7 %% This file is provided to you under the Apache License,
8 %% Version 2.0 (the "License"); you may not use this file
9 %% except in compliance with the License. You may obtain
10 %% a copy of the License at
11 %%
12 %% http://www.apache.org/licenses/LICENSE-2.0
13 %%
14 %% Unless required by applicable law or agreed to in writing,
15 %% software distributed under the License is distributed on an
16 %% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 %% KIND, either express or implied. See the License for the
18 %% specific language governing permissions and limitations
19 %% under the License.
20 %%
21 %% -------------------------------------------------------------------
22 -module(bitcask_timeshift).
23
24 -include_lib("eunit/include/eunit.hrl").
25 -include("bitcask.hrl").
26
27 -compile(export_all).
28
29 current_tstamp() ->
30 case erlang:get(meck_tstamp) of
31 undefined ->
32 erlang:error(uninitialized_meck_tstamp);
33 Value ->
34 Value
35 end.
36
37 next_tstamp() ->
38 Ts = case erlang:get(meck_tstamp) of
39 undefined ->
40 1;
41 Tstamp ->
42 Tstamp + erlang:get(meck_tstamp_step)
43 end,
44 erlang:put(meck_tstamp, Ts),
45 Ts.
46
47 set_tstamp(Tstamp) ->
48 erlang:put(meck_tstamp, Tstamp).
49
50 set_tstamp_step(Step) ->
51 erlang:put(meck_tstamp_step, Step).
52
53 timeshift_test() ->
54 try
55 meck:new(bitcask_time, [passthrough]),
56 meck:expect(bitcask_time, tstamp, fun next_tstamp/0),
57 set_tstamp(100),
58 set_tstamp_step(-1),
59
60 ?cmd("rm -rf /tmp/bc.timeshift"),
61 Bref = bitcask:open("/tmp/bc.timeshift", [read_write]),
62 ok = bitcask:put(Bref, <<"k1">>, <<"v1">>),
63 {error, _} = bitcask:put(Bref, <<"k1">>, <<"v2">>),
64 bitcask:close(Bref),
65
66 %% For each of the data files, validate that it has a valid hint file
67 Validate = fun(Fname) ->
68 {ok, S} = bitcask_fileops:open_file(Fname),
69 try
70 ?assert(bitcask_fileops:has_valid_hintfile(S))
71 after
72 bitcask_fileops:close(S)
73 end
74 end,
75 [Validate(Fname) || {_Ts, Fname} <-
76 bitcask_fileops:data_file_tstamps("/tmp/bc.timeshift")]
77
78 after
79 meck:unload()
80 end.
Something went wrong with that request. Please try again.