# python-connector-neo4j

See [python-connector-neo4j](https://github.com/theorchard/python-connector-neo4j) for latest version.

## Experiments

1. Start venv and install packages

```
$ python -m venv env
$ source env/bin/activate
$ (env) pip install -r reqirements.txt
```

2. Start neo4j running in a container locally
```
$ docker run -p7687:7687 -p7474:7474 -v=$HOME/neo4j/plugins:/plugins -v=$HOME/neo4j/data:/data -v $HOME/neo4j/certificats:/certificates --env=NEO4J_AUTH=neo4j/blerg neo4j:3.5.18
```

### Simulate Server Crash

The following process, simulates a neo4j server going down during an application's runtime and prints out information about the state of the application's connection pool. It shows that the connector library causes "bad" connections to be removed from the pool before they can be used, and shows how an application can gracefully recover from neo4j server outage without needing to be re-deployed.

1. Open a new shell and follow prompts
```
$ (env) python examples/simulate_server_crash.py
```

### Simulate Flask Behavior

The following process exposed CRUD endpoints. The POST endpoint can be used to artificially slow down and/or fail to test session handling.

1. Run flask app example

```
$ (env) FLASK_APP=examples/app.py flask run
```

2. Create a person

```
curl --request POST \
  --url 'http://localhost:5000/people' \
  --header 'Content-Type: application/json' \
  --data '{
	"name": "Trinity"
}'
```

3. Get people

```
curl --request GET \
  --url http://localhost:5000/people \
  --header 'Content-Type: application/json'
}'
```

4. Delete all people

```
curl --request DELETE \
  --url http://localhost:5000/people \
  --header 'Content-Type: application/json'
}'
```

5. Simulate a slow request (10s) that errors after query but before transaction closes.

```
curl --request POST \
  --url 'http://localhost:5000/people?error=1&sleep=10' \
  --header 'Content-Type: application/json' \
  --data '{
	"name": "Trinity"
}'
```

:bangbang: Try running step #5 then step #1 to confirm that the transactions are sufficiently isolated.