<commit_before>describe 'redis-admin', ->
    cli = null
    cfg = null
    Redis = require 'redis-stream'
    redisAdmin = require '../redis-admin'

    beforeEach (done) ->
        (cli = new Redis 6379, 'localhost', 11)
        cfg =
            id: 'myhairystorage'
            client: cli
        done()

    afterEach (done) ->
        flusher = cli.stream()
        flusher.on 'data', (reply) -> 
            flusher.end()
            done()
        flusher.write 'flushdb'

    describe '#stream history', ->
        beforeEach (done) ->
            @commit1 =
                headers: []
                streamId: '123'
                streamRevision: 1
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,1,12,0,0)
            @commit2 =
                headers: []
                streamId: '123'
                streamRevision: 4
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,8,23,0,0)
            @commit3 =
                headers: []
                streamId: '456'
                streamRevision: 1
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,9,3,59,0)
            @commit4 =
                headers: []
                streamId: '789'
                streamRevision: 1
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,9,6,59,0)
            @commit5 =
                headers: []
                streamId: '987'
                streamRevision: 1
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,10,12,0,0)
            @commits = [
                @commit1
                @commit2
                @commit3
                @commit4
                @commit5
            ]

            sut = redisAdmin
            @admin = sut.createAdmin cfg
            @admin.on 'ready', (err, admin) =>
                writer = cli.stream('zadd')
                writer.on 'end', =>
                    auditor = cli.stream('zadd')

                    auditor.on 'end', ->
                        done()
                    for c in @commits
                        auditor.write ["streamId2RevByTime", 
                            c.timestamp.getTime(), 
                            JSON.stringify { 
                                    streamId: c.streamId,
                                    streamRevision: c.streamRevision
                                }
                            ]
                    auditor.end()

                for c in @commits
                    writer.write ["commits:#{c.streamId}", 
                        c.streamRevision, 
                        JSON.stringify(c)]
                writer.end()
        

        it 'should emit streamid mapping between given datetime range', (done) ->
            start = new Date(2012, 9, 8, 7, 0, 0).getTime()
            end = new Date(2012, 9, 9, 7, 0, 0).getTime()
            stream = @admin.createRangeStream()
            vals = []
            stream.on 'data', (data) ->
                vals.push data
            stream.on 'end', ->
                vals.length.should.equal 3
                done()
            stream.write [start, end]
            stream.end()

        it 'should create chronological event stream given datetime range', (done) ->
            start = new Date(2012, 9, 8, 7, 0, 0).getTime()
            end = new Date(2012, 9, 9, 7, 0, 0).getTime()
            stream = @admin.createEventStream()
            vals = []
            stream.on 'data', (data) ->
                console.log 'receiveddata', data
                vals.push data
            stream.on 'end', ->
                vals.length.should.equal 9
                done()
            stream.write [start, end]
            stream.end()


<commit_msg>streaming events works better<commit_after>describe 'redis-admin', ->
    cli = null
    cfg = null
    Redis = require 'redis-stream'
    redisAdmin = require '../redis-admin'

    beforeEach (done) ->
        (cli = new Redis 6379, 'localhost', 11)
        cfg =
            id: 'myhairystorage'
            client: cli
        done()

    afterEach (done) ->
        flusher = cli.stream()
        flusher.on 'data', (reply) -> 
            flusher.end()
            done()
        flusher.write 'flushdb'

    describe '#stream history', ->
        beforeEach (done) ->
            @commit1 =
                headers: []
                streamId: '123'
                streamRevision: 1
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,1,12,0,0)
            @commit2 =
                headers: []
                streamId: '123'
                streamRevision: 4
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,8,23,0,0)
            @commit3 =
                headers: []
                streamId: '456'
                streamRevision: 1
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,9,3,59,0)
            @commit4 =
                headers: []
                streamId: '789'
                streamRevision: 1
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,9,6,59,0)
            @commit5 =
                headers: []
                streamId: '987'
                streamRevision: 1
                payload: [
                    {a:1}
                    {b:2}
                    {c:3}
                ]
                timestamp: new Date(2012,9,10,12,0,0)
            @commits = [
                @commit1
                @commit2
                @commit3
                @commit4
                @commit5
            ]

            sut = redisAdmin
            @admin = sut.createAdmin cfg
            @admin.on 'ready', (err, admin) =>
                writer = cli.stream('zadd')
                writer.on 'end', =>
                    auditor = cli.stream('zadd')

                    auditor.on 'end', ->
                        done()
                    for c in @commits
                        auditor.write ["streamId2RevByTime", 
                            c.timestamp.getTime(), 
                            JSON.stringify { 
                                    streamId: c.streamId,
                                    streamRevision: c.streamRevision
                                }
                            ]
                    auditor.end()

                for c in @commits
                    writer.write ["commits:#{c.streamId}", 
                        c.streamRevision, 
                        JSON.stringify(c)]
                writer.end()
        

        it 'should emit streamid mapping between given datetime range', (done) ->
            start = new Date(2012, 9, 8, 7, 0, 0).getTime()
            end = new Date(2012, 9, 9, 7, 0, 0).getTime()
            stream = @admin.createRangeStream()
            vals = []
            stream.on 'data', (data) ->
                vals.push data
            stream.on 'end', ->
                vals.length.should.equal 3
                done()
            stream.write [start, end]
            stream.end()

        it 'should create chronological event stream given datetime range', (done) ->
            start = new Date(2012, 9, 8, 7, 0, 0).getTime()
            end = new Date(2012, 9, 9, 7, 0, 0).getTime()
            stream = @admin.createEventStream()
            vals = []
            stream.on 'data', (data) ->
                vals.push data
            stream.on 'end', ->
                vals.length.should.equal 9
                vals[0].should.eql @commit1.payload[0]
                done()
            stream.write [start, end]
            stream.end()



{'fraction_non_alphanumeric': 0.10540028422548556, 'fraction_numerical': 0.0337517764092847, 'mean_word_length': 0.8556361239288068, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2202414', 'n_tokens_mistral': 2479, 'n_tokens_neox': 2123, 'n_words': 486}