|
| 1 | +import { ErrorCode, MilvusClient } from '../../milvus'; |
| 2 | + |
| 3 | +describe('Replicate configuration API', () => { |
| 4 | + const createClient = () => { |
| 5 | + const client = new MilvusClient({ |
| 6 | + address: 'localhost:19530', |
| 7 | + __SKIP_CONNECT__: true, |
| 8 | + }); |
| 9 | + const calls: { method: string; params: any; options: any }[] = []; |
| 10 | + (client as any).channelPool = { |
| 11 | + acquire: jest.fn().mockResolvedValue({ |
| 12 | + UpdateReplicateConfiguration: (params: any, options: any, cb: any) => { |
| 13 | + calls.push({ |
| 14 | + method: 'UpdateReplicateConfiguration', |
| 15 | + params, |
| 16 | + options, |
| 17 | + }); |
| 18 | + cb(null, { error_code: ErrorCode.SUCCESS, reason: '' }); |
| 19 | + }, |
| 20 | + GetReplicateConfiguration: (params: any, options: any, cb: any) => { |
| 21 | + calls.push({ method: 'GetReplicateConfiguration', params, options }); |
| 22 | + cb(null, { |
| 23 | + status: { error_code: ErrorCode.SUCCESS, reason: '' }, |
| 24 | + configuration: { |
| 25 | + clusters: [ |
| 26 | + { |
| 27 | + cluster_id: 'source-cluster', |
| 28 | + connection_param: { |
| 29 | + uri: 'http://source:19530', |
| 30 | + token: 'source-token', |
| 31 | + }, |
| 32 | + pchannels: ['source-pchannel'], |
| 33 | + }, |
| 34 | + ], |
| 35 | + cross_cluster_topology: [ |
| 36 | + { |
| 37 | + source_cluster_id: 'source-cluster', |
| 38 | + target_cluster_id: 'target-cluster', |
| 39 | + }, |
| 40 | + ], |
| 41 | + }, |
| 42 | + }); |
| 43 | + }, |
| 44 | + }), |
| 45 | + release: jest.fn(), |
| 46 | + }; |
| 47 | + |
| 48 | + return { client, calls }; |
| 49 | + }; |
| 50 | + |
| 51 | + it('should update replicate configuration', async () => { |
| 52 | + const { client, calls } = createClient(); |
| 53 | + |
| 54 | + const res = await client.updateReplicateConfiguration({ |
| 55 | + clusters: [ |
| 56 | + { |
| 57 | + cluster_id: 'source-cluster', |
| 58 | + connection_param: { |
| 59 | + uri: 'http://source:19530', |
| 60 | + token: 'source-token', |
| 61 | + }, |
| 62 | + pchannels: ['source-pchannel'], |
| 63 | + }, |
| 64 | + { |
| 65 | + cluster_id: 'target-cluster', |
| 66 | + connection_param: { |
| 67 | + uri: 'http://target:19530', |
| 68 | + token: 'target-token', |
| 69 | + }, |
| 70 | + }, |
| 71 | + ], |
| 72 | + cross_cluster_topology: [ |
| 73 | + { |
| 74 | + source_cluster_id: 'source-cluster', |
| 75 | + target_cluster_id: 'target-cluster', |
| 76 | + }, |
| 77 | + ], |
| 78 | + force_promote: true, |
| 79 | + timeout: 1000, |
| 80 | + }); |
| 81 | + |
| 82 | + expect(res.error_code).toEqual(ErrorCode.SUCCESS); |
| 83 | + expect(calls[0]).toEqual( |
| 84 | + expect.objectContaining({ |
| 85 | + method: 'UpdateReplicateConfiguration', |
| 86 | + params: { |
| 87 | + replicate_configuration: { |
| 88 | + clusters: [ |
| 89 | + { |
| 90 | + cluster_id: 'source-cluster', |
| 91 | + connection_param: { |
| 92 | + uri: 'http://source:19530', |
| 93 | + token: 'source-token', |
| 94 | + }, |
| 95 | + pchannels: ['source-pchannel'], |
| 96 | + }, |
| 97 | + { |
| 98 | + cluster_id: 'target-cluster', |
| 99 | + connection_param: { |
| 100 | + uri: 'http://target:19530', |
| 101 | + token: 'target-token', |
| 102 | + }, |
| 103 | + }, |
| 104 | + ], |
| 105 | + cross_cluster_topology: [ |
| 106 | + { |
| 107 | + source_cluster_id: 'source-cluster', |
| 108 | + target_cluster_id: 'target-cluster', |
| 109 | + }, |
| 110 | + ], |
| 111 | + }, |
| 112 | + force_promote: true, |
| 113 | + }, |
| 114 | + }) |
| 115 | + ); |
| 116 | + expect(calls[0].options.deadline).toBeInstanceOf(Date); |
| 117 | + }); |
| 118 | + |
| 119 | + it('should default optional update fields', async () => { |
| 120 | + const { client, calls } = createClient(); |
| 121 | + |
| 122 | + await client.update_replicate_configuration({ |
| 123 | + clusters: [ |
| 124 | + { |
| 125 | + cluster_id: 'source-cluster', |
| 126 | + connection_param: { uri: 'http://source:19530' }, |
| 127 | + }, |
| 128 | + ], |
| 129 | + }); |
| 130 | + |
| 131 | + expect(calls[0].params).toEqual({ |
| 132 | + replicate_configuration: { |
| 133 | + clusters: [ |
| 134 | + { |
| 135 | + cluster_id: 'source-cluster', |
| 136 | + connection_param: { uri: 'http://source:19530' }, |
| 137 | + }, |
| 138 | + ], |
| 139 | + cross_cluster_topology: [], |
| 140 | + }, |
| 141 | + force_promote: false, |
| 142 | + }); |
| 143 | + }); |
| 144 | + |
| 145 | + it('should reject update without clusters', async () => { |
| 146 | + const { client } = createClient(); |
| 147 | + |
| 148 | + await expect( |
| 149 | + client.updateReplicateConfiguration({} as any) |
| 150 | + ).rejects.toThrow('The `clusters` property is missing.'); |
| 151 | + }); |
| 152 | + |
| 153 | + it('should get replicate configuration', async () => { |
| 154 | + const { client, calls } = createClient(); |
| 155 | + |
| 156 | + const res = await client.getReplicateConfiguration({ timeout: 1000 }); |
| 157 | + |
| 158 | + expect(res.status.error_code).toEqual(ErrorCode.SUCCESS); |
| 159 | + expect(res.configuration.clusters[0]).toEqual({ |
| 160 | + cluster_id: 'source-cluster', |
| 161 | + connection_param: { |
| 162 | + uri: 'http://source:19530', |
| 163 | + token: 'source-token', |
| 164 | + }, |
| 165 | + pchannels: ['source-pchannel'], |
| 166 | + }); |
| 167 | + expect(calls[0]).toEqual( |
| 168 | + expect.objectContaining({ |
| 169 | + method: 'GetReplicateConfiguration', |
| 170 | + params: {}, |
| 171 | + }) |
| 172 | + ); |
| 173 | + }); |
| 174 | +}); |
0 commit comments