You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

RMI测试单独运行通过,与其他测试同跑时UnmarshalException失败

RMI测试单独运行正常、批量运行失败的问题

我遇到一个RMI测试的奇怪问题:某测试方法单独执行时可以正常通过,但和其他同样基于RMI的测试一起运行时就会失败,且两种场景下测试的结构完全一致。

测试类核心代码

...

@BeforeClass
public static void beforeTest() throws Exception {
  try {
    System.setProperty(Constants.JAVA_RMI_TEST_PORT_ENVIRONMENT, TestEnvironment.getPort());
    dataFactory.register();
    await().atMost(5, TimeUnit.SECONDS);
    client = DataFactoryClient.getInstance(TestEnvironment.getDomain(), TestEnvironment.getPort());
  } catch (RemoteException e) {
    throw new RuntimeException(e);
  } catch (NotBoundException e) {
    throw new RuntimeException(e);
  }
}

@AfterClass
public static void afterAll() {
  dataFactory.release();
}


@Test
public void testSimpleSave() throws Exception {
  EntityStore entityStore = client.getEntityStore();
  Assert.assertNotNull(entityStore);

  DataFactoryEntity entity = new DataFactoryEntityBuilder()
          .environment(TestEnvironment.getEnvironment())
          .entityType("Foo")
          .putPropertyMap("foo", "bar")
          .build();

  DataFactoryEntity dataFactoryEntity = entityStore.saveEntity(entity).get();
  Assert.assertNotNull(dataFactoryEntity);
  Assert.assertNotNull(dataFactoryEntity.entityId());
  Assert.assertEquals("bar", dataFactoryEntity.propertyMap().get("foo"));
}

EntityStoreClientImpl相关代码

public class EntityStoreClientImpl implements EntityStore {
  @Override public Option<DataFactoryEntity> saveEntity(@NotNull DataFactoryEntity entity)
      throws DataFactoryException, NotBoundException, RemoteException {
    return getEntityStore().saveEntity(entity);
  }
}

批量运行时抛出的异常

java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
    java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: ....datafactory.database.impl.DatabaseManagerImpl

    at sun.rmi.registry.RegistryImpl_Stub.lookup(RegistryImpl_Stub.java:130)
    at ....datafactory.repositories.impl.EntityStoreClientImpl.getEntityStore(EntityStoreClientImpl.java:108)
    at ....datafactory.repositories.impl.EntityStoreClientImpl.saveEntity(EntityStoreClientImpl.java:56)
    at ....datafactory.DataFactoryClientTest.testSimpleSave(DataFactoryClientTest.java:75)

这个测试本不应该对DatabaseManagerImpl进行序列化(该类本身也没有实现序列化接口),但奇怪的是批量运行时会触发对它的序列化操作。

更新:可正常通过的同类测试示例

@Test
public void testNearbyConditionWithGeoHash() throws Exception {
  String environment = TestEnvironment.getEnvironment();
  EntityStore entityStore = DataFactoryClient.getInstance(TestEnvironment.getDomain(), TestEnvironment.getPort()).getEntityStore();

  DataFactoryEntity firstLocation = new DataFactoryEntityBuilder()
      .environment(environment)
      .entityType("Room")
      .putPropertyMap("address", "Room 123, 456 Street, 789 Avenue")
      .putPropertyMap("geoLocation", new GeoHash(120.976171, 14.580919).toString())
      .build();
  firstLocation = entityStore.saveEntity(firstLocation).get();
  assertNotNull(firstLocation.entityId());
...
}

内容的提问来源于stack exchange,提问作者quarks

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 08:40:57