Я получаю следующее исключение при выполнении тестов интеграции для транзакционной функции MongoDB.
org.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 10107 (NotMaster): 'not master' on server localhost:60876. The full response is {"operationTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "ok": 0.0, "errmsg": "not master", "code": 10107, "codeName": "NotMaster", "$gleStats": {"lastOpTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "electionId": {"$oid": "7fffffff0000000000000001"}}, "lastCommittedOpTime": {"$timestamp": {"t": 0, "i": 0}}, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1615104939, "i": 2}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}}; nested exception is com.mongodb.MongoNotPrimaryException: Command failed with error 10107 (NotMaster): 'not master' on server localhost:60876. The full response is {"operationTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "ok": 0.0, "errmsg": "not master", "code": 10107, "codeName": "NotMaster", "$gleStats": {"lastOpTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "electionId": {"$oid": "7fffffff0000000000000001"}}, "lastCommittedOpTime": {"$timestamp": {"t": 0, "i": 0}}, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1615104939, "i": 2}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}}
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:133)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2874)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:568)
at org.springframework.data.mongodb.core.MongoTemplate.saveDocument(MongoTemplate.java:1485)
at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:1421)
at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:1363)
....................
Caused by: com.mongodb.MongoNotPrimaryException: Command failed with error 10107 (NotMaster): 'not master' on server localhost:60876. The full response is {"operationTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "ok": 0.0, "errmsg": "not master", "code": 10107, "codeName": "NotMaster", "$gleStats": {"lastOpTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "electionId": {"$oid": "7fffffff0000000000000001"}}, "lastCommittedOpTime": {"$timestamp": {"t": 0, "i": 0}}, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1615104939, "i": 2}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}}
at com.mongodb.internal.connection.ProtocolHelper.createSpecialException(ProtocolHelper.java:244)
at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:171)
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:302)
В моем тестовом классе есть следующий метод.
@Test
@Order(1)
void testUpdateValidationsById() {
MyEntity entity = new MyEntity();
entity.setId("6030a6e1b32d1f70b4ce8039");
entity.setAttributeType("IP Address, FQDN");
entity.setCategory("NTP");
entity.setCategoryLabel("NTP");
entity.setTrueMsgDetails("It is true");
entity.setFalseMsgDetails("It is false");
entity.setCorevalidation("Core Validation");
ResponseEntity re = controller.updateValidationsById(entity);
boolean flag = re.getStatusCode().is2xxSuccessful();
assertEquals(true, flag);
}
Мой класс тестовой конфигурации выглядит следующим образом.
@Profile("test")
@ActiveProfiles("test")
@TestConfiguration
public class TestMongoDBConfig implements InitializingBean, DisposableBean {
private MongodExecutable executable;
private String replicaSetName = "rs0";
private int mongoDBPort = 27021;
@Override
public void afterPropertiesSet() throws Exception {
mongoDBPort = Network.getFreeServerPort();
IMongoCmdOptions cmdOptions = new MongoCmdOptionsBuilder().useNoPrealloc(false).useSmallFiles(false)
.master(false).verbose(false).useNoJournal(false).syncDelay(0).build();
// IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION)
IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.V4_0)
// .net(new Net(27023, Network.localhostIsIPv6()))
.net(new Net(mongoDBPort, Network.localhostIsIPv6()))
.replication(new Storage(null, replicaSetName, 5000)).configServer(true).cmdOptions(cmdOptions)
.build();
MongodStarter starter = MongodStarter.getDefaultInstance();
executable = starter.prepare(mongodConfig);
executable.start();
}
@Bean(name = "test1")
public MongoClient mongoClient() {
ConnectionString cs = new ConnectionString("mongodb://localhost:" + mongoDBPort + "/");
MongoClient mongoClient = MongoClients.create(cs);
System.out.println("--------------------------------------");
System.out.println("Mongo Selected ort : " + mongoDBPort);
System.out.println("MongoClient : " + mongoClient);
System.out.println("--------------------------------------");
mongoClient.getDatabase("admin").runCommand(new Document("replSetInitiate", new Document()));
return mongoClient;
}
/**
* Destroy.
*
* @throws Exception the exception
*/
@Override
public void destroy() throws Exception {
executable.stop();
}
}
Подробнее здесь: https://stackoverflow.com/questions/665 ... master-not
UncategorizedMongoDbException: команда завершилась с ошибкой 10107 (NotMaster): «не главный» на сервере ⇐ JAVA
Программисты JAVA общаются здесь
1721045040
Anonymous
Я получаю следующее исключение при выполнении тестов интеграции для транзакционной функции MongoDB.
org.springframework.data.mongodb.UncategorizedMongoDbException: Command failed with error 10107 (NotMaster): 'not master' on server localhost:60876. The full response is {"operationTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "ok": 0.0, "errmsg": "not master", "code": 10107, "codeName": "NotMaster", "$gleStats": {"lastOpTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "electionId": {"$oid": "7fffffff0000000000000001"}}, "lastCommittedOpTime": {"$timestamp": {"t": 0, "i": 0}}, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1615104939, "i": 2}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}}; nested exception is com.mongodb.MongoNotPrimaryException: Command failed with error 10107 (NotMaster): 'not master' on server localhost:60876. The full response is {"operationTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "ok": 0.0, "errmsg": "not master", "code": 10107, "codeName": "NotMaster", "$gleStats": {"lastOpTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "electionId": {"$oid": "7fffffff0000000000000001"}}, "lastCommittedOpTime": {"$timestamp": {"t": 0, "i": 0}}, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1615104939, "i": 2}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}}
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:133)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2874)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:568)
at org.springframework.data.mongodb.core.MongoTemplate.saveDocument(MongoTemplate.java:1485)
at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:1421)
at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:1363)
....................
Caused by: com.mongodb.MongoNotPrimaryException: Command failed with error 10107 (NotMaster): 'not master' on server localhost:60876. The full response is {"operationTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "ok": 0.0, "errmsg": "not master", "code": 10107, "codeName": "NotMaster", "$gleStats": {"lastOpTime": {"$timestamp": {"t": 1615104939, "i": 1}}, "electionId": {"$oid": "7fffffff0000000000000001"}}, "lastCommittedOpTime": {"$timestamp": {"t": 0, "i": 0}}, "$clusterTime": {"clusterTime": {"$timestamp": {"t": 1615104939, "i": 2}}, "signature": {"hash": {"$binary": {"base64": "AAAAAAAAAAAAAAAAAAAAAAAAAAA=", "subType": "00"}}, "keyId": 0}}}
at com.mongodb.internal.connection.ProtocolHelper.createSpecialException(ProtocolHelper.java:244)
at com.mongodb.internal.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:171)
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:302)
В моем тестовом классе есть следующий метод.
@Test
@Order(1)
void testUpdateValidationsById() {
MyEntity entity = new MyEntity();
entity.setId("6030a6e1b32d1f70b4ce8039");
entity.setAttributeType("IP Address, FQDN");
entity.setCategory("NTP");
entity.setCategoryLabel("NTP");
entity.setTrueMsgDetails("It is true");
entity.setFalseMsgDetails("It is false");
entity.setCorevalidation("Core Validation");
ResponseEntity re = controller.updateValidationsById(entity);
boolean flag = re.getStatusCode().is2xxSuccessful();
assertEquals(true, flag);
}
Мой класс тестовой конфигурации выглядит следующим образом.
@Profile("test")
@ActiveProfiles("test")
@TestConfiguration
public class TestMongoDBConfig implements InitializingBean, DisposableBean {
private MongodExecutable executable;
private String replicaSetName = "rs0";
private int mongoDBPort = 27021;
@Override
public void afterPropertiesSet() throws Exception {
mongoDBPort = Network.getFreeServerPort();
IMongoCmdOptions cmdOptions = new MongoCmdOptionsBuilder().useNoPrealloc(false).useSmallFiles(false)
.master(false).verbose(false).useNoJournal(false).syncDelay(0).build();
// IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.PRODUCTION)
IMongodConfig mongodConfig = new MongodConfigBuilder().version(Version.Main.V4_0)
// .net(new Net(27023, Network.localhostIsIPv6()))
.net(new Net(mongoDBPort, Network.localhostIsIPv6()))
.replication(new Storage(null, replicaSetName, 5000)).configServer(true).cmdOptions(cmdOptions)
.build();
MongodStarter starter = MongodStarter.getDefaultInstance();
executable = starter.prepare(mongodConfig);
executable.start();
}
@Bean(name = "test1")
public MongoClient mongoClient() {
ConnectionString cs = new ConnectionString("mongodb://localhost:" + mongoDBPort + "/");
MongoClient mongoClient = MongoClients.create(cs);
System.out.println("--------------------------------------");
System.out.println("Mongo Selected ort : " + mongoDBPort);
System.out.println("MongoClient : " + mongoClient);
System.out.println("--------------------------------------");
mongoClient.getDatabase("admin").runCommand(new Document("replSetInitiate", new Document()));
return mongoClient;
}
/**
* Destroy.
*
* @throws Exception the exception
*/
@Override
public void destroy() throws Exception {
executable.stop();
}
}
Подробнее здесь: [url]https://stackoverflow.com/questions/66514538/uncategorizedmongodbexception-command-failed-with-error-10107-notmaster-not[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия