|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# Copyright 2020 The Matrix.org Foundation C.I.C. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +from synapse.replication.tcp.commands import ( |
| 16 | + RdataCommand, |
| 17 | + ReplicateCommand, |
| 18 | + parse_command_from_line, |
| 19 | +) |
| 20 | + |
| 21 | +from tests.unittest import TestCase |
| 22 | + |
| 23 | + |
| 24 | +class ParseCommandTestCase(TestCase): |
| 25 | + def test_parse_one_word_command(self): |
| 26 | + line = "REPLICATE" |
| 27 | + cmd = parse_command_from_line(line) |
| 28 | + self.assertIsInstance(cmd, ReplicateCommand) |
| 29 | + |
| 30 | + def test_parse_rdata(self): |
| 31 | + line = 'RDATA events 6287863 ["ev", ["$eventid", "!roomid", "type", null, null, null]]' |
| 32 | + cmd = parse_command_from_line(line) |
| 33 | + self.assertIsInstance(cmd, RdataCommand) |
| 34 | + self.assertEqual(cmd.stream_name, "events") |
| 35 | + self.assertEqual(cmd.token, 6287863) |
| 36 | + |
| 37 | + def test_parse_rdata_batch(self): |
| 38 | + line = 'RDATA presence batch ["@foo:example.com", "online"]' |
| 39 | + cmd = parse_command_from_line(line) |
| 40 | + self.assertIsInstance(cmd, RdataCommand) |
| 41 | + self.assertEqual(cmd.stream_name, "presence") |
| 42 | + self.assertIsNone(cmd.token) |
0 commit comments