Commit 2a2f5676 authored by Paal Kvamme's avatar Paal Kvamme
Browse files

User opt-in for the readonly kludge. Unit tests dealing with re-open should not depend on defaults.

parent b1bd12b8
......@@ -2884,10 +2884,11 @@ test_roflag()
// Assumption: No need to use the forceRwBeforeWrite hack, i.e.
// SDAPI allows TRUNCATE open even when the file already exists
// and is read-only. The test also verifies that assumption.
ctx.setRoAfterWrite(false).forceRoBeforeRead(false).forceRwBeforeWrite(false);
{
std::shared_ptr<OpenZGY::IZgyWriter> writer =
IZgyWriter::open(ZgyWriterArgs()
.iocontext(Test_Utils::default_sd_context())
.iocontext(&ctx)
.size(128, 42, 555)
.filename(cad.name()));
if (!TEST_CHECK(bool(writer)))
......
......@@ -230,6 +230,7 @@ update_sdreopen(const std::string& filename, std::int64_t start, std::int64_t nb
{
OpenZGY::SeismicStoreIOContext context =
OpenZGY::SeismicStoreIOContext(*Test_Utils::default_sd_context())
.setRoAfterWrite(false)
.segsizebytes(2048)
.segsplit(nbytes==10000 ? 8 : 1);
std::shared_ptr<FileADT> fd =
......
......@@ -49,6 +49,46 @@ namespace Test_API {
}
#endif
namespace {
// All methods in this file that might be testing SD
// should explicitly specify that we don't want a
// read-only file at the end.
#ifdef HAVE_SD
const OpenZGY::SeismicStoreIOContext*
default_sd_context_rw()
{
using InternalZGY::Environment;
static OpenZGY::SeismicStoreIOContext instance =
OpenZGY::SeismicStoreIOContext()
.setRoAfterWrite(false)
.forceRoBeforeRead(false)
.forceRwBeforeWrite(false)
.sdurl(Environment::getStringEnv("OPENZGY_SDURL"))
.sdapikey(Environment::getStringEnv("OPENZGY_SDAPIKEY"))
.sdtoken(Environment::getStringEnv("OPENZGY_TOKEN"), "");
return &instance;
}
const OpenZGY::IOContext*
default_context_rw()
{
return default_sd_context_rw();
}
#else
const OpenZGY::IOContext*
default_context_rw()
{
return nullptr;
}
#endif
}
namespace {
/**
* Pass a SilentProgress instance to finalize() to get back the "total"
......@@ -212,9 +252,9 @@ test_reopen_plain()
static void
test_reopen_plain_sd()
{
Test_Utils::CloudFileAutoDelete cad("reopen_plain_sd.zgy", Test_Utils::default_sd_context());
do_write_twice(cad.name(), Test_Utils::default_sd_context());
do_check_written(cad.name(), Test_Utils::default_sd_context());
Test_Utils::CloudFileAutoDelete cad("reopen_plain_sd.zgy", default_sd_context_rw());
do_write_twice(cad.name(), default_sd_context_rw());
do_check_written(cad.name(), default_sd_context_rw());
}
#endif // HAVE_SD
......@@ -450,7 +490,7 @@ do_test_reopen(const std::string& filename, TestTwiceFlags flags)
0;
ZgyWriterArgs firstargs = ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(filename)
.size(66, 100, 100)
.bricksize(8, 32, 64)
......@@ -467,7 +507,7 @@ do_test_reopen(const std::string& filename, TestTwiceFlags flags)
firstargs.zfp_compressor(99);
ZgyWriterArgs secondargs = ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(filename);
if ((flags & TestTwiceFlags::step2_nometa) == TestTwiceFlags::nothing)
......@@ -550,7 +590,7 @@ do_test_reopen(const std::string& filename, TestTwiceFlags flags)
// OPEN THE FILE AND CHECK RESULTS.
std::shared_ptr<OpenZGY::IZgyReader> reader =
OpenZGY::IZgyReader::open(filename, Test_Utils::default_context());
OpenZGY::IZgyReader::open(filename, default_context_rw());
const int actual_nlods = reader->nlods();
......@@ -701,7 +741,7 @@ test_reopen_not_if_meta()
std::shared_ptr<OpenZGY::IZgyWriter> writer;
writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(10, 100, 100)
.datarange(-1, 1));
......@@ -712,7 +752,7 @@ test_reopen_not_if_meta()
must_throw("Cannot change", [&](){
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(10, 100, 100));
});
......@@ -720,7 +760,7 @@ test_reopen_not_if_meta()
must_throw("Cannot change", [&](){
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.bricksize(64, 64, 64));
});
......@@ -728,7 +768,7 @@ test_reopen_not_if_meta()
must_throw("Cannot change", [&](){
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.datatype(SampleDataType::float32));
});
......@@ -736,7 +776,7 @@ test_reopen_not_if_meta()
must_throw("Cannot change", [&](){
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.datarange(-1, 1));
});
......@@ -745,7 +785,7 @@ test_reopen_not_if_meta()
must_throw("Cannot change", [&](){
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.hunit(UnitDimension::length, "m", 1));
});
......@@ -769,7 +809,7 @@ test_reopen_not_if_final()
std::shared_ptr<OpenZGY::IZgyWriter> writer;
writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(10, 100, 300)
.zfp_compressor(99));
......@@ -787,14 +827,14 @@ test_reopen_not_if_final()
must_throw("finalized compressed file cannot be opened for update", [&](){
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
});
// Re-create the file as uncompressed.
writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(10, 100, 300));
writer->write(size3i_t{0,0,0}, size3i_t{1,1,1}, &fortytwo);
......@@ -811,7 +851,7 @@ test_reopen_not_if_final()
must_throw("finalized file cannot have compressed data appended", [&](){
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.zfp_compressor(99));
});
......@@ -831,7 +871,7 @@ test_reopen_not_if_compress()
std::shared_ptr<OpenZGY::IZgyWriter> writer;
writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(10, 100, 300)
.zfp_compressor(99));
......@@ -843,7 +883,7 @@ test_reopen_not_if_compress()
// Ok, append compressed data to a not finalized file.
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.zfp_compressor(99));
writer->write(size3i_t{0,0,64}, size3i_t{1,1,1}, &fifteen);
......@@ -853,7 +893,7 @@ test_reopen_not_if_compress()
// Ok but odd, append uncompressed data to a not finalized compressed file.
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
writer->write(size3i_t{0,0,128}, size3i_t{1,1,1}, &fifteen);
writer->close_incomplete();
......@@ -863,7 +903,7 @@ test_reopen_not_if_compress()
// Disallow updating an uncompressed brick with compressed data.
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.zfp_compressor(99));
must_throw("is illegal", [&](){
......@@ -879,7 +919,7 @@ test_reopen_not_if_compress()
// Disallow updating a compressed brick with uncompressed data.
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
writer->write(size3i_t{0,0,128}, size3i_t{1,1,1}, &fortytwo);
......@@ -914,7 +954,7 @@ test_reopen_alignment()
std::shared_ptr<OpenZGY::IZgyWriter> writer;
writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(64, 64, 1024));
const float fortytwo{42};
......@@ -923,7 +963,7 @@ test_reopen_alignment()
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.zfp_compressor(30));
for (int ii=64; ii<1024; ii += 64)
......@@ -932,7 +972,7 @@ test_reopen_alignment()
writer.reset();
std::shared_ptr<OpenZGY::IZgyReader> reader;
reader = OpenZGY::IZgyReader::open(lad.name(), Test_Utils::default_context());
reader = OpenZGY::IZgyReader::open(lad.name(), default_context_rw());
std::shared_ptr<const FileStatistics> stats = reader->filestats();
if (verbose())
......@@ -960,7 +1000,7 @@ test_reopen_create_tiny()
std::shared_ptr<OpenZGY::IZgyWriter> writer;
writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(10, 20, 30));
const float fortytwo{42}, sixteen{-16};
......@@ -972,7 +1012,7 @@ test_reopen_create_tiny()
// Make sure statistics were collected.
std::shared_ptr<OpenZGY::IZgyReader> reader;
reader = OpenZGY::IZgyReader::open(lad.name(), Test_Utils::default_context());
reader = OpenZGY::IZgyReader::open(lad.name(), default_context_rw());
SampleStatistics stat = reader->statistics();
TEST_EQUAL(stat.cnt, 10*20*30);
TEST_EQUAL(stat.min, -16);
......@@ -986,7 +1026,7 @@ read_one_sample(const std::string& filename, int ii, int jj, int kk, int lod)
typedef OpenZGY::IZgyWriter::size3i_t size3i_t;
std::shared_ptr<OpenZGY::IZgyReader> reader;
float result{0};
reader = OpenZGY::IZgyReader::open(filename, Test_Utils::default_context());
reader = OpenZGY::IZgyReader::open(filename, default_context_rw());
reader->read(size3i_t{ii,jj,kk}, size3i_t{1,1,1}, &result, lod);
return result;
}
......@@ -1006,7 +1046,7 @@ test_reopen_update_tiny()
std::shared_ptr<OpenZGY::IZgyWriter> writer;
writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(10, 20, 30));
const float fortytwo{42}, sixteen{-16};
......@@ -1021,7 +1061,7 @@ test_reopen_update_tiny()
// Make sure statistics were not collected.
std::shared_ptr<OpenZGY::IZgyReader> reader;
reader = OpenZGY::IZgyReader::open(lad.name(), Test_Utils::default_context());
reader = OpenZGY::IZgyReader::open(lad.name(), default_context_rw());
SampleStatistics stat = reader->statistics();
TEST_EQUAL(stat.cnt, 0);
......@@ -1033,7 +1073,7 @@ test_reopen_update_tiny()
// for the statistics.
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
writer->close();
......@@ -1041,7 +1081,7 @@ test_reopen_update_tiny()
return;
// Make sure statistics are now good.
reader = OpenZGY::IZgyReader::open(lad.name(), Test_Utils::default_context());
reader = OpenZGY::IZgyReader::open(lad.name(), default_context_rw());
stat = reader->statistics();
TEST_EQUAL(stat.cnt, 10*20*30);
TEST_EQUAL(stat.min, -16);
......@@ -1052,13 +1092,13 @@ test_reopen_update_tiny()
// Actually need to write something as well.
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
writer->write(size3i_t{0,0,2}, size3i_t{1,1,1}, &sixteen);
writer->close_incomplete();
// Stale statistics should have been erased.
reader = OpenZGY::IZgyReader::open(lad.name(), Test_Utils::default_context());
reader = OpenZGY::IZgyReader::open(lad.name(), default_context_rw());
stat = reader->statistics();
TEST_EQUAL(stat.cnt, 0);
......@@ -1102,7 +1142,7 @@ test_reopen_update_too_old()
must_throw("version is too old", [&](){
auto writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
});
}
......@@ -1123,7 +1163,7 @@ test_reopen_update_bad_vt()
// Create uncompressed int8 file.
writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.datatype(SampleDataType::int8)
.datarange(-128, 127)
......@@ -1137,7 +1177,7 @@ test_reopen_update_bad_vt()
must_throw("need to be stored as float", [&](){
writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.zfp_compressor(30));
});
......@@ -1296,7 +1336,7 @@ test_reopen_empty()
// Create empty file with 3 lod levels
auto writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(10, 100, 200));
writer->close();
......@@ -1306,7 +1346,7 @@ test_reopen_empty()
// even though the file is not "dirty" in the normal sense.
{
auto reader = OpenZGY::IZgyReader::open
(lad.name(), Test_Utils::default_context());
(lad.name(), default_context_rw());
TEST_EQUAL(reader->nlods(), 3);
TEST_EQUAL(reader->statistics().cnt, 10*100*200);
}
......@@ -1319,7 +1359,7 @@ test_reopen_empty()
{
auto writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
writer->finalize(std::vector<OpenZGY::DecimationType>{}, nullptr,
FinalizeAction::Delete, true);
......@@ -1329,7 +1369,7 @@ test_reopen_empty()
// Check that lowres and statistics were deleted
{
auto reader = OpenZGY::IZgyReader::open
(lad.name(), Test_Utils::default_context());
(lad.name(), default_context_rw());
TEST_EQUAL(reader->nlods(), 1);
TEST_EQUAL(reader->statistics().cnt, 0);
}
......@@ -1338,7 +1378,7 @@ test_reopen_empty()
{
auto writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
writer->close();
}
......@@ -1347,7 +1387,7 @@ test_reopen_empty()
// the low resolution data exists.
{
auto reader = OpenZGY::IZgyReader::open
(lad.name(), Test_Utils::default_context());
(lad.name(), default_context_rw());
TEST_EQUAL(reader->nlods(), 3);
TEST_EQUAL(reader->statistics().cnt, 10*100*200);
}
......@@ -1387,7 +1427,7 @@ test_reopen_track_changes()
SilentProgress p;
auto writer = OpenZGY::IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.bricksize(16,32,32)
.size(261, 547, 202));
......@@ -1406,7 +1446,7 @@ test_reopen_track_changes()
SilentProgress p;
auto writer = OpenZGY::IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
if (!TEST_CHECK(writer != nullptr))
return;
......@@ -1427,7 +1467,7 @@ test_reopen_track_changes()
{
auto reader = OpenZGY::IZgyReader::open
(lad.name(), Test_Utils::default_context());
(lad.name(), default_context_rw());
if (!TEST_CHECK(reader != nullptr))
return;
TEST_EQUAL(reader->nlods(), 6);
......@@ -1699,7 +1739,7 @@ test_reopen_rwlod()
std::shared_ptr<IZgyWriter> writer =
IZgyWriter::open
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name())
.size(66, 100, 100)
.bricksize(8, 32, 64)
......@@ -1715,7 +1755,7 @@ test_reopen_rwlod()
writer->close();
writer = IZgyWriter::reopen
(ZgyWriterArgs()
.iocontext(Test_Utils::default_context())
.iocontext(default_context_rw())
.filename(lad.name()));
const float ten{10};
......@@ -2155,7 +2195,7 @@ void
test_reopen_zgycloud()
{
Test_Utils::CloudFileAutoDelete cad
("reopen_zgycloud.zgy", Test_Utils::default_sd_context());
("reopen_zgycloud.zgy", default_sd_context_rw());
{
// Expected to fail because the header segment is not padded.
// Otherwise this file, containing no bricks, would have worked.
......@@ -2165,7 +2205,7 @@ test_reopen_zgycloud()
must_throw("Only files uploaded by OpenZGY", [&](){
writer = IZgyWriter::reopen(ZgyWriterArgs()
.filename(cad.name())
.iocontext(Test_Utils::default_sd_context()));
.iocontext(default_sd_context_rw()));
});
}
{
......@@ -2176,7 +2216,7 @@ test_reopen_zgycloud()
must_throw("Only files uploaded by OpenZGY", [&](){
writer = IZgyWriter::reopen(ZgyWriterArgs()
.filename(cad.name())
.iocontext(Test_Utils::default_sd_context()));
.iocontext(default_sd_context_rw()));
});
}
{
......@@ -2189,7 +2229,7 @@ test_reopen_zgycloud()
must_throw("version is too old for this library", [&](){
writer = IZgyWriter::reopen(ZgyWriterArgs()
.filename(cad.name())
.iocontext(Test_Utils::default_sd_context()));
.iocontext(default_sd_context_rw()));
});
}
}
......@@ -2266,7 +2306,7 @@ list_segments(const std::string& name, int verbose)
{
#if 0
std::shared_ptr<OpenZGY::IZgyReader> reader =
OpenZGY::IZgyReader::open(name, Test_Utils::default_sd_context());
OpenZGY::IZgyReader::open(name, default_sd_context_rw());
std::shared_ptr<const OpenZGY::FileStatistics> fs = reader->filestats();
reader->close();
return list_segments(fs, verbose);
......@@ -2286,9 +2326,9 @@ static void
test_reopen_sd()
{
typedef OpenZGY::IZgyWriter::size3i_t size3i_t;
Test_Utils::CloudFileAutoDelete cad("reopen_sd.zgy", Test_Utils::default_sd_context());
Test_Utils::CloudFileAutoDelete cad("reopen_sd.zgy", default_sd_context_rw());
OpenZGY::SeismicStoreIOContext context =
OpenZGY::SeismicStoreIOContext(*Test_Utils::default_sd_context())
OpenZGY::SeismicStoreIOContext(*default_sd_context_rw())
.segsplit(8)
.segsize(2);
if (verbose())
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment