|
| 1 | +/*********************************************************************** |
| 2 | + * Copyright (c) 2013-2025 General Atomics Integrated Intelligence, Inc. |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Apache License, Version 2.0 |
| 5 | + * which accompanies this distribution and is available at |
| 6 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 7 | + ***********************************************************************/ |
| 8 | + |
| 9 | +package org.locationtech.geomesa.gt.partition.postgis |
| 10 | + |
| 11 | +import org.junit.runner.RunWith |
| 12 | +import org.specs2.mutable.Specification |
| 13 | +import org.specs2.runner.JUnitRunner |
| 14 | + |
| 15 | +@RunWith(classOf[JUnitRunner]) |
| 16 | +class PartitionedPostgisDataStoreFactoryTest extends Specification { |
| 17 | + |
| 18 | + import scala.collection.JavaConverters._ |
| 19 | + |
| 20 | + "PartitionedPostgisDataStoreFactory" should { |
| 21 | + |
| 22 | + "advertise the prepare_threshold parameter" in { |
| 23 | + // guards the setupParameters registration: if the param is dropped from that Seq, |
| 24 | + // GeoTools silently stops exposing it and this fails |
| 25 | + val factory = new PartitionedPostgisDataStoreFactory() |
| 26 | + val keys = factory.getParametersInfo.map(_.key).toSeq |
| 27 | + keys must contain(PartitionedPostgisDataStoreParams.PrepareThreshold.key) |
| 28 | + PartitionedPostgisDataStoreParams.PrepareThreshold.key mustEqual "prepare_threshold" |
| 29 | + } |
| 30 | + |
| 31 | + "emit prepare_threshold as the pgjdbc driver property prepareThreshold" in { |
| 32 | + val factory = new PartitionedPostgisDataStoreFactory() |
| 33 | + val params = Map[String, AnyRef](PartitionedPostgisDataStoreParams.PrepareThreshold.key -> Int.box(-1)) |
| 34 | + val options = factory.createConnectionOptions(params.asJava) |
| 35 | + // the datastore key is snake_case but the emitted pgjdbc connection property keeps its own spelling |
| 36 | + options.get("prepareThreshold") must beSome("-1") |
| 37 | + // it's a driver property, not a server GUC, so it must not leak into the '-c' options string |
| 38 | + options.get("options") must beNone |
| 39 | + } |
| 40 | + |
| 41 | + "not emit prepareThreshold when the parameter is unset" in { |
| 42 | + val factory = new PartitionedPostgisDataStoreFactory() |
| 43 | + val options = factory.createConnectionOptions(Map.empty[String, AnyRef].asJava) |
| 44 | + options.get("prepareThreshold") must beNone |
| 45 | + } |
| 46 | + |
| 47 | + "route idle_in_transaction_session_timeout to a server GUC, not a driver property" in { |
| 48 | + // sibling param: proves the driver-property vs. '-c <guc>' split is behaving as intended |
| 49 | + val factory = new PartitionedPostgisDataStoreFactory() |
| 50 | + val params = |
| 51 | + Map[String, AnyRef](PartitionedPostgisDataStoreParams.IdleInTransactionTimeout.key -> "2 minutes") |
| 52 | + val options = factory.createConnectionOptions(params.asJava) |
| 53 | + options.get("options") must beSome |
| 54 | + options("options") must contain("-c idle_in_transaction_session_timeout=120000") |
| 55 | + options.get("prepareThreshold") must beNone |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments