kukuy 1.5.0 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,54 +0,0 @@
1
- const { RoundRobinAlgorithm } = require('./src/algorithms/RoundRobinAlgorithm');
2
- const { IPHashAlgorithm } = require('./src/algorithms/IPHashAlgorithm');
3
- const { ServerPool } = require('./src/core/ServerPool');
4
-
5
- // Crear instancias de prueba
6
- const roundRobin = new RoundRobinAlgorithm();
7
- const ipHash = new IPHashAlgorithm();
8
- const serverPool = new ServerPool();
9
-
10
- // Agregar servidores de prueba
11
- const servers = [
12
- { url: 'http://server1.com', weight: 1, tags: ['api'] },
13
- { url: 'http://server2.com', weight: 1, tags: ['api'] },
14
- { url: 'http://server3.com', weight: 1, tags: ['web'] }
15
- ];
16
-
17
- serverPool.addServers(servers);
18
-
19
- console.log('Prueba de optimización del balanceador Kukuy');
20
- console.log('============================================');
21
-
22
- // Probar Round Robin
23
- console.log('\n1. Prueba de Round Robin:');
24
- const healthyServers = serverPool.getHealthyServers();
25
- for (let i = 0; i < 5; i++) {
26
- const server = roundRobin.selectServer(healthyServers);
27
- console.log(`Solicitud ${i+1}: Servidor seleccionado - ${server.url}`);
28
- }
29
-
30
- // Probar IP Hash
31
- console.log('\n2. Prueba de IP Hash:');
32
- const requestContext1 = { req: { headers: { 'x-forwarded-for': '192.168.1.10' } } };
33
- const requestContext2 = { req: { headers: { 'x-forwarded-for': '192.168.1.11' } } };
34
-
35
- const server1 = ipHash.selectServer(healthyServers, requestContext1);
36
- const server2 = ipHash.selectServer(healthyServers, requestContext1); // Misma IP
37
- const server3 = ipHash.selectServer(healthyServers, requestContext2); // Distinta IP
38
-
39
- console.log(`IP 192.168.1.10 primera vez: ${server1.url}`);
40
- console.log(`IP 192.168.1.10 segunda vez: ${server2.url}`);
41
- console.log(`IP 192.168.1.11 primera vez: ${server3.url}`);
42
- console.log(`Misma IP usa mismo servidor: ${server1.id === server2.id ? 'Sí' : 'No'}`);
43
-
44
- // Probar eficiencia de acceso a servidores
45
- console.log('\n3. Prueba de eficiencia de acceso a servidores:');
46
- const startTime = process.hrtime.bigint();
47
- const taggedServers = serverPool.getServersByTag('api');
48
- const endTime = process.hrtime.bigint();
49
- const duration = Number(endTime - startTime) / 1000000; // Convertir a milisegundos
50
-
51
- console.log(`Servidores con tag 'api': ${taggedServers.length}`);
52
- console.log(`Tiempo de acceso: ${duration} ms`);
53
-
54
- console.log('\n¡Todas las pruebas básicas pasaron!');