partitions.service.test.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import mockMilvusClient from '../__mocks__/milvus/milvusClient';
  2. import { MilvusService } from '../../milvus/milvus.service';
  3. import { ERR_NO_COLLECTION } from '../utils/constants';
  4. import { PartitionsService } from '../../partitions/partitions.service';
  5. import {
  6. insightCacheForTest,
  7. mockAddress,
  8. mockGetPartitionsInfoData,
  9. mockPartition,
  10. } from '../__mocks__/consts';
  11. import { MilvusClient } from '@zilliz/milvus2-sdk-node/dist/milvus';
  12. // mock Milvus client
  13. jest.mock('@zilliz/milvus2-sdk-node', () => {
  14. return {
  15. MilvusClient: mockMilvusClient,
  16. };
  17. });
  18. describe('Test partitions service', () => {
  19. let milvusService: any;
  20. let service: any;
  21. beforeAll(async () => {
  22. // setup Milvus service and connect to mock Milvus client
  23. milvusService = new MilvusService();
  24. MilvusService.activeAddress = mockAddress;
  25. MilvusService.activeMilvusClient = new MilvusClient(mockAddress);
  26. await milvusService.connectMilvus(
  27. { address: mockAddress },
  28. insightCacheForTest
  29. );
  30. service = new PartitionsService(milvusService);
  31. });
  32. afterAll(() => {
  33. milvusService = null;
  34. service = null;
  35. });
  36. test('test manager after connected to Milvus', () => {
  37. expect(service.partitionManager).toBeDefined();
  38. });
  39. test('test createPartition method', async () => {
  40. const res = await service.createPartition({
  41. collection_name: 'c1',
  42. partition_name: 'p1',
  43. });
  44. expect(res.data).toBe('p1');
  45. try {
  46. await service.createPartition({
  47. collection_name: '',
  48. partition_name: 'p1',
  49. });
  50. } catch (err) {
  51. expect(err).toBe(ERR_NO_COLLECTION);
  52. }
  53. });
  54. test('test deletePartition method', async () => {
  55. const mockParam = {
  56. collection_name: 'c1',
  57. partition_name: 'p1',
  58. };
  59. const res = await service.deletePartition(mockParam);
  60. expect(res.data).toEqual(mockParam);
  61. try {
  62. await service.deletePartition({
  63. collection_name: '',
  64. partition_name: '',
  65. });
  66. } catch (err) {
  67. expect(err).toBe(ERR_NO_COLLECTION);
  68. }
  69. });
  70. test('test loadPartitions method', async () => {
  71. const mockParam = {
  72. collection_name: 'c1',
  73. partition_names: ['p1', 'p2'],
  74. };
  75. const res = await service.loadPartitions(mockParam);
  76. expect(res.data).toEqual(mockParam);
  77. try {
  78. await service.loadPartitions({
  79. collection_name: '',
  80. partition_names: [],
  81. });
  82. } catch (err) {
  83. expect(err).toBe(ERR_NO_COLLECTION);
  84. }
  85. });
  86. test('test releasePartitions method', async () => {
  87. const mockParam = {
  88. collection_name: 'c1',
  89. partition_names: ['p1', 'p2'],
  90. };
  91. const res = await service.releasePartitions(mockParam);
  92. expect(res.data).toEqual(mockParam);
  93. try {
  94. await service.releasePartitions({
  95. collection_name: '',
  96. partition_names: [],
  97. });
  98. } catch (err) {
  99. expect(err).toBe(ERR_NO_COLLECTION);
  100. }
  101. });
  102. test('test getPartitions method', async () => {
  103. const res = await service.getPartitions({ collection_name: 'c1' });
  104. const { status, ...data } = res;
  105. expect(data).toEqual(mockPartition);
  106. try {
  107. await service.getPartitions({ collection_name: '' });
  108. } catch (err) {
  109. expect(err).toBe(ERR_NO_COLLECTION);
  110. }
  111. });
  112. test('test getPartitionStatistics method', async () => {
  113. const res = await service.getPartitionStatistics({
  114. collection_name: 'c1',
  115. partition_name: 'p1',
  116. });
  117. const { status, ...data } = res;
  118. expect(data.name).toBe('p1');
  119. expect(data.stats.length).toBe(1);
  120. try {
  121. await service.getPartitionStatistics({
  122. collection_name: '',
  123. partition_name: '',
  124. });
  125. } catch (err) {
  126. expect(err).toBe(ERR_NO_COLLECTION);
  127. }
  128. });
  129. test('test getPartitionsInfo method', async () => {
  130. const res = await service.getPartitionsInfo({ collection_name: 'c1' });
  131. expect(res).toEqual(mockGetPartitionsInfoData);
  132. });
  133. });