test env for tiledatabase
parent
0cece506ac
commit
7b5c4346b6
|
@ -165,6 +165,10 @@ public interface TileServerConfig extends Config {
|
|||
@DefaultValue("org.postgresql.Driver")
|
||||
String tileDatabaseDriver();
|
||||
|
||||
@Key("minetest.db.dialect")
|
||||
@DefaultValue("POSTGRES")
|
||||
SQLDialect tileDatabaseDialect();
|
||||
|
||||
/*
|
||||
Debug stuff
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package io.rudin.minetest.tileserver.provider;
|
||||
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import io.rudin.minetest.tileserver.config.TileServerConfig;
|
||||
import io.rudin.minetest.tileserver.qualifier.TileDB;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.SQLDialect;
|
||||
|
@ -15,15 +16,18 @@ import javax.sql.DataSource;
|
|||
public class TileDBDSLContextProvider implements Provider<DSLContext> {
|
||||
|
||||
@Inject
|
||||
public TileDBDSLContextProvider(@TileDB DataSource ds) {
|
||||
public TileDBDSLContextProvider(@TileDB DataSource ds, TileServerConfig cfg) {
|
||||
this.ds = ds;
|
||||
this.cfg = cfg;
|
||||
}
|
||||
|
||||
|
||||
private final TileServerConfig cfg;
|
||||
|
||||
private final DataSource ds;
|
||||
|
||||
@Override
|
||||
public DSLContext get() {
|
||||
return DSL.using(ds, SQLDialect.POSTGRES);
|
||||
return DSL.using(ds, cfg.tileDatabaseDialect());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import io.rudin.minetest.tileserver.qualifier.TileDB;
|
|||
import io.rudin.minetest.tileserver.service.TileCache;
|
||||
import io.rudin.minetest.tileserver.tiledb.tables.records.TilesRecord;
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.SQLDialect;
|
||||
import org.jooq.impl.DSL;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -109,10 +110,15 @@ public class DatabaseTileCache implements TileCache {
|
|||
|
||||
@Override
|
||||
public long getLatestTimestamp() {
|
||||
return ctx
|
||||
Long mtime = ctx
|
||||
.select(DSL.max(TILES.MTIME))
|
||||
.from(TILES)
|
||||
.fetchOne(DSL.max(TILES.MTIME));
|
||||
|
||||
if (mtime == null)
|
||||
return 0L;
|
||||
else
|
||||
return mtime;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -121,17 +127,25 @@ public class DatabaseTileCache implements TileCache {
|
|||
}
|
||||
|
||||
private void insertOrupdate(TilesRecord record){
|
||||
ctx
|
||||
.insertInto(TILES, record.fields())
|
||||
.values(record.intoArray())
|
||||
.onDuplicateKeyUpdate()
|
||||
.set(TILES.X, record.getX())
|
||||
.set(TILES.Y, record.getY())
|
||||
.set(TILES.Z, record.getZ())
|
||||
.set(TILES.LAYERID, record.getLayerid())
|
||||
.set(TILES.MTIME, record.getMtime())
|
||||
.set(TILES.TILE, record.getTile())
|
||||
.execute();
|
||||
if (ctx.dialect() == SQLDialect.POSTGRES){
|
||||
//upsert
|
||||
ctx
|
||||
.insertInto(TILES, record.fields())
|
||||
.values(record.intoArray())
|
||||
.onDuplicateKeyUpdate()
|
||||
.set(TILES.X, record.getX())
|
||||
.set(TILES.Y, record.getY())
|
||||
.set(TILES.Z, record.getZ())
|
||||
.set(TILES.LAYERID, record.getLayerid())
|
||||
.set(TILES.MTIME, record.getMtime())
|
||||
.set(TILES.TILE, record.getTile())
|
||||
.execute();
|
||||
|
||||
} else {
|
||||
//fallback
|
||||
record.store();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import io.rudin.minetest.tileserver.module.DBModule;
|
|||
import io.rudin.minetest.tileserver.module.ServiceModule;
|
||||
import io.rudin.minetest.tileserver.module.TestServiceModule;
|
||||
import io.rudin.minetest.tileserver.qualifier.MapDB;
|
||||
import io.rudin.minetest.tileserver.qualifier.TileDB;
|
||||
import io.rudin.minetest.tileserver.util.StreamUtil;
|
||||
import org.aeonbits.owner.ConfigFactory;
|
||||
import org.jooq.DSLContext;
|
||||
|
@ -38,18 +39,27 @@ public class TileServerTest {
|
|||
@Before
|
||||
public void init() throws SQLException, IOException {
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put("minetest.db.url", "jdbc:h2:mem:tileserver;DB_CLOSE_DELAY=-1");
|
||||
|
||||
properties.put("minetest.db.url", "jdbc:h2:mem:blocks;DB_CLOSE_DELAY=-1");
|
||||
properties.put("minetest.db.username", "sa");
|
||||
properties.put("minetest.db.password", "");
|
||||
properties.put("minetest.db.driver", "org.h2.Driver");
|
||||
properties.put("minetest.db.dialect", "H2");
|
||||
|
||||
properties.put("tile.db.url", "jdbc:h2:mem:tiles;DB_CLOSE_DELAY=-1");
|
||||
properties.put("tile.db.username", "sa");
|
||||
properties.put("tile.db.password", "");
|
||||
properties.put("tile.db.driver", "org.h2.Driver");
|
||||
properties.put("tile.db.dialect", "H2");
|
||||
|
||||
properties.put("tile.cache.impl", "DATABASE");
|
||||
|
||||
TileServerConfig cfg = ConfigFactory.create(TileServerConfig.class, properties);
|
||||
|
||||
injector = Guice.createInjector(
|
||||
new ConfigModule(cfg),
|
||||
new DBModule(cfg),
|
||||
new TestServiceModule()
|
||||
new ServiceModule(cfg)
|
||||
);
|
||||
|
||||
DataSource dataSource = injector.getInstance(Key.get(DataSource.class, MapDB.class));
|
||||
|
@ -59,6 +69,13 @@ public class TileServerTest {
|
|||
|
||||
}
|
||||
|
||||
DataSource tileDataSource = injector.getInstance(Key.get(DataSource.class, TileDB.class));
|
||||
try (Connection connection = tileDataSource.getConnection()){
|
||||
connection.createStatement().execute("drop all objects");
|
||||
connection.createStatement().execute("runscript from 'classpath:/minetest-tiledb.sql'");
|
||||
|
||||
}
|
||||
|
||||
//does not work: create function plsql not available in h2
|
||||
//injector.getInstance(DBMigration.class).migrate();
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
create table "tiles" (
|
||||
"x" int not null,
|
||||
"y" int not null,
|
||||
"z" int not null,
|
||||
"mtime" bigint not null,
|
||||
"tile" bytea,
|
||||
"layerid" int not null default 0,
|
||||
|
||||
PRIMARY KEY("layerid", "x","y","z")
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue