Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

subscribe never returns a result #88

Closed
chrisjenx opened this issue Mar 16, 2020 · 2 comments
Closed

subscribe never returns a result #88

chrisjenx opened this issue Mar 16, 2020 · 2 comments

Comments

@chrisjenx
Copy link

I can break the mock by using subscribe It looks like this should be implemented?

class JedisMockTest {

    private lateinit var redisServer: RedisServer
    private val jedis by lazy { Jedis(redisServer.host, redisServer.bindPort) }

    @Before
    fun setUp() {
        redisServer = RedisServer.newRedisServer()
        redisServer.start()
    }

    @After
    fun tearDown() {
        redisServer.stop()
    }

    @Test
    fun `test redis ping`() {
        val result = jedis.ping("Hello")
        assertEquals("Hello", result)
    }

    @Test
    fun `test pub sub`() {
        val countDownLatch = CountDownLatch(1)
        jedis.subscribe(object : JedisPubSub() {
            override fun onMessage(channel: String?, message: String?) {
                countDownLatch.countDown()
            }
        }, "channel")

//        jedis.publish("channel", "Message")

//        countDownLatch.await()
    }
}

The test will hang forever as it never gets a result from the subscribe call.

@chrisjenx
Copy link
Author

Never mind closing, Jedis isn't clear, the sub needs to be inside it's own thread!

@chrisjenx
Copy link
Author

This works incase anyone else gets stuck:

    @Test
    fun `test pub sub`() = runBlockingTest {
        val subscribed = CountDownLatch(1)
        val countDownLatch = CountDownLatch(1)
        val job = launch(Dispatchers.IO) {
            jedis.resource.use {
                it.subscribe(object : JedisPubSub() {
                    override fun onSubscribe(channel: String?, subscribedChannels: Int) {
                        println("Subscribed")
                        subscribed.countDown()
                    }

                    override fun onMessage(channel: String?, message: String?) {
                        println("onMessage: $message")
                        countDownLatch.countDown()
                    }
                }, "channel")
            }
        }

        launch(Dispatchers.IO) {
            subscribed.await(1000, TimeUnit.MILLISECONDS)
            jedis.resource.use { it.publish("channel", "Message") }
        }

        countDownLatch.await(1000, TimeUnit.MILLISECONDS)
        assertEquals(0, countDownLatch.count)
        job.cancel()
    }

inponomarev added a commit that referenced this issue Jun 4, 2022
* Bump testcontainers.version from 1.16.3 to 1.17.1 (#84)

Bumps `testcontainers.version` from 1.16.3 to 1.17.1.

Updates `testcontainers` from 1.16.3 to 1.17.1
- [Release notes](https://github.com/testcontainers/testcontainers-java/releases)
- [Changelog](https://github.com/testcontainers/testcontainers-java/blob/master/CHANGELOG.md)
- [Commits](testcontainers/testcontainers-java@1.16.3...1.17.1)

Updates `junit-jupiter` from 1.16.3 to 1.17.1
- [Release notes](https://github.com/testcontainers/testcontainers-java/releases)
- [Changelog](https://github.com/testcontainers/testcontainers-java/blob/master/CHANGELOG.md)
- [Commits](testcontainers/testcontainers-java@1.16.3...1.17.1)

---
updated-dependencies:
- dependency-name: org.testcontainers:testcontainers
  dependency-type: direct:development
  update-type: version-update:semver-minor
- dependency-name: org.testcontainers:junit-jupiter
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump jedis from 4.2.1 to 4.2.2 (#82)

* Add structures for String, HyperLogLog and BitMap (#91)

* changed slice, added RMString, changed string-slice operations for string-RMString

* add RMBitMap

* add RMHyperLogLog

* add tests

* refactoring

Co-authored-by: Ivan Ponomarev <iponomarev@mail.ru>

* Bump jedis from 4.2.2 to 4.2.3 (#93)

Bumps [jedis](https://github.com/redis/jedis) from 4.2.2 to 4.2.3.
- [Release notes](https://github.com/redis/jedis/releases)
- [Commits](redis/jedis@v4.2.2...v4.2.3)

---
updated-dependencies:
- dependency-name: redis.clients:jedis
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump mockito-core from 4.4.0 to 4.5.1 (#88)

Bumps [mockito-core](https://github.com/mockito/mockito) from 4.4.0 to 4.5.1.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v4.4.0...v4.5.1)

---
updated-dependencies:
- dependency-name: org.mockito:mockito-core
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump maven-javadoc-plugin from 3.3.2 to 3.4.0 (#86)

Bumps [maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.3.2 to 3.4.0.
- [Release notes](https://github.com/apache/maven-javadoc-plugin/releases)
- [Commits](apache/maven-javadoc-plugin@maven-javadoc-plugin-3.3.2...maven-javadoc-plugin-3.4.0)

---
updated-dependencies:
- dependency-name: org.apache.maven.plugins:maven-javadoc-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump mockito-core from 4.5.1 to 4.6.1 (#97)

Bumps [mockito-core](https://github.com/mockito/mockito) from 4.5.1 to 4.6.1.
- [Release notes](https://github.com/mockito/mockito/releases)
- [Commits](mockito/mockito@v4.5.1...v4.6.1)

---
updated-dependencies:
- dependency-name: org.mockito:mockito-core
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump testcontainers.version from 1.17.1 to 1.17.2 (#94)

Bumps `testcontainers.version` from 1.17.1 to 1.17.2.

Updates `testcontainers` from 1.17.1 to 1.17.2
- [Release notes](https://github.com/testcontainers/testcontainers-java/releases)
- [Changelog](https://github.com/testcontainers/testcontainers-java/blob/master/CHANGELOG.md)
- [Commits](testcontainers/testcontainers-java@1.17.1...1.17.2)

Updates `junit-jupiter` from 1.17.1 to 1.17.2
- [Release notes](https://github.com/testcontainers/testcontainers-java/releases)
- [Changelog](https://github.com/testcontainers/testcontainers-java/blob/master/CHANGELOG.md)
- [Commits](testcontainers/testcontainers-java@1.17.1...1.17.2)

---
updated-dependencies:
- dependency-name: org.testcontainers:testcontainers
  dependency-type: direct:development
  update-type: version-update:semver-patch
- dependency-name: org.testcontainers:junit-jupiter
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump nexus-staging-maven-plugin from 1.6.8 to 1.6.13 (#87)

Bumps nexus-staging-maven-plugin from 1.6.8 to 1.6.13.

---
updated-dependencies:
- dependency-name: org.sonatype.plugins:nexus-staging-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* Bump spotbugs-maven-plugin from 4.6.0.0 to 4.7.0.0 (#95)

* Bump spotbugs-maven-plugin from 4.6.0.0 to 4.7.0.0

Bumps [spotbugs-maven-plugin](https://github.com/spotbugs/spotbugs-maven-plugin) from 4.6.0.0 to 4.7.0.0.
- [Release notes](https://github.com/spotbugs/spotbugs-maven-plugin/releases)
- [Commits](spotbugs/spotbugs-maven-plugin@spotbugs-maven-plugin-4.6.0.0...spotbugs-maven-plugin-4.7.0.0)

---
updated-dependencies:
- dependency-name: com.github.spotbugs:spotbugs-maven-plugin
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* fix spotbugs warnings

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Ivan Ponomarev <iponomarev@mail.ru>

* add native tests (#92)

* add native tests

* add InterceptorMockServer

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: DibrovDru <60964857+DibrovDru@users.noreply.github.com>
Co-authored-by: mdvorchik <71084918+mdvorchik@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant