question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

URI parsing adds additional properties to configuration rather than properties map.

See original GitHub issue

I’m working in HR #1059 and trying to leverage the DB-specific SqlConnectOptions parsing of a URL string to allow additional properties on the URL but it looks like the parse logic isn’t capturing these properties except for a few in the PgConnectionUriParser.

The expectation would be that additional properties would be returned with a call to SqlConnectOptions.getProperties()

By using this URL String url = "jdbc:postgresql://testuser:testpassword@localhost:11111/hreact?prop1=value1&prop2=value2"; and calling PgConnectOptions.fromUri(…) prop1 and prop2 are dropped because any extra parsed props are put into the configuration rather than the properties.put

I’ve changed configuration.put(key, value); to properties.put(key, value); locally and the properties are added to the options however, because the SqlConnectOptions properties are stored in a HashMap() and the conversion to JSON may end up failing in the fail assertEquals(expectedConfiguration, actualConfiguration); because the properties aren’t necessarily ordered in a HashMap().

The following test added to PgConnectOptionsTest should work, but it fails.

  @Test
  public void testValidUriShouldSucceed() {
    connectionUri = "postgresql://?fallback_application_name=myapp&search_path=myschema&prop1=value1&prop2=value2&prop3=value3&loggerLevel=OFF";
    actualConfiguration = PgConnectOptions.fromUri(connectionUri);

    Map<String, String> expectedProperties = new HashMap<>();
    expectedProperties.put("fallback_application_name", "myapp");
    expectedProperties.put("search_path", "myschema");
    expectedProperties.put("prop1", "value1");
    expectedProperties.put("prop2", "value2");
    expectedProperties.put("prop3", "value3");
    expectedProperties.put("loggerLevel", "OFF");

    expectedConfiguration = new PgConnectOptions()
      .setProperties(expectedProperties);

    assertEquals(expectedConfiguration, actualConfiguration);
  }

Is there a reason why the assertEquals() check compares the JSON string only? I would think that the order of general JSON property elements shouldn’t matter.

Maybe the assertEquals() could be modified to do a more specific check for equality and in particular specific additional properties?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:23 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
vietjcommented, Jan 9, 2022

@gavinking I don’t disagree with you, I’m saying that some documented parameters are for the client and either the pg client supports them or it does not. So we need for the client side parameters to log at least that it will not work as expected.

0reactions
vietjcommented, Jan 12, 2022

I will try to support more of them like TCP time out, etc… some seem not hard to implement.

Read more comments on GitHub >

github_iconTop Results From Across the Web

24. Externalized Configuration - Spring
The properties that map to @ConfigurationProperties classes available in Spring Boot, which are configured via properties files, YAML files, environment ...
Read more >
Parse a URI String into Name-Value Collection - java
This solution on the other hand collects a map (given that in a url there can be more parameters with same name but...
Read more >
Inject a Map from a YAML File with Spring - Baeldung
This annotation is introduced to easily inject external properties from configuration files directly into Java objects. In this section, we'll ...
Read more >
Common Problems Found in RAML 1.0 API Specifications
Using the schema or schemas keyword instead of type or types ... Either add the property to the example or, in the type...
Read more >
Java Properties file examples - Mkyong.com
1. Write to the properties file ... Set the property key and value, and save it somewhere. ... The path/to/config.properties is created. path/to/ ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found