Skip to content

Several connections in one environment variable #188

@dzmitry-lahoda

Description

@dzmitry-lahoda

Issue:

  • we have runtime when we need several connections to multiple event stores
  • it is impossible to configure via JSON

Solution:

  • scheme as in next test

Otherusages:

  • one liner connection string from notebook to make streams research more interactive
module Tests
open Equinox.EventStore
open Expecto
open System

type Connector with
    static member Connect (uri:Uri, connectionName) =
        // TODO: drop proper exception
        // TODO: consider what if no : presented
        // TODO: consider password contains non url encoded chracters
        // TODO: consider ?requestTimeoutMilliseconds= and requestRetries=
        let namePassword = uri.UserInfo.Split(":")
        let discovery =
          match uri.Scheme with
          | "uri" ->  uri.Host |> Uri |> Discovery.Uri
          | "gossipdns" -> uri.Host |> Discovery.GossipDns   
        let connector = Connector(namePassword.[0], namePassword.[1], TimeSpan.FromSeconds 5., 10)
        connector.Connect(connectionName, discovery) 



[<Tests>]
let tests =
  testList "samples" [
    let url = "gossipdns://admin:changeit@localhost:1234?requestTimeoutMilliseconds=5000&requestRetries=10"

    test "format" {
      let parsed = Uri(url)
      
      Expect.equal parsed.Scheme "gossipdns" "Scheme"
      Expect.equal parsed.UserInfo "admin:changeit" "UserPassword"
      Expect.equal parsed.Host "localhost" "Host"      
    }

    testAsync "factory1" {
      let parsed = Uri(url)
      let! connection = Connector.Connect(parsed,"Test")
      Expect.isNotNull connection "Created"
    }    
  ]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions