mcpField
Q
qe-middleware-testing-patterns

qe-middleware-testing-patterns

github.com/proffesor-for-testingテスト・品質51980 回インストール今日更新
リポジトリ

qe-middleware-testing-patterns について

企業ミドルウェア、ESB、メッセージ駆動システム向けのテストパターンをまとめたスキルです。ルーティング、変換、エラー処理、順序、プロトコル仲介、統合パターンのテストとエージェントによる検証を扱います。

主な機能

  1. 01メッセージルーティングと変換のテスト
  2. 02DLQとリトライ動作の検証
  3. 03順序と相関IDの確認
  4. 04エラー処理と補償フローのテスト
  5. 05プロトコル仲介とEIPパターンのテスト
  6. 06エージェントによるミドルウェア検証の調整

活用シーン

  1. 01メッセージブローカーのルーティング先をテスト
  2. 02変換後のメッセージスキーマを検証
  3. 03不正メッセージ処理とリトライを確認
  4. 04相関IDでマルチホップ処理を追跡

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/proffesor-for-testing/agentic-qe --skill qe-middleware-testing-patterns

インストール後、Claude Code で/qe-middleware-testing-patternsを入力して読み込まれたか確認します。

詳細

ミドルウェアテストのパターン

<default_to_action> エンタープライズミドルウェア、ESB、またはメッセージ駆動型システムをテストする場合:

  1. メッセージルーティングロジックを検証します(コンテンツベース、ヘッダーベース、受信者リスト)。
  2. メッセージ変換をエンドツーエンドでテストします(入力形式 -> 出力形式)。
  3. デッドレターキューの処理を検証します(有害メッセージ、リトライ上限到達)。
  4. 相関 ID を使用して、メッセージの順序とシーケンスをアサートします。
  5. エラー処理と補償パターンを実行します。
  6. プロトコルの仲介をテストします(SOAP から REST、同期から非同期)。
  7. EIP パターンを検証します(スプリッター、アグリゲーター、コンテンツエンリッチャー、ノーマライザー)。

パターンをすばやく選択するには:

  • メッセージルーティングの問題 -> コンテンツベースルーターのテスト
  • 変換の失敗 -> スキーマ入力/スキーマ出力の検証
  • メッセージの消失 -> DLQ とリトライパターンのテスト
  • プロトコルのブリッジング -> 仲介の往復テスト
  • 複雑なフロー -> 相関 ID のトレーステスト

重要な成功要因:

  • ミドルウェアは正常に動作しているときには見えません。見えない部分をテストしましょう。
  • 正常系とエラーチャネル(DLQ)の両方を必ず検証します。
  • 相関 ID は、複数のホップを経由するメッセージを追跡するための命綱です。 </default_to_action>

クイックリファレンスカード

使用する場面
  • ESB のメッセージフローのテスト(IBM IIB/ACE、MuleSoft、WSO2)
  • メッセージ変換の検証(XSLT、JSON から XML、フラットファイルの解析)
  • メッセージブローカーのルーティングのテスト(MQ、Kafka、RabbitMQ)
  • デッドレターキューの動作の検証
  • プロトコルの仲介のテスト(SOAP/REST ブリッジング)
  • エンタープライズ統合パターン(EIP)の検証
テストレベル
レベル目的依存関係速度
単体変換単一のマッピングの正確性なし高速
ルートロジックルーティング判断の正確性モック化されたエンドポイント高速
統合エンドツーエンドのメッセージフローブローカー + エンドポイント中速
DLQ/エラーエラー処理と復旧ミドルウェアスタック全体低速
重要なテストシナリオ
シナリオ必ずテストする項目例
ルーティング正しい宛先の選択注文タイプ A -> キュー A、タイプ B -> キュー B
変換マッピング後のスキーマ準拠XML -> JSON のフィールドマッピングの正確性
DLQ有害メッセージの処理不正な XML が失われずに DLQ に格納される
順序シーケンスの保持メッセージ 1-2-3 が順番どおりに到着する
相関複数ホップのトレース相関 ID でリクエストとレスポンスを照合する
リトライ一時的な障害からの復旧バックオフを伴う 3 回のリトライ後、DLQ に送る
仲介プロトコルブリッジングの忠実性SOAP リクエストによって正しい REST 呼び出しが行われる
ツール
  • メッセージブローカー:IBM MQ、RabbitMQ、Apache Kafka、ActiveMQ
  • ESB:IBM IIB/ACE、MuleSoft、WSO2、Apache Camel
  • テスト:SoapUI、Postman、カスタムハーネス
  • 仮想化:Mountebank、WireMock、HoverFly
  • 監視:Splunk、ELK、Datadog
エージェントの連携
  • qe-middleware-validator:ルーティングルール、変換の正確性、EIP パターンを検証します
  • qe-message-broker-tester:ブローカー接続、DLQ の動作、メッセージ順序をテストします
  • qe-soap-tester:SOAP/WSDL の検証、WS-Security、プロトコルの仲介をテストします

メッセージルーティングパターンのテスト

コンテンツベースルーター
describe('Content-Based Router - Order Type', () => {
  it('routes standard orders to fulfillment queue', async () => {
    const message = {
      correlationId: uuid(),
      body: { orderType: 'STANDARD', orderId: 'ORD-001', items: [{ sku: 'A1', qty: 2 }] }
    };

    await broker.publish('orders.inbound', message);

    const routed = await broker.consume('orders.fulfillment', { timeout: 5000 });
    expect(routed.body.orderId).toBe('ORD-001');
    expect(routed.correlationId).toBe(message.correlationId);

    const dlq = await broker.tryConsume('orders.dlq', { timeout: 1000 });
    expect(dlq).toBeNull(); // Nothing in DLQ
  });

  it('routes express orders to priority queue', async () => {
    const message = {
      correlationId: uuid(),
      body: { orderType: 'EXPRESS', orderId: 'ORD-002', items: [{ sku: 'B1', qty: 1 }] }
    };

    await broker.publish('orders.inbound', message);

    const routed = await broker.consume('orders.priority', { timeout: 5000 });
    expect(routed.body.orderId).toBe('ORD-002');
  });

  it('sends unrecognized order types to DLQ', async () => {
    const message = {
      correlationId: uuid(),
      body: { orderType: 'UNKNOWN', orderId: 'ORD-003' }
    };

    await broker.publish('orders.inbound', message);

    const dlqMessage = await broker.consume('orders.dlq', { timeout: 5000 });
    expect(dlqMessage.body.orderId).toBe('ORD-003');
    expect(dlqMessage.headers['x-error-reason']).toContain('Unrecognized orderType');
  });
});
ヘッダーベースルーター
describe('Header-Based Router - Region', () => {
  it('routes by x-region header to regional queues', async () => {
    const regions = ['US', 'EU', 'APAC'];

    for (const region of regions) {
      const message = {
        headers: { 'x-region': region },
        body: { orderId: `ORD-${region}` }
      };

      await broker.publish('orders.global', message);

      const routed = await broker.consume(`orders.${region.toLowerCase()}`, { timeout: 5000 });
      expect(routed.body.orderId).toBe(`ORD-${region}`);
    }
  });

  it('routes messages without region header to default queue', async () => {
    await broker.publish('orders.global', { body: { orderId: 'ORD-NO-REGION' } });

    const routed = await broker.consume('orders.default', { timeout: 5000 });
    expect(routed.body.orderId).toBe('ORD-NO-REGION');
  });
});
受信者リスト
describe('Recipient List - Order Notifications', () => {
  it('fans out order to all registered recipients', async () => {
    const message = {
      body: { orderId: 'ORD-100', total: 250.00 }
    };

    await broker.publish('orders.confirmed', message);

    // All three systems should receive the message
    const [warehouse, billing, crm] = await Promise.all([
      broker.consume('notify.warehouse', { timeout: 5000 }),
      broker.consume('notify.billing', { timeout: 5000 }),
      broker.consume('notify.crm', { timeout: 5000 })
    ]);

    expect(warehouse.body.orderId).toBe('ORD-100');
    expect(billing.body.orderId).toBe('ORD-100');
    expect(crm.body.orderId).toBe('ORD-100');
  });
});

メッセージ変換のテスト

JSON から XML への変換
describe('JSON to XML Transformation', () => {
  it('transforms order JSON to SAP XML format', async () => {
    const jsonInput = {
      orderId: 'ORD-500',
      customer: { id: 'CUST-01', name: 'Acme Corp' },
      items: [
        { sku: 'MAT-100', quantity: 10, unitPrice: 25.00 }
      ]
    };

    await broker.publish('transform.json-in', { body: jsonInput });

    const xmlOutput = await broker.consume('transform.xml-out', { timeout: 5000 });
    const parsed = parseXml(xmlOutput.body);

    expect(parsed.SalesOrder.OrderNumber).toBe('ORD-500');
    expect(parsed.SalesOrder.SoldToParty.CustomerID).toBe('CUST-01');
    expect(parsed.SalesOrder.Items.Item[0].MaterialNumber).toBe('MAT-100');
    expect(parsed.SalesOrder.Items.Item[0].Quantity).toBe('10');
  });

  it('handles missing optional fields gracefully', async () => {
    const jsonInput = {
      orderId: 'ORD-501',
      customer: { id: 'CUST-02' }, // name is missing
      items: [{ sku: 'MAT-200', quantity: 5 }] // unitPrice missing
    };

    await broker.publish('transform.json-in', { body: jsonInput });

    const xmlOutput = await broker.consume('transform.xml-out', { timeout: 5000 });
    const parsed = parseXml(xmlOutput.body);

    expect(parsed.SalesOrder.SoldToParty.Name).toBe(''); // Default empty
    expect(parsed.SalesOrder.Items.Item[0].UnitPrice).toBe('0.00');
  });

  it('rejects invalid input and sends to DLQ with error details', async () => {
    const invalidInput = { items: [] }; // Missing required orderId and customer

    await broker.publish('transform.json-in', { body: invalidInput });

    const dlq = await broker.consume('transform.dlq', { timeout: 5000 });
    expect(dlq.headers['x-error-reason']).toContain('orderId is required');
  });
});
フラットファイルから XML への変換
describe('Flat-File to XML Transformation', () => {
  it('parses fixed-width flat file into structured XML', async () => {
    // Fixed-width: positions 1-10 = orderId, 11-20 = sku, 21-25 = qty
    const flatFile = 'ORD-001   MAT-10000010\nORD-001   MAT-20000005\n';

    await broker.publish('transform.flatfile-in', { body: flatFile });

    const xmlOutput = await broker.consume('transform.flatfile-xml-out', { timeout: 5000 });
    const parsed = parseXml(xmlOutput.body);

    expect(parsed.Orders.Order).toHaveLength(1);
    expect(parsed.Orders.Order[0].Items.Item).toHaveLength(2);
    expect(parsed.Orders.Order[0].Items.Item[0].Quantity).toBe('10');
  });

  it('handles lines with trailing whitespace correctly', async () => {
    const flatFile = 'ORD-002   MAT-30000001   \n';

    await broker.publish('transform.flatfile-in', { body: flatFile });

    const xmlOutput = await broker.consume('transform.flatfile-xml-out', { timeout: 5000 });
    const parsed = parseXml(xmlOutput.body);

    expect(parsed.Orders.Order[0].OrderId).toBe('ORD-002');
    expect(parsed.Orders.Order[0].Items.Item[0].Quantity).toBe('1');
  });
});

デッドレターキュー(DLQ)のテスト

describe('Dead Letter Queue Strategy', () => {
  it('moves message to DLQ after max retries', async () => {
    // Configure endpoint to always fail
    mockEndpoint.respondWith(500, 'Service Unavailable');

    await broker.publish('orders.process', {
      body: { orderId: 'ORD-FAIL' },
      headers: { 'x-correlation-id': 'corr-123' }
    });

    // Wait for retries to exhaust (3 retries with backoff)
    const dlqMessage = await broker.consume('orders.dlq', { timeout: 30000 });

    expect(dlqMessage.body.orderId).toBe('ORD-FAIL');
    expect(dlqMessage.headers['x-retry-count']).toBe('3');
    expect(dlqMessage.headers['x-original-queue']).toBe('orders.process');
    expect(dlqMessage.headers['x-correlation-id']).toBe('corr-123');
    expect(dlqMessage.headers['x-error-reason']).toContain('Service Unavailable');
    expect(dlqMessage.headers['x-first-failure-timestamp']).toBeDefined();
  });

  it('preserves original message body in DLQ', async () => {
    const originalBody = {
      orderId: 'ORD-PRESERVE',
      items: [{ sku: 'A', qty: 1 }, { sku: 'B', qty: 2 }]
    };

    mockEndpoint.respondWith(500, 'Timeout');
    await broker.publish('orders.process', { body: originalBody });

    const dlqMessage = await broker.consume('orders.dlq', { timeout: 30000 });
    expect(dlqMessage.body).toEqual(originalBody); // Body unchanged
  });

  it('DLQ messages can be replayed after fix', async () => {
    // Step 1: Message fails, lands in DLQ
    mockEndpoint.respondWith(500, 'Down');
    await broker.publish('orders.process', { body: { orderId: 'ORD-REPLAY' } });
    const dlqMessage = await broker.consume('orders.dlq', { timeout: 30000 });

    // Step 2: Fix the endpoint
    mockEndpoint.respondWith(200, 'OK');

    // Step 3: Replay from DLQ
    await broker.publish('orders.process', dlqMessage);
    const success = await broker.consume('orders.completed', { timeout: 5000 });
    expect(success.body.orderId).toBe('ORD-REPLAY');
  });
});

メッセージの順序とシーケンス

describe('Message Ordering Validation', () => {
  it('preserves FIFO order within same partition key', async () => {
    const messages = Array.from({ length: 10 }, (_, i) => ({
      headers: { 'x-partition-key': 'ORDER-GROUP-1', 'x-sequence': String(i + 1) },
      body: { orderId: `ORD-${i + 1}`, sequence: i + 1 }
    }));

    for (const msg of messages) {
      await broker.publish('orders.sequenced', msg);
    }

    const received = [];
    for (let i = 0; i < 10; i++) {
      const msg = await broker.consume('orders.sequenced.out', { timeout: 5000 });
      received.push(msg.body.sequence);
    }

    expect(received).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
  });

  it('detects out-of-order messages via sequence gap', async () => {
    // Send messages 1, 2, 4 (skip 3)
    for (const seq of [1, 2, 4]) {
      await broker.publish('orders.sequenced', {
        headers: { 'x-partition-key': 'GROUP-2', 'x-sequence': String(seq) },
        body: { sequence: seq }
      });
    }

    // The middleware should detect the gap and raise an alert
    const alert = await broker.consume('orders.sequence-gap', { timeout: 10000 });
    expect(alert.body.missingSequence).toBe(3);
    expect(alert.body.partitionKey).toBe('GROUP-2');
  });
});

ESB のエラー処理と補償

describe('Compensation Pattern - Saga', () => {
  it('compensates completed steps when a later step fails', async () => {
    // Saga: Reserve Inventory -> Charge Payment -> Ship
    // If Ship fails, Payment and Inventory must be compensated

    mockServices.inventory.respondWith(200); // Step 1 succeeds
    mockServices.payment.respondWith(200);   // Step 2 succeeds
    mockServices.shipping.respondWith(500);  // Step 3 fails

    await broker.publish('saga.order', {
      body: { orderId: 'ORD-SAGA', amount: 100.00 }
    });

    // Verify compensation messages were sent
    const paymentRefund = await broker.consume('saga.compensate.payment', { timeout: 10000 });
    expect(paymentRefund.body.action).toBe('REFUND');
    expect(paymentRefund.body.orderId).toBe('ORD-SAGA');

    const inventoryRelease = await broker.consume('saga.compensate.inventory', { timeout: 10000 });
    expect(inventoryRelease.body.action).toBe('RELEASE');
    expect(inventoryRelease.body.orderId).toBe('ORD-SAGA');
  });
});

プロトコル仲介のテスト

SOAP から REST への仲介
describe('SOAP to REST Protocol Mediation', () => {
  it('converts SOAP request to REST call and back', async () => {
    const soapRequest = `
      <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                        xmlns:ord="http://example.com/orders">
        <soapenv:Body>
          <ord:GetOrder>
            <ord:OrderId>ORD-700</ord:OrderId>
          </ord:GetOrder>
        </soapenv:Body>
      </soapenv:Envelope>
    `;

    // ESB should convert SOAP -> REST GET /orders/ORD-700
    mockRestBackend.onGet('/orders/ORD-700').reply(200, {
      orderId: 'ORD-700',
      status: 'SHIPPED',
      total: 150.00
    });

    const response = await soapClient.send(soapRequest, { endpoint: esbSoapEndpoint });

    // Verify SOAP response wraps REST data correctly
    const parsed = parseSoapResponse(response);
    expect(parsed.OrderId).toBe('ORD-700');
    expect(parsed.Status).toBe('SHIPPED');
    expect(parsed.Total).toBe('150.00');
  });

  it('maps REST error to SOAP fault', async () => {
    const soapRequest = buildSoapGetOrder('ORD-NOTFOUND');

    mockRestBackend.onGet('/orders/ORD-NOTFOUND').reply(404, {
      error: 'Order not found'
    });

    const response = await soapClient.send(soapRequest, { endpoint: esbSoapEndpoint });
    const fault = parseSoapFault(response);

    expect(fault.faultCode).toBe('Client');
    expect(fault.faultString).toContain('Order not found');
  });
});
同期から非同期への仲介
describe('Sync to Async Mediation', () => {
  it('accepts sync request, returns correlation ID, delivers result async', async () => {
    // Client sends synchronous HTTP POST
    const response = await httpClient.post(`${esbEndpoint}/async-orders`, {
      orderId: 'ORD-ASYNC',
      items: [{ sku: 'X1', qty: 5 }]
    });

    // ESB returns 202 Accepted with correlation ID
    expect(response.status).toBe(202);
    expect(response.body.correlationId).toBeDefined();
    const correlationId = response.body.correlationId;

    // Result arrives asynchronously on callback queue
    const result = await broker.consume('orders.async.results', {
      timeout: 15000,
      filter: (msg) => msg.headers['x-correlation-id'] === correlationId
    });

    expect(result.body.orderId).toBe('ORD-ASYNC');
    expect(result.body.status).toBe('ACCEPTED');
  });
});

エンタープライズ統合パターン(EIP)

スプリッターパターン
describe('Splitter - Batch Order to Individual Items', () => {
  it('splits batch order into individual item messages', async () => {
    const batchOrder = {
      orderId: 'BATCH-001',
      items: [
        { sku: 'A1', qty: 10 },
        { sku: 'B2', qty: 5 },
        { sku: 'C3', qty: 20 }
      ]
    };

    await broker.publish('orders.batch', { body: batchOrder });

    const splitMessages = [];
    for (let i = 0; i < 3; i++) {
      splitMessages.push(await broker.consume('orders.items', { timeout: 5000 }));
    }

    expect(splitMessages).toHaveLength(3);
    expect(splitMessages.map(m => m.body.sku).sort()).toEqual(['A1', 'B2', 'C3']);

    // Each split message retains parent correlation
    for (const msg of splitMessages) {
      expect(msg.headers['x-batch-id']).toBe('BATCH-001');
      expect(msg.headers['x-split-total']).toBe('3');
    }
  });
});
アグリゲーターパターン
describe('Aggregator - Collect Item Results', () => {
  it('aggregates individual item results into batch response', async () => {
    const batchId = 'BATCH-002';
    const itemResults = [
      { sku: 'A1', status: 'PICKED', batchId },
      { sku: 'B2', status: 'PICKED', batchId },
      { sku: 'C3', status: 'PICKED', batchId }
    ];

    for (const result of itemResults) {
      await broker.publish('items.completed', {
        headers: { 'x-batch-id': batchId, 'x-split-total': '3' },
        body: result
      });
    }

    const aggregated = await broker.consume('orders.batch.completed', { timeout: 10000 });

    expect(aggregated.body.batchId).toBe('BATCH-002');
    expect(aggregated.body.items).toHaveLength(3);
    expect(aggregated.body.items.every(i => i.status === 'PICKED')).toBe(true);
  });

  it('handles aggregation timeout for incomplete batches', async () => {
    const batchId = 'BATCH-TIMEOUT';

    // Only send 2 of 3 expected items
    for (let i = 0; i < 2; i++) {
      await broker.publish('items.completed', {
        headers: { 'x-batch-id': batchId, 'x-split-total': '3' },
        body: { sku: `ITEM-${i}`, status: 'PICKED', batchId }
      });
    }

    // After timeout, aggregator should emit partial result with error
    const partial = await broker.consume('orders.batch.incomplete', { timeout: 60000 });
    expect(partial.body.batchId).toBe('BATCH-TIMEOUT');
    expect(partial.body.receivedCount).toBe(2);
    expect(partial.body.expectedCount).toBe(3);
  });
});
コンテンツエンリッチャーパターン
describe('Content Enricher - Customer Data Lookup', () => {
  it('enriches order with customer details from CRM', async () => {
    mockCrm.onGet('/customers/CUST-50').reply(200, {
      name: 'Acme Corp',
      tier: 'GOLD',
      creditLimit: 50000
    });

    await broker.publish('orders.enrich', {
      body: { orderId: 'ORD-ENRICH', customerId: 'CUST-50', total: 1200 }
    });

    const enriched = await broker.consume('orders.enriched', { timeout: 5000 });

    expect(enriched.body.orderId).toBe('ORD-ENRICH');
    expect(enriched.body.customer.name).toBe('Acme Corp');
    expect(enriched.body.customer.tier).toBe('GOLD');
    expect(enriched.body.creditCheckPassed).toBe(true); // 1200 < 50000
  });
});

リトライとサーキットブレーカーパターン

describe('Retry with Exponential Backoff', () => {
  it('retries 3 times with increasing delays before DLQ', async () => {
    const timestamps = [];
    mockEndpoint.onPost('/process').reply(() => {
      timestamps.push(Date.now());
      return [500, 'Temporary failure'];
    });

    await broker.publish('orders.process', { body: { orderId: 'ORD-RETRY' } });

    await broker.consume('orders.dlq', { timeout: 60000 });

    // Verify exponential backoff timing (1s, 2s, 4s approximately)
    expect(timestamps).toHaveLength(4); // 1 initial + 3 retries
    const delay1 = timestamps[1] - timestamps[0];
    const delay2 = timestamps[2] - timestamps[1];
    expect(delay1).toBeGreaterThan(800);  // ~1s
    expect(delay2).toBeGreaterThan(1800); // ~2s
  });
});

describe('Circuit Breaker', () => {
  it('opens circuit after threshold failures', async () => {
    // Fail 5 messages to trip circuit breaker (threshold = 5)
    mockEndpoint.onPost('/process').reply(500, 'Down');

    for (let i = 0; i < 5; i++) {
      await broker.publish('orders.circuit', { body: { orderId: `ORD-CB-${i}` } });
    }

    // Wait for circuit to open
    await sleep(5000);

    // Next message should be immediately rejected (circuit open)
    const startTime = Date.now();
    await broker.publish('orders.circuit', { body: { orderId: 'ORD-CB-FAST-FAIL' } });
    const dlq = await broker.consume('orders.circuit.dlq', { timeout: 3000 });
    const elapsed = Date.now() - startTime;

    expect(dlq.headers['x-circuit-state']).toBe('OPEN');
    expect(elapsed).toBeLessThan(2000); // Fast fail, no retry
  });
});

分離テストのためのサービス仮想化

describe('Service Virtualization - Middleware Isolation', () => {
  let virtualService;

  beforeAll(async () => {
    virtualService = await mountebank.createImposter({
      port: 4545,
      protocol: 'http',
      stubs: [
        {
          predicates: [{ equals: { method: 'POST', path: '/sap/orders' } }],
          responses: [{
            is: {
              statusCode: 200,
              headers: { 'Content-Type': 'application/xml' },
              body: '<OrderResponse><Status>CREATED</Status><SapOrderId>SAP-001</SapOrderId></OrderResponse>'
            }
          }]
        },
        {
          predicates: [{ equals: { method: 'POST', path: '/sap/orders' },
                         contains: { body: '<InvalidField>' } }],
          responses: [{
            is: { statusCode: 400, body: '<Error>Invalid request</Error>' }
          }]
        }
      ]
    });
  });

  afterAll(async () => {
    await mountebank.deleteImposter(4545);
  });

  it('middleware correctly handles SAP success response', async () => {
    await broker.publish('orders.to-sap', {
      body: { orderId: 'ORD-VIRT', customer: 'CUST-01' }
    });

    const result = await broker.consume('orders.sap-confirmed', { timeout: 5000 });
    expect(result.body.sapOrderId).toBe('SAP-001');
  });
});

ベストプラクティス

実施すること
  • すべてのフローで、正常系とエラーチャネル(DLQ)の両方をテストします
  • 相関 ID を使用して、複数ホップのミドルウェアを通過するメッセージを追跡します
  • すべての変換境界でスキーマへの準拠を検証します
  • パーティション分割されたキューや順序付きキューで、メッセージの順序をテストします
  • サービス仮想化を使用して、ミドルウェアをバックエンドシステムから分離します
  • リトライの上限到達をテストして、DLQ の動作を確認します
  • 複数ステップのフローで補償パターン(Saga ロールバック)を検証します
避けること
  • 正常系だけをテストし、DLQ/エラーキューを無視すること
  • キュー名をハードコードすること。設定駆動型のテストを使用します
  • メッセージの順序に関する要件を無視すること
  • 変換時のエッジケース(空のフィールド、特殊文字、エンコーディング)のテストを省略すること
  • 相関 ID の検証なしにミドルウェアをテストすること
  • バックオフのタイミングを検証せずに、リトライが正しく動作すると想定すること
  • サーキットブレーカーのしきい値をテストせずにデプロイすること

エージェントを活用したミドルウェアのテスト

// Validate middleware routing rules
await Task("Middleware Routing Validation", {
  routingConfig: 'esb/routing-rules.xml',
  messageTypes: ['STANDARD_ORDER', 'EXPRESS_ORDER', 'RETURN'],
  validateDLQ: true,
  checkCorrelationIds: true
}, "qe-middleware-validator");

// Test message broker behavior
await Task("Message Broker DLQ Test", {
  broker: 'rabbitmq',
  queues: ['orders.inbound', 'orders.process', 'orders.dlq'],
  retryPolicy: { maxRetries: 3, backoff: 'exponential' },
  poisonMessages: ['malformed-xml', 'missing-required-fields', 'oversized-payload']
}, "qe-message-broker-tester");

// SOAP/WSDL contract validation
await Task("SOAP Service Contract Validation", {
  wsdl: 'services/OrderService.wsdl',
  endpoints: ['CreateOrder', 'GetOrderStatus', 'CancelOrder'],
  validateWsSecurity: true,
  testFaultHandling: true
}, "qe-soap-tester");

// Transformation accuracy testing
await Task("Transformation Accuracy Suite", {
  transformations: [
    { name: 'JSON-to-SAP-XML', input: 'testdata/order.json', expected: 'testdata/order-sap.xml' },
    { name: 'Flat-to-XML', input: 'testdata/inventory.dat', expected: 'testdata/inventory.xml' }
  ],
  validateSchemas: true,
  edgeCases: ['empty-fields', 'special-chars', 'max-length']
}, "qe-middleware-validator");

エージェント連携のヒント

メモリ名前空間
aqe/middleware-testing/
  routing/           - Routing rule configurations and test results
  transformations/   - Mapping definitions and validation results
  dlq/               - DLQ test results and replay outcomes
  eip-patterns/      - EIP pattern test coverage
  circuit-breakers/  - Circuit breaker state and threshold configs
  correlation/       - Correlation ID tracing results
フリート連携
const middlewareFleet = await FleetManager.coordinate({
  strategy: 'middleware-testing',
  agents: [
    'qe-middleware-validator',   // Routing, transformation, EIP patterns
    'qe-message-broker-tester',  // DLQ, ordering, retry, circuit breaker
    'qe-soap-tester'             // SOAP contracts, WS-Security, mediation
  ],
  topology: 'mesh'
});

await middlewareFleet.execute({
  flows: [
    { name: 'order-inbound', stages: ['route', 'transform', 'enrich', 'deliver'] },
    { name: 'payment-processing', stages: ['validate', 'authorize', 'settle'] }
  ],
  testDLQ: true,
  testCompensation: true
});

関連スキル


覚えておくこと

ミドルウェアは、エンタープライズアーキテクチャの神経系です。正常に動作しているときは誰にも気づかれません。障害が起きると、すべてが壊れます。ルーティングの判断、変換、エラーチャネル、補償パターンをテストしてください。複数ホップのフロー全体で相関 ID を使って常に検証し、有害なメッセージが診断と再生に十分なメタデータとともに DLQ に入ることを必ず確認してください。

エージェントの活用: エージェントは、メッセージタイプに対するルーティングルールを検証し、スキーマへの準拠を確認しながら変換の正確性をテストし、DLQ/リトライ/サーキットブレーカーの動作を体系的に検証します。手動テストでは網羅できない、ルーティング経路の組み合わせや変換時のエッジケースをカバーするために、エージェントを活用してください。

コメント